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
3b61f50c
Commit
3b61f50c
authored
Dec 18, 2014
by
Gabi Melman
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #20 from fooinha/syslog-openlog
Syslog openlog
parents
ce6ee347
630e301e
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
75 additions
and
18 deletions
+75
-18
README.md
README.md
+2
-1
example/Makefile
example/Makefile
+1
-1
example/example.cpp
example/example.cpp
+2
-1
include/spdlog/common.h
include/spdlog/common.h
+29
-0
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
-3
include/spdlog/sinks/syslog_sink.h
include/spdlog/sinks/syslog_sink.h
+26
-4
include/spdlog/spdlog.h
include/spdlog/spdlog.h
+2
-1
No files found.
README.md
View file @
3b61f50c
...
@@ -97,7 +97,8 @@ int main(int, char* [])
...
@@ -97,7 +97,8 @@ int main(int, char* [])
// syslog example
// syslog example
//
//
#ifdef __linux__
#ifdef __linux__
auto
syslog_logger
=
spd
::
syslog_logger
(
"syslog"
);
std
::
string
ident
=
"my_app"
;
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!"
);
syslog_logger
->
warn
(
"This is warning that will end up in syslog. This is Linux only!"
);
#endif
#endif
}
}
...
...
example/Makefile
View file @
3b61f50c
...
@@ -5,7 +5,7 @@ CXX_DEBUG_FLAGS= -g
...
@@ -5,7 +5,7 @@ CXX_DEBUG_FLAGS= -g
all
:
example bench
all
:
example bench
debug
:
example-debug bench-debug
debug
:
example-debug bench-debug
example
:
example.cpp
example
:
example.cpp
$(CXX)
example.cpp
-o
example
$(CXXFLAGS)
$(CXX_RELEASE_FLAGS)
$(CXX)
example.cpp
-o
example
$(CXXFLAGS)
$(CXX_RELEASE_FLAGS)
...
...
example/example.cpp
View file @
3b61f50c
...
@@ -86,7 +86,8 @@ int main(int, char* [])
...
@@ -86,7 +86,8 @@ int main(int, char* [])
// syslog example
// syslog example
//
//
#ifdef __linux__
#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!"
);
syslog_logger
->
warn
(
"This is warning that will end up in syslog. This is Linux only!"
);
#endif
#endif
}
}
...
...
include/spdlog/common.h
View file @
3b61f50c
...
@@ -27,13 +27,42 @@
...
@@ -27,13 +27,42 @@
#include<initializer_list>
#include<initializer_list>
#include<chrono>
#include<chrono>
#ifdef __linux__
#define SYSLOG_NAMES 1
#include <syslog.h>
#endif
namespace
spdlog
namespace
spdlog
{
{
class
formatter
;
class
formatter
;
namespace
sinks
namespace
sinks
{
{
class
sink
;
class
sink
;
#ifdef __linux__
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
;
}
}
}
#endif
}
// Common types across the lib
// Common types across the lib
using
log_clock
=
std
::
chrono
::
system_clock
;
using
log_clock
=
std
::
chrono
::
system_clock
;
...
...
include/spdlog/details/format.h
View file @
3b61f50c
...
@@ -115,8 +115,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
...
@@ -115,8 +115,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define FMT_DISALLOW_COPY_AND_ASSIGN(TypeName) \
#define FMT_DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName&); \
TypeName(const TypeName&); \
void operator=(const TypeName&)
void operator=(const TypeName&)
namespace
spdlog
{
namespace
spdlog
namespace
details
{
{
namespace
details
{
namespace
fmt
namespace
fmt
{
{
...
@@ -1054,7 +1056,7 @@ public:
...
@@ -1054,7 +1056,7 @@ public:
{
{
default:
default:
assert
(
false
);
assert
(
false
);
// Fall through.
// Fall through.
case
Arg
:
:
INT
:
case
Arg
:
:
INT
:
return
FMT_DISPATCH
(
visit_int
(
arg
.
int_value
));
return
FMT_DISPATCH
(
visit_int
(
arg
.
int_value
));
case
Arg
:
:
UINT
:
case
Arg
:
:
UINT
:
...
@@ -2223,7 +2225,7 @@ void BasicWriter<Char>::write_double(
...
@@ -2223,7 +2225,7 @@ void BasicWriter<Char>::write_double(
// MSVC's printf doesn't support 'F'.
// MSVC's printf doesn't support 'F'.
type
=
'f'
;
type
=
'f'
;
#endif
#endif
// Fall through.
// Fall through.
case
'E'
:
case
'E'
:
case
'G'
:
case
'G'
:
case
'A'
:
case
'A'
:
...
@@ -2849,8 +2851,10 @@ fmt::print(format, args...);
...
@@ -2849,8 +2851,10 @@ fmt::print(format, args...);
#define FMT_VARIADIC_W(ReturnType, func, ...) \
#define FMT_VARIADIC_W(ReturnType, func, ...) \
FMT_VARIADIC_(wchar_t, ReturnType, func, return func, __VA_ARGS__)
FMT_VARIADIC_(wchar_t, ReturnType, func, return func, __VA_ARGS__)
namespace
spdlog
{
namespace
spdlog
namespace
details
{
{
namespace
details
{
namespace
fmt
namespace
fmt
{
{
FMT_VARIADIC
(
std
::
string
,
format
,
StringRef
)
FMT_VARIADIC
(
std
::
string
,
format
,
StringRef
)
...
...
include/spdlog/details/pattern_formatter_impl.h
View file @
3b61f50c
...
@@ -458,7 +458,7 @@ inline void spdlog::pattern_formatter::handle_flag(char flag)
...
@@ -458,7 +458,7 @@ inline void spdlog::pattern_formatter::handle_flag(char flag)
{
{
switch
(
flag
)
switch
(
flag
)
{
{
// logger name
// logger name
case
'n'
:
case
'n'
:
_formatters
.
push_back
(
std
::
unique_ptr
<
details
::
flag_formatter
>
(
new
details
::
name_formatter
()));
_formatters
.
push_back
(
std
::
unique_ptr
<
details
::
flag_formatter
>
(
new
details
::
name_formatter
()));
break
;
break
;
...
...
include/spdlog/details/spdlog_impl.h
View file @
3b61f50c
...
@@ -87,11 +87,10 @@ inline std::shared_ptr<spdlog::logger> spdlog::stderr_logger_st(const std::strin
...
@@ -87,11 +87,10 @@ inline std::shared_ptr<spdlog::logger> spdlog::stderr_logger_st(const std::strin
#ifdef __linux__
#ifdef __linux__
// Create syslog logger
// 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
#endif
...
...
include/spdlog/sinks/syslog_sink.h
View file @
3b61f50c
...
@@ -27,7 +27,8 @@
...
@@ -27,7 +27,8 @@
#ifdef __linux__
#ifdef __linux__
#include <string>
#include <string>
#include <syslog.h>
#include "./sink.h"
#include "./sink.h"
#include "../common.h"
#include "../common.h"
#include "../details/log_msg.h"
#include "../details/log_msg.h"
...
@@ -45,8 +46,9 @@ namespace sinks
...
@@ -45,8 +46,9 @@ namespace sinks
class
syslog_sink
:
public
sink
class
syslog_sink
:
public
sink
{
{
public:
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
::
TRACE
)]
=
LOG_DEBUG
;
_priorities
[
static_cast
<
int
>
(
level
::
DEBUG
)]
=
LOG_DEBUG
;
_priorities
[
static_cast
<
int
>
(
level
::
DEBUG
)]
=
LOG_DEBUG
;
_priorities
[
static_cast
<
int
>
(
level
::
INFO
)]
=
LOG_INFO
;
_priorities
[
static_cast
<
int
>
(
level
::
INFO
)]
=
LOG_INFO
;
...
@@ -59,18 +61,23 @@ public:
...
@@ -59,18 +61,23 @@ public:
_priorities
[
static_cast
<
int
>
(
level
::
ALWAYS
)]
=
LOG_INFO
;
_priorities
[
static_cast
<
int
>
(
level
::
ALWAYS
)]
=
LOG_INFO
;
_priorities
[
static_cast
<
int
>
(
level
::
OFF
)]
=
LOG_INFO
;
_priorities
[
static_cast
<
int
>
(
level
::
OFF
)]
=
LOG_INFO
;
::
openlog
(
ident
.
c_str
(),
option
,
syslog_facility_from_name
(
facility
));
}
virtual
~
syslog_sink
()
{
::
closelog
();
}
}
virtual
~
syslog_sink
()
=
default
;
syslog_sink
(
const
syslog_sink
&
)
=
delete
;
syslog_sink
(
const
syslog_sink
&
)
=
delete
;
syslog_sink
&
operator
=
(
const
syslog_sink
&
)
=
delete
;
syslog_sink
&
operator
=
(
const
syslog_sink
&
)
=
delete
;
void
log
(
const
details
::
log_msg
&
msg
)
override
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:
protected:
/**
/**
* Simply maps spdlog's log level to syslog priority level.
* Simply maps spdlog's log level to syslog priority level.
*/
*/
...
@@ -81,6 +88,21 @@ protected:
...
@@ -81,6 +88,21 @@ protected:
private:
private:
std
::
array
<
int
,
11
>
_priorities
;
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 @
3b61f50c
...
@@ -96,7 +96,8 @@ std::shared_ptr<logger> stderr_logger_st(const std::string& logger_name);
...
@@ -96,7 +96,8 @@ std::shared_ptr<logger> stderr_logger_st(const std::string& logger_name);
// Create a syslog logger
// Create a syslog logger
//
//
#ifdef __linux__
#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
=
static_cast
<
int
>
(
sinks
::
syslog
::
option
::
PID
),
const
std
::
string
&
facility
=
"user"
);
#endif
#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