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
8c9a6fc0
Commit
8c9a6fc0
authored
Dec 16, 2014
by
fooinha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
* openlog setup for syslog sink
parent
fbd2a33b
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
56 additions
and
14 deletions
+56
-14
example/example.cpp
example/example.cpp
+3
-2
include/spdlog/details/format.h
include/spdlog/details/format.h
+10
-6
include/spdlog/details/pattern_formatter_impl.h
include/spdlog/details/pattern_formatter_impl.h
+1
-1
include/spdlog/details/spdlog_impl.h
include/spdlog/details/spdlog_impl.h
+2
-2
include/spdlog/sinks/syslog_sink.h
include/spdlog/sinks/syslog_sink.h
+39
-2
include/spdlog/spdlog.h
include/spdlog/spdlog.h
+1
-1
No files found.
example/example.cpp
View file @
8c9a6fc0
...
...
@@ -85,7 +85,8 @@ int main(int, char* [])
// syslog example
//
#ifdef __linux__
auto
syslog_logger
=
spd
::
syslog_logger
(
"syslog"
);
std
::
string
ident
=
"my_ident"
;
auto
syslog_logger
=
spd
::
syslog_logger
(
"syslog"
,
ident
,
spd
::
sinks
::
syslog
::
option
::
PID
|
spd
::
sinks
::
syslog
::
option
::
PERROR
,
"mail"
);
syslog_logger
->
warn
(
"This is warning that will end up in syslog. This is Linux only!"
);
#endif
}
...
...
include/spdlog/details/format.h
View file @
8c9a6fc0
...
...
@@ -115,8 +115,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define FMT_DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName&); \
void operator=(const TypeName&)
namespace
spdlog
{
namespace
details
{
namespace
spdlog
{
namespace
details
{
namespace
fmt
{
...
...
@@ -2849,8 +2851,10 @@ fmt::print(format, args...);
#define FMT_VARIADIC_W(ReturnType, func, ...) \
FMT_VARIADIC_(wchar_t, ReturnType, func, return func, __VA_ARGS__)
namespace
spdlog
{
namespace
details
{
namespace
spdlog
{
namespace
details
{
namespace
fmt
{
FMT_VARIADIC
(
std
::
string
,
format
,
StringRef
)
...
...
include/spdlog/details/pattern_formatter_impl.h
View file @
8c9a6fc0
include/spdlog/details/spdlog_impl.h
View file @
8c9a6fc0
...
...
@@ -87,9 +87,9 @@ inline std::shared_ptr<spdlog::logger> spdlog::stderr_logger_st(const std::strin
#ifdef __linux__
// Create syslog logger
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
syslog_logger
(
const
std
::
string
&
logger_name
)
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
syslog_logger
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
ident
,
int
option
,
const
std
::
string
&
facility
)
{
return
create
<
spdlog
::
sinks
::
syslog_sink
>
(
logger_name
);
return
create
<
spdlog
::
sinks
::
syslog_sink
>
(
logger_name
,
ident
,
option
,
facility
);
}
#endif
...
...
include/spdlog/sinks/syslog_sink.h
View file @
8c9a6fc0
...
...
@@ -27,6 +27,9 @@
#ifdef __linux__
#include <string>
#define SYSLOG_NAMES 1
#include <syslog.h>
#include "./sink.h"
#include "../common.h"
...
...
@@ -37,6 +40,21 @@ namespace spdlog
{
namespace
sinks
{
namespace
syslog
{
namespace
option
{
typedef
enum
{
CONS
=
LOG_CONS
,
NDELAY
=
LOG_NDELAY
,
NOWAIT
=
LOG_NOWAIT
,
ODELAY
=
LOG_ODELAY
,
PERROR
=
LOG_PERROR
,
PID
=
LOG_PID
}
option_enum
;
}
}
/**
* Sink that write to syslog using the `syscall()` library call.
*
...
...
@@ -45,8 +63,9 @@ namespace sinks
class
syslog_sink
:
public
sink
{
public:
syslog_sink
()
syslog_sink
(
const
std
::
string
&
ident
=
""
,
int
option
=
static_cast
<
int
>
(
syslog
::
option
::
PID
),
const
std
::
string
&
facility
=
"user"
)
{
_priorities
[
static_cast
<
int
>
(
level
::
TRACE
)]
=
LOG_DEBUG
;
_priorities
[
static_cast
<
int
>
(
level
::
DEBUG
)]
=
LOG_DEBUG
;
_priorities
[
static_cast
<
int
>
(
level
::
INFO
)]
=
LOG_INFO
;
...
...
@@ -59,6 +78,8 @@ public:
_priorities
[
static_cast
<
int
>
(
level
::
ALWAYS
)]
=
LOG_INFO
;
_priorities
[
static_cast
<
int
>
(
level
::
OFF
)]
=
LOG_INFO
;
::
openlog
(
ident
.
c_str
(),
option
,
syslog_facility_from_name
(
facility
));
}
virtual
~
syslog_sink
()
=
default
;
...
...
@@ -67,10 +88,11 @@ public:
void
log
(
const
details
::
log_msg
&
msg
)
override
{
syslog
(
syslog_prio_from_level
(
msg
),
"%s"
,
msg
.
formatted
.
str
().
c_str
());
::
syslog
(
syslog_prio_from_level
(
msg
),
"%s"
,
msg
.
formatted
.
str
().
c_str
());
};
protected:
/**
* Simply maps spdlog's log level to syslog priority level.
*/
...
...
@@ -81,6 +103,21 @@ protected:
private:
std
::
array
<
int
,
11
>
_priorities
;
inline
int
syslog_facility_from_name
(
const
std
::
string
&
name
)
{
if
(
name
.
empty
())
return
LOG_USER
;
for
(
int
i
=
0
;
facilitynames
[
i
].
c_name
!=
NULL
;
++
i
)
{
if
(
name
==
facilitynames
[
i
].
c_name
)
return
facilitynames
[
i
].
c_val
;
}
return
LOG_USER
;
}
};
}
}
...
...
include/spdlog/spdlog.h
View file @
8c9a6fc0
...
...
@@ -96,7 +96,7 @@ std::shared_ptr<logger> stderr_logger_st(const std::string& logger_name);
// Create a syslog logger
//
#ifdef __linux__
std
::
shared_ptr
<
logger
>
syslog_logger
(
const
std
::
string
&
logger_name
);
std
::
shared_ptr
<
logger
>
syslog_logger
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
ident
,
int
option
,
const
std
::
string
&
facility
);
#endif
//
...
...
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