Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
spdlog
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
spdlog
Commits
4bece787
Commit
4bece787
authored
Feb 09, 2020
by
bandana2004
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor Event Log sink
parent
db1a2214
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
364 additions
and
104 deletions
+364
-104
include/spdlog/sinks/eventlog_sink.h
include/spdlog/sinks/eventlog_sink.h
+0
-100
include/spdlog/sinks/win_eventlog_sink.h
include/spdlog/sinks/win_eventlog_sink.h
+357
-0
tests/test_eventlog.cpp
tests/test_eventlog.cpp
+7
-4
No files found.
include/spdlog/sinks/eventlog_sink.h
deleted
100644 → 0
View file @
db1a2214
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
// Requires the following registry entries to be present, with the following modifications:
// 1. {app_name} should be replaced with your application name
// 2. {log_name} should be replaced with the specific log name and the key should be duplicated for
// each log used in the application
/*---------------------------------------------------------------------------------------
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\{app_name}]
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\{app_name}\{log_name}]
"TypesSupported"=dword:00000007
"EventMessageFile"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,\
00,6f,00,74,00,25,00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,\
5c,00,6d,00,73,00,63,00,6f,00,72,00,65,00,65,00,2e,00,64,00,6c,00,6c,00,00,\
00
-----------------------------------------------------------------------------------------*/
#pragma once
#ifdef _WIN32
#include <winbase.h>
#endif
#include <spdlog/details/null_mutex.h>
#include <spdlog/sinks/base_sink.h>
#include <mutex>
#include <string>
namespace
spdlog
{
namespace
sinks
{
/*
* Windows Event Log sink
*/
template
<
typename
Mutex
>
class
eventlog_sink
:
public
base_sink
<
Mutex
>
{
public:
explicit
eventlog_sink
(
std
::
string
const
&
source
,
std
::
string
const
&
log
=
"Application"
,
std
::
string
const
&
message_file_path
=
"%windir%
\\
System32
\\
mscoree.dll"
);
eventlog_sink
(
eventlog_sink
const
&
)
=
delete
;
eventlog_sink
&
operator
=
(
eventlog_sink
const
&
)
=
delete
;
protected:
void
sink_it_
(
const
details
::
log_msg
&
msg
)
override
;
void
flush_
()
override
{}
virtual
void
set_pattern_
(
const
std
::
string
&
pattern
)
override
;
virtual
void
set_formatter_
(
std
::
unique_ptr
<
spdlog
::
formatter
>
sink_formatter
)
override
;
private:
std
::
unique_ptr
<
sink
>
impl_
;
};
#ifdef _WIN32
#include "eventlog_sink_win32.h"
#else
template
<
typename
Mutex
>
eventlog_sink
<
Mutex
>::
eventlog_sink
(
std
::
string
const
&
source
,
std
::
string
const
&
log
,
std
::
string
const
&
message_file_path
)
{
}
template
<
typename
Mutex
>
void
eventlog_sink
<
Mutex
>::
sink_it_
(
const
details
::
log_msg
&
msg
)
{}
#endif
template
<
typename
Mutex
>
void
eventlog_sink
<
Mutex
>::
set_pattern_
(
const
std
::
string
&
pattern
)
{
if
(
impl_
)
impl_
->
set_pattern
(
pattern
);
}
template
<
typename
Mutex
>
void
eventlog_sink
<
Mutex
>::
set_formatter_
(
std
::
unique_ptr
<
spdlog
::
formatter
>
sink_formatter
)
{
if
(
impl_
)
impl_
->
set_formatter
(
std
::
move
(
sink_formatter
));
}
using
eventlog_sink_mt
=
eventlog_sink
<
std
::
mutex
>
;
using
eventlog_sink_st
=
eventlog_sink
<
details
::
null_mutex
>
;
using
windebug_sink_mt
=
eventlog_sink_mt
;
using
windebug_sink_st
=
eventlog_sink_st
;
}
// namespace sinks
}
// namespace spdlog
include/spdlog/sinks/
eventlog_sink_win32
.h
→
include/spdlog/sinks/
win_eventlog_sink
.h
View file @
4bece787
This diff is collapsed.
Click to expand it.
tests/test_eventlog.cpp
View file @
4bece787
...
...
@@ -2,10 +2,13 @@
#include "test_sink.h"
#include "spdlog/fmt/bin_to_hex.h"
#include "spdlog/sinks/eventlog_sink.h"
#if _WIN32
#include "spdlog/sinks/win_eventlog_sink.h"
static
const
LPCSTR
TEST_LOG
=
"my log"
;
static
const
LPCSTR
TEST_SOURCE
=
"my source"
;
static
void
test_single_print
(
std
::
function
<
void
(
std
::
string
const
&
)
>
do_print
,
std
::
string
const
&
expectedContents
,
WORD
expectedEventType
)
{
do_print
(
expectedContents
);
...
...
@@ -22,7 +25,7 @@ static void test_single_print(std::function<void(std::string const&)> do_print,
if
(
handle_
)
REQUIRE
(
CloseEventLog
(
handle_
));
}
}
eventLog
{
OpenEventLog
(
nullptr
,
"my_source"
)};
}
eventLog
{
OpenEventLog
(
nullptr
,
TEST_SOURCE
)};
REQUIRE
(
eventLog
.
handle_
);
...
...
@@ -49,7 +52,7 @@ TEST_CASE("eventlog", "[eventlog]")
{
using
namespace
spdlog
;
auto
test_sink
=
std
::
make_shared
<
sinks
::
eventlog_sink_mt
>
(
"my_source"
,
"my_spd_log"
);
auto
test_sink
=
std
::
make_shared
<
sinks
::
win_eventlog_sink_mt
>
(
TEST_SOURCE
);
spdlog
::
logger
test_logger
(
"eventlog"
,
test_sink
);
test_logger
.
set_level
(
level
::
trace
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment