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
b1867cfb
Commit
b1867cfb
authored
Dec 21, 2014
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
log levels now lowercase
parent
892de62f
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
68 additions
and
78 deletions
+68
-78
README.md
README.md
+3
-3
example/example.cpp
example/example.cpp
+21
-31
include/spdlog/common.h
include/spdlog/common.h
+10
-10
include/spdlog/details/async_logger_impl.h
include/spdlog/details/async_logger_impl.h
+1
-1
include/spdlog/details/log_msg.h
include/spdlog/details/log_msg.h
+1
-1
include/spdlog/details/logger_impl.h
include/spdlog/details/logger_impl.h
+20
-20
include/spdlog/details/registry.h
include/spdlog/details/registry.h
+2
-2
include/spdlog/sinks/syslog_sink.h
include/spdlog/sinks/syslog_sink.h
+10
-10
No files found.
README.md
View file @
b1867cfb
...
...
@@ -68,7 +68,7 @@ int main(int, char* [])
try
{
// Set log level to all loggers to DEBUG and above
spd
::
set_level
(
spd
::
level
::
DEBUG
);
spd
::
set_level
(
spd
::
level
::
debug
);
//Create console, multithreaded logger
auto
console
=
spd
::
stdout_logger_mt
(
"console"
);
...
...
@@ -87,7 +87,7 @@ int main(int, char* [])
//Create a file rotating logger with 5mb size max and 3 rotated files
auto
file_logger
=
spd
::
rotating_logger_mt
(
"file_logger"
,
"logs/mylogfile"
,
1048576
*
5
,
3
);
file_logger
->
set_level
(
spd
::
level
::
INFO
);
file_logger
->
set_level
(
spd
::
level
::
info
);
for
(
int
i
=
0
;
i
<
10
;
++
i
)
file_logger
->
info
(
"{} * {} equals {:>10}"
,
i
,
i
,
i
*
i
);
...
...
@@ -114,7 +114,7 @@ int main(int, char* [])
//
#ifdef __linux__
std
::
string
ident
=
"my_app"
;
auto
syslog_logger
=
spd
::
syslog_logger
(
"syslog"
,
ident
,
spd
::
sinks
::
syslog
::
option
::
PID
|
spd
::
sinks
::
syslog
::
option
::
PERROR
,
"mail"
);
auto
syslog_logger
=
spd
::
syslog_logger
(
"syslog"
,
ident
,
LOG_PID
|
LOG_PERROR
);
syslog_logger
->
warn
(
"This is warning that will end up in syslog. This is Linux only!"
);
#endif
}
...
...
example/example.cpp
View file @
b1867cfb
...
...
@@ -28,17 +28,13 @@
#include <iostream>
#include "spdlog/spdlog.h"
int
main
(
int
,
char
*
[])
{
namespace
spd
=
spdlog
;
try
{
std
::
string
filename
=
"logs/spdlog_example"
;
// Set log level to all loggers to DEBUG and above
spd
::
set_level
(
spd
::
level
::
DEBUG
);
spd
::
set_level
(
spd
::
level
::
debug
);
//Create console, multithreaded logger
auto
console
=
spd
::
stdout_logger_mt
(
"console"
);
...
...
@@ -47,55 +43,49 @@ int main(int, char* [])
console
->
info
()
<<
"Streams are supported too "
<<
1
;
console
->
info
(
"Easy padding in numbers like {:08d}"
,
12
);
console
->
info
(
"Support for int: {0:d}; hex: {0:
08
x}; oct: {0:o}; bin: {0:b}"
,
42
);
console
->
info
(
"Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}"
,
42
);
console
->
info
(
"Support for floats {:03.2f}"
,
1.23456
);
console
->
info
(
"Positional args are {1} {0}.."
,
"too"
,
"supported"
);
console
->
info
(
"{:<30}"
,
"left aligned"
);
console
->
info
(
"{:>30}"
,
"right aligned"
);
console
->
info
(
"{:^30}"
,
"centered"
);
//Create a file rotating logger with 5mb size max and 3 rotated files
auto
file_logger
=
spd
::
rotating_logger_mt
(
"file_logger"
,
filename
,
1024
*
1024
*
5
,
3
);
file_logger
->
info
(
"Log file message number"
,
1
);
auto
file_logger
=
spd
::
rotating_logger_mt
(
"file_logger"
,
"logs/mylogfile"
,
1048576
*
5
,
3
);
file_logger
->
set_level
(
spd
::
level
::
info
);
for
(
int
i
=
0
;
i
<
10
;
++
i
)
file_logger
->
info
(
"{} * {} equals {:>10}"
,
i
,
i
,
i
*
i
);
file_logger
->
info
(
"{} * {} equals {:>10}"
,
i
,
i
,
i
*
i
);
//Customize msg format for all messages
spd
::
set_pattern
(
"*** [%H:%M:%S %z] [thread %t] %v ***"
);
file_logger
->
info
(
"This is another message with custom format"
);
spd
::
get
(
"console"
)
->
info
(
"loggers can be retrieved from a global registry using the spdlog::get(logger_name) function"
);
// Debug and trace macros to be turned on/off at compile time.
// Evaluates to empty statements if not turned on
// Define SPDLOG_DEBUG_ON or SPDLOG_TRACE_ON - before including spdlog.h
SPDLOG_TRACE
(
console
,
"Enabled only #ifdef SPDLOG_TRACE_ON..{} ,{}"
,
1
,
3.23
);
SPDLOG_DEBUG
(
console
,
"Enabled only #ifdef SPDLOG_DEBUG_ON.. {} ,{}"
,
1
,
3.23
);
#ifdef __linux__
// syslog example
std
::
string
ident
=
"spdlog_example"
;
// empty ident can be used to use current program name
auto
syslog_logger
=
spd
::
syslog_logger
(
"syslog"
,
ident
,
LOG_PID
);
syslog_logger
->
set_pattern
(
"[%l] %v"
);
//syslog already put timestamps so set the pattern to minimum (log level and the message)
syslog_logger
->
warn
(
"This message that will end up in syslog. This is Linux only.."
);
#endif
// Asynchronous logging is easy..
//
// Asynchronous logging is very fast..
// Just call spdlog::set_async_mode(q_size) and all created loggers from now on will be asynchronous..
//
Note: queue size must be power of 2!
size_t
q_size
=
1048576
;
//
size_t
q_size
=
1048576
;
//queue size must be power of 2
spdlog
::
set_async_mode
(
q_size
);
auto
async_file
=
spd
::
daily_logger_st
(
"async_file_logger"
,
"logs/async_log.txt"
);
for
(
int
i
=
0
;
i
<
100
;
i
++
)
async_file
->
info
(
"This is async log message #{}.. Should be very fast.. "
,
i
);
async_file
->
info
()
<<
"This is async log.."
<<
"Should be very fast!"
;
//
// syslog example
//
#ifdef __linux__
std
::
string
ident
=
"my_app"
;
auto
syslog_logger
=
spd
::
syslog_logger
(
"syslog"
,
ident
,
LOG_PID
|
LOG_PERROR
);
syslog_logger
->
warn
(
"This is warning that will end up in syslog. This is Linux only!"
);
#endif
}
catch
(
const
spd
::
spdlog_ex
&
ex
)
{
std
::
cout
<<
"Log failed: "
<<
ex
.
what
()
<<
std
::
endl
;
}
return
0
;
}
include/spdlog/common.h
View file @
b1867cfb
...
...
@@ -54,16 +54,16 @@ namespace level
{
typedef
enum
{
TRACE
=
0
,
DEBUG
=
1
,
INFO
=
2
,
NOTICE
=
3
,
WARN
=
4
,
ERR
=
5
,
CRITICAL
=
6
,
ALERT
=
7
,
EMERG
=
8
,
OFF
=
9
trace
=
0
,
debug
=
1
,
info
=
2
,
notice
=
3
,
warn
=
4
,
err
=
5
,
critical
=
6
,
alert
=
7
,
emerg
=
8
,
off
=
9
}
level_enum
;
static
const
char
*
level_names
[]
{
"trace"
,
"debug"
,
"info"
,
"notice"
,
"warning"
,
"error"
,
"critical"
,
"alert"
,
"emerg"
,
"off"
};
...
...
include/spdlog/details/async_logger_impl.h
View file @
b1867cfb
...
...
@@ -63,7 +63,7 @@ inline void spdlog::async_logger::_set_pattern(const std::string& pattern)
inline
void
spdlog
::
async_logger
::
_stop
()
{
set_level
(
level
::
OFF
);
set_level
(
level
::
off
);
}
inline
void
spdlog
::
async_logger
::
_log_msg
(
details
::
log_msg
&
msg
)
...
...
include/spdlog/details/log_msg.h
View file @
b1867cfb
...
...
@@ -80,7 +80,7 @@ struct log_msg
void
clear
()
{
level
=
level
::
OFF
;
level
=
level
::
off
;
raw
.
clear
();
formatted
.
clear
();
}
...
...
include/spdlog/details/logger_impl.h
View file @
b1867cfb
...
...
@@ -40,7 +40,7 @@ inline spdlog::logger::logger(const std::string& logger_name, const It& begin, c
{
// no support under vs2013 for member initialization for std::atomic
_level
=
level
::
INFO
;
_level
=
level
::
info
;
}
// ctor with sinks as init list
...
...
@@ -92,55 +92,55 @@ inline spdlog::details::line_logger spdlog::logger::_log_if_enabled(level::level
template
<
typename
...
Args
>
inline
spdlog
::
details
::
line_logger
spdlog
::
logger
::
trace
(
const
char
*
fmt
,
const
Args
&
...
args
)
{
return
_log_if_enabled
(
level
::
TRACE
,
fmt
,
args
...);
return
_log_if_enabled
(
level
::
trace
,
fmt
,
args
...);
}
template
<
typename
...
Args
>
inline
spdlog
::
details
::
line_logger
spdlog
::
logger
::
debug
(
const
char
*
fmt
,
const
Args
&
...
args
)
{
return
_log_if_enabled
(
level
::
DEBUG
,
fmt
,
args
...);
return
_log_if_enabled
(
level
::
debug
,
fmt
,
args
...);
}
template
<
typename
...
Args
>
inline
spdlog
::
details
::
line_logger
spdlog
::
logger
::
info
(
const
char
*
fmt
,
const
Args
&
...
args
)
{
return
_log_if_enabled
(
level
::
INFO
,
fmt
,
args
...);
return
_log_if_enabled
(
level
::
info
,
fmt
,
args
...);
}
template
<
typename
...
Args
>
inline
spdlog
::
details
::
line_logger
spdlog
::
logger
::
notice
(
const
char
*
fmt
,
const
Args
&
...
args
)
{
return
_log_if_enabled
(
level
::
NOTICE
,
fmt
,
args
...);
return
_log_if_enabled
(
level
::
notice
,
fmt
,
args
...);
}
template
<
typename
...
Args
>
inline
spdlog
::
details
::
line_logger
spdlog
::
logger
::
warn
(
const
char
*
fmt
,
const
Args
&
...
args
)
{
return
_log_if_enabled
(
level
::
WARN
,
fmt
,
args
...);
return
_log_if_enabled
(
level
::
warn
,
fmt
,
args
...);
}
template
<
typename
...
Args
>
inline
spdlog
::
details
::
line_logger
spdlog
::
logger
::
error
(
const
char
*
fmt
,
const
Args
&
...
args
)
{
return
_log_if_enabled
(
level
::
ERR
,
fmt
,
args
...);
return
_log_if_enabled
(
level
::
err
,
fmt
,
args
...);
}
template
<
typename
...
Args
>
inline
spdlog
::
details
::
line_logger
spdlog
::
logger
::
critical
(
const
char
*
fmt
,
const
Args
&
...
args
)
{
return
_log_if_enabled
(
level
::
CRITICAL
,
fmt
,
args
...);
return
_log_if_enabled
(
level
::
critical
,
fmt
,
args
...);
}
template
<
typename
...
Args
>
inline
spdlog
::
details
::
line_logger
spdlog
::
logger
::
alert
(
const
char
*
fmt
,
const
Args
&
...
args
)
{
return
_log_if_enabled
(
level
::
ALERT
,
fmt
,
args
...);
return
_log_if_enabled
(
level
::
alert
,
fmt
,
args
...);
}
template
<
typename
...
Args
>
inline
spdlog
::
details
::
line_logger
spdlog
::
logger
::
emerg
(
const
char
*
fmt
,
const
Args
&
...
args
)
{
return
_log_if_enabled
(
level
::
EMERG
,
fmt
,
args
...);
return
_log_if_enabled
(
level
::
emerg
,
fmt
,
args
...);
}
...
...
@@ -152,48 +152,48 @@ inline spdlog::details::line_logger spdlog::logger::emerg(const char* fmt, const
inline
spdlog
::
details
::
line_logger
spdlog
::
logger
::
trace
()
{
return
_log_if_enabled
(
level
::
TRACE
);
return
_log_if_enabled
(
level
::
trace
);
}
inline
spdlog
::
details
::
line_logger
spdlog
::
logger
::
debug
()
{
return
_log_if_enabled
(
level
::
DEBUG
);
return
_log_if_enabled
(
level
::
debug
);
}
inline
spdlog
::
details
::
line_logger
spdlog
::
logger
::
info
()
{
return
_log_if_enabled
(
level
::
INFO
);
return
_log_if_enabled
(
level
::
info
);
}
inline
spdlog
::
details
::
line_logger
spdlog
::
logger
::
notice
()
{
return
_log_if_enabled
(
level
::
NOTICE
);
return
_log_if_enabled
(
level
::
notice
);
}
inline
spdlog
::
details
::
line_logger
spdlog
::
logger
::
warn
()
{
return
_log_if_enabled
(
level
::
WARN
);
return
_log_if_enabled
(
level
::
warn
);
}
inline
spdlog
::
details
::
line_logger
spdlog
::
logger
::
error
()
{
return
_log_if_enabled
(
level
::
ERR
);
return
_log_if_enabled
(
level
::
err
);
}
inline
spdlog
::
details
::
line_logger
spdlog
::
logger
::
critical
()
{
return
_log_if_enabled
(
level
::
CRITICAL
);
return
_log_if_enabled
(
level
::
critical
);
}
inline
spdlog
::
details
::
line_logger
spdlog
::
logger
::
alert
()
{
return
_log_if_enabled
(
level
::
ALERT
);
return
_log_if_enabled
(
level
::
alert
);
}
inline
spdlog
::
details
::
line_logger
spdlog
::
logger
::
emerg
()
{
return
_log_if_enabled
(
level
::
EMERG
);
return
_log_if_enabled
(
level
::
emerg
);
}
...
...
@@ -255,7 +255,7 @@ inline void spdlog::logger::_set_formatter(formatter_ptr msg_formatter)
inline
void
spdlog
::
logger
::
_stop
()
{
set_level
(
level
::
OFF
);
set_level
(
level
::
off
);
}
...
...
include/spdlog/details/registry.h
View file @
b1867cfb
...
...
@@ -130,7 +130,7 @@ public:
void
stop_all
()
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
_mutex
);
_level
=
level
::
OFF
;
_level
=
level
::
off
;
for
(
auto
&
l
:
_loggers
)
l
.
second
->
stop
();
}
...
...
@@ -149,7 +149,7 @@ private:
std
::
mutex
_mutex
;
std
::
unordered_map
<
std
::
string
,
std
::
shared_ptr
<
logger
>>
_loggers
;
formatter_ptr
_formatter
;
level
::
level_enum
_level
=
level
::
INFO
;
level
::
level_enum
_level
=
level
::
info
;
bool
_async_mode
=
false
;
size_t
_async_q_size
=
0
;
};
...
...
include/spdlog/sinks/syslog_sink.h
View file @
b1867cfb
...
...
@@ -50,16 +50,16 @@ public:
syslog_sink
(
const
std
::
string
&
ident
=
""
,
int
syslog_option
=
0
,
int
syslog_facility
=
LOG_USER
)
:
_ident
(
ident
)
{
_priorities
[
static_cast
<
int
>
(
level
::
TRACE
)]
=
LOG_DEBUG
;
_priorities
[
static_cast
<
int
>
(
level
::
DEBUG
)]
=
LOG_DEBUG
;
_priorities
[
static_cast
<
int
>
(
level
::
INFO
)]
=
LOG_INFO
;
_priorities
[
static_cast
<
int
>
(
level
::
NOTICE
)]
=
LOG_NOTICE
;
_priorities
[
static_cast
<
int
>
(
level
::
WARN
)]
=
LOG_WARNING
;
_priorities
[
static_cast
<
int
>
(
level
::
ERR
)]
=
LOG_ERR
;
_priorities
[
static_cast
<
int
>
(
level
::
CRITICAL
)]
=
LOG_CRIT
;
_priorities
[
static_cast
<
int
>
(
level
::
ALERT
)]
=
LOG_ALERT
;
_priorities
[
static_cast
<
int
>
(
level
::
EMERG
)]
=
LOG_EMERG
;
_priorities
[
static_cast
<
int
>
(
level
::
OFF
)]
=
LOG_INFO
;
_priorities
[
static_cast
<
int
>
(
level
::
trace
)]
=
LOG_DEBUG
;
_priorities
[
static_cast
<
int
>
(
level
::
debug
)]
=
LOG_DEBUG
;
_priorities
[
static_cast
<
int
>
(
level
::
info
)]
=
LOG_INFO
;
_priorities
[
static_cast
<
int
>
(
level
::
notice
)]
=
LOG_NOTICE
;
_priorities
[
static_cast
<
int
>
(
level
::
warn
)]
=
LOG_WARNING
;
_priorities
[
static_cast
<
int
>
(
level
::
err
)]
=
LOG_ERR
;
_priorities
[
static_cast
<
int
>
(
level
::
critical
)]
=
LOG_CRIT
;
_priorities
[
static_cast
<
int
>
(
level
::
alert
)]
=
LOG_ALERT
;
_priorities
[
static_cast
<
int
>
(
level
::
emerg
)]
=
LOG_EMERG
;
_priorities
[
static_cast
<
int
>
(
level
::
off
)]
=
LOG_INFO
;
//set ident to be program name if empty
::
openlog
(
_ident
.
empty
()
?
nullptr
:
_ident
.
c_str
(),
syslog_option
,
syslog_facility
);
...
...
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