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
a13981ff
Commit
a13981ff
authored
Jun 27, 2019
by
Jorge Bellon-Castro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Provide source location support for systemd_sink.h
parent
3d069f7b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
8 deletions
+27
-8
include/spdlog/sinks/systemd_sink.h
include/spdlog/sinks/systemd_sink.h
+25
-6
tests/CMakeLists.txt
tests/CMakeLists.txt
+1
-1
tests/test_systemd.cpp
tests/test_systemd.cpp
+1
-1
No files found.
include/spdlog/sinks/systemd_sink.h
View file @
a13981ff
...
...
@@ -7,8 +7,6 @@
#include "spdlog/details/null_mutex.h"
#include "spdlog/details/synchronous_factory.h"
#include <array>
#include <string>
#include <systemd/sd-journal.h>
namespace
spdlog
{
...
...
@@ -36,16 +34,16 @@ inline int syslog_level(level::level_enum l)
}
/**
* Sink that write to systemd
using the `sd_journal_print
()` library call.
* Sink that write to systemd
journal using the `sd_journal_send
()` library call.
*
* Locking is not needed, as `sd_journal_
print
()` itself is thread-safe.
* Locking is not needed, as `sd_journal_
send
()` itself is thread-safe.
*/
template
<
typename
Mutex
>
class
systemd_sink
:
public
base_sink
<
Mutex
>
{
public:
//
explicit
systemd_sink
(
void
)
{}
explicit
systemd_sink
()
{}
~
systemd_sink
()
override
{}
...
...
@@ -55,8 +53,29 @@ public:
protected:
void
sink_it_
(
const
details
::
log_msg
&
msg
)
override
{
if
(
sd_journal_print
(
syslog_level
(
msg
.
level
),
"%.*s"
,
static_cast
<
int
>
(
msg
.
payload
.
size
()),
msg
.
payload
.
data
()))
const
char
*
key_msg
=
"MESSAGE=%.*s"
;
const
char
*
key_prio
=
"PRIORITY=%d"
;
const
char
*
key_file
=
"CODE_FILE=%s"
;
const
char
*
key_line
=
"CODE_LINE=%d"
;
const
char
*
key_func
=
"CODE_FUNC=%s"
;
if
(
!
msg
.
source
.
filename
||
!
msg
.
source
.
funcname
||
msg
.
source
.
line
==
0
)
{
// Do not send source location if not available
key_file
=
nullptr
;
}
// Note: function call inside '()' to avoid macro expansion
int
err
=
(
sd_journal_send
)(
key_msg
,
static_cast
<
int
>
(
msg
.
payload
.
size
()),
msg
.
payload
.
data
(),
key_prio
,
syslog_level
(
msg
.
level
),
key_file
,
msg
.
source
.
filename
,
key_line
,
msg
.
source
.
line
,
key_func
,
msg
.
source
.
funcname
,
nullptr
);
if
(
err
)
{
throw
spdlog_ex
(
"Failed writing to systemd"
);
}
}
void
flush_
()
override
{}
...
...
tests/CMakeLists.txt
View file @
a13981ff
...
...
@@ -14,7 +14,7 @@ set(SPDLOG_UTESTS_SOURCES
test_mpmc_q.cpp
test_sink.h
test_fmt_helper.cpp
test_stdout_api.cpp
)
test_stdout_api.cpp
)
file
(
MAKE_DIRECTORY
"
${
CMAKE_CURRENT_BINARY_DIR
}
/logs"
)
enable_testing
()
...
...
tests/test_systemd.cpp
View file @
a13981ff
...
...
@@ -8,6 +8,6 @@ TEST_CASE("systemd", "[all]")
spdlog
::
logger
logger
(
"spdlog_systemd_test"
,
systemd_sink
);
logger
.
debug
(
"test debug"
);
logger
.
error
(
"test error"
);
SPDLOG_LOGGER_ERROR
((
&
logger
),
"test error"
);
logger
.
info
(
"test info"
);
}
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