Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
S
spdlog
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
spdlog
Commits
8b403081
Unverified
Commit
8b403081
authored
Jun 28, 2019
by
Gabi Melman
Committed by
GitHub
Jun 28, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1122 from jbelloncastro/v1.x
Provide source location support for systemd_sink.h
parents
94c2810b
dc054c3f
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
7 deletions
+26
-7
systemd_sink.h
include/spdlog/sinks/systemd_sink.h
+25
-6
CMakeLists.txt
tests/CMakeLists.txt
+0
-0
test_systemd.cpp
tests/test_systemd.cpp
+1
-1
No files found.
include/spdlog/sinks/systemd_sink.h
View file @
8b403081
...
@@ -7,8 +7,6 @@
...
@@ -7,8 +7,6 @@
#include "spdlog/details/null_mutex.h"
#include "spdlog/details/null_mutex.h"
#include "spdlog/details/synchronous_factory.h"
#include "spdlog/details/synchronous_factory.h"
#include <array>
#include <string>
#include <systemd/sd-journal.h>
#include <systemd/sd-journal.h>
namespace
spdlog
{
namespace
spdlog
{
...
@@ -36,16 +34,16 @@ inline int syslog_level(level::level_enum l)
...
@@ -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
>
template
<
typename
Mutex
>
class
systemd_sink
:
public
base_sink
<
Mutex
>
class
systemd_sink
:
public
base_sink
<
Mutex
>
{
{
public
:
public
:
//
//
explicit
systemd_sink
(
void
)
{}
explicit
systemd_sink
()
{}
~
systemd_sink
()
override
{}
~
systemd_sink
()
override
{}
...
@@ -55,9 +53,30 @@ public:
...
@@ -55,9 +53,30 @@ public:
protected
:
protected
:
void
sink_it_
(
const
details
::
log_msg
&
msg
)
override
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"
);
throw
spdlog_ex
(
"Failed writing to systemd"
);
}
}
}
void
flush_
()
override
{}
void
flush_
()
override
{}
};
};
...
...
tests/CMakeLists.txt
View file @
8b403081
tests/test_systemd.cpp
View file @
8b403081
...
@@ -8,6 +8,6 @@ TEST_CASE("systemd", "[all]")
...
@@ -8,6 +8,6 @@ TEST_CASE("systemd", "[all]")
spdlog
::
logger
logger
(
"spdlog_systemd_test"
,
systemd_sink
);
spdlog
::
logger
logger
(
"spdlog_systemd_test"
,
systemd_sink
);
logger
.
debug
(
"test debug"
);
logger
.
debug
(
"test debug"
);
logger
.
error
(
"test error"
);
SPDLOG_LOGGER_ERROR
((
&
logger
),
"test error"
);
logger
.
info
(
"test info"
);
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