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
e68cf1c9
Commit
e68cf1c9
authored
Jun 18, 2019
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add formatting option to syslog in ctor. Fix issue #729 #1107
parent
f0fcc73f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
10 deletions
+31
-10
syslog_sink.h
include/spdlog/sinks/syslog_sink.h
+31
-10
No files found.
include/spdlog/sinks/syslog_sink.h
View file @
e68cf1c9
...
@@ -13,16 +13,15 @@ namespace spdlog {
...
@@ -13,16 +13,15 @@ namespace spdlog {
namespace
sinks
{
namespace
sinks
{
/**
/**
* Sink that write to syslog using the `syscall()` library call.
* Sink that write to syslog using the `syscall()` library call.
*
* Locking is not needed, as `syslog()` itself is thread-safe.
*/
*/
template
<
typename
Mutex
>
template
<
typename
Mutex
>
class
syslog_sink
:
public
base_sink
<
Mutex
>
class
syslog_sink
:
public
base_sink
<
Mutex
>
{
{
public
:
public
:
//
syslog_sink
(
std
::
string
ident
,
int
syslog_option
,
int
syslog_facility
,
bool
enable_formatting
)
:
explicit
syslog_sink
(
std
::
string
ident
=
""
,
int
syslog_option
=
0
,
int
syslog_facility
=
LOG_USER
)
enable_formatting_
{
enable_formatting
},
:
ident_
(
std
::
move
(
ident
))
ident_
{
std
::
move
(
ident
)}
{
{
priorities_
[
static_cast
<
size_t
>
(
level
::
trace
)]
=
LOG_DEBUG
;
priorities_
[
static_cast
<
size_t
>
(
level
::
trace
)]
=
LOG_DEBUG
;
priorities_
[
static_cast
<
size_t
>
(
level
::
debug
)]
=
LOG_DEBUG
;
priorities_
[
static_cast
<
size_t
>
(
level
::
debug
)]
=
LOG_DEBUG
;
...
@@ -47,10 +46,24 @@ public:
...
@@ -47,10 +46,24 @@ public:
protected
:
protected
:
void
sink_it_
(
const
details
::
log_msg
&
msg
)
override
void
sink_it_
(
const
details
::
log_msg
&
msg
)
override
{
{
::
syslog
(
syslog_prio_from_level
(
msg
),
"%s"
,
fmt
::
to_string
(
msg
.
payload
).
c_str
());
string_view_t
payload
;
if
(
enable_formatting_
)
{
fmt
::
memory_buffer
formatted
;
sink
::
formatter_
->
format
(
msg
,
formatted
);
payload
=
string_view_t
(
formatted
.
data
(),
formatted
.
size
());
}
else
{
payload
=
msg
.
payload
;
}
::
syslog
(
syslog_prio_from_level
(
msg
),
"%s"
,
payload
.
data
());
}
}
void
flush_
()
override
{}
void
flush_
()
override
{}
bool
enable_formatting_
=
false
;
private
:
private
:
std
::
array
<
int
,
7
>
priorities_
;
std
::
array
<
int
,
7
>
priorities_
;
...
@@ -74,15 +87,23 @@ using syslog_sink_st = syslog_sink<details::null_mutex>;
...
@@ -74,15 +87,23 @@ using syslog_sink_st = syslog_sink<details::null_mutex>;
// Create and register a syslog logger
// Create and register a syslog logger
template
<
typename
Factory
=
default_factory
>
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
syslog_logger_mt
(
inline
std
::
shared_ptr
<
logger
>
syslog_logger_mt
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
syslog_ident
=
""
,
int
syslog_option
=
0
,
int
syslog_facility
=
(
1
<<
3
))
const
std
::
string
&
logger_name
,
const
std
::
string
&
syslog_ident
=
""
,
int
syslog_option
=
0
,
int
syslog_facility
=
LOG_USER
,
bool
enable_formatting
=
false
)
{
{
return
Factory
::
template
create
<
sinks
::
syslog_sink_mt
>
(
logger_name
,
syslog_ident
,
syslog_option
,
syslog_facility
);
return
Factory
::
template
create
<
sinks
::
syslog_sink_mt
>
(
logger_name
,
syslog_ident
,
syslog_option
,
syslog_facility
,
enable_formatting
);
}
}
template
<
typename
Factory
=
default_factory
>
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
syslog_logger_st
(
inline
std
::
shared_ptr
<
logger
>
syslog_logger_st
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
syslog_ident
=
""
,
int
syslog_option
=
0
,
int
syslog_facility
=
(
1
<<
3
))
const
std
::
string
&
logger_name
,
const
std
::
string
&
syslog_ident
=
""
,
int
syslog_option
=
0
,
int
syslog_facility
=
LOG_USER
,
bool
enable_formatting
=
false
)
{
{
return
Factory
::
template
create
<
sinks
::
syslog_sink_st
>
(
logger_name
,
syslog_ident
,
syslog_option
,
syslog_facility
);
return
Factory
::
template
create
<
sinks
::
syslog_sink_st
>
(
logger_name
,
syslog_ident
,
syslog_option
,
syslog_facility
,
enable_formatting
);
}
}
}
// namespace spdlog
}
// namespace spdlog
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