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
348390f9
Commit
348390f9
authored
Dec 18, 2014
by
gabi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added debug macros
parent
3e516699
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
107 additions
and
68 deletions
+107
-68
README.md
README.md
+2
-1
example.cpp
example/example.cpp
+2
-1
common.h
include/spdlog/common.h
+3
-5
logger_impl.h
include/spdlog/details/logger_impl.h
+44
-38
logger.h
include/spdlog/logger.h
+37
-16
spdlog.h
include/spdlog/spdlog.h
+19
-7
No files found.
README.md
View file @
348390f9
...
...
@@ -81,7 +81,8 @@ int main(int, char* [])
spd
::
get
(
"console"
)
->
info
(
"loggers can be retrieved from a global registry using the spdlog::get(logger_name) function"
);
SPDLOG_TRACE
(
file_logger
,
"This is a trace message (only #ifdef _DEBUG)"
,
123
);
SPDLOG_TRACE
(
console
,
"Trace message - enabled only #ifdef SPDLOG_TRACE_ON..{} ,{}"
,
1
,
3.23
);
SPDLOG_DEBUG
(
console
,
"Debug message - enabled only #ifdef SPDLOG_DEBUG_ON.. {} ,{}"
,
1
,
3.23
);
//
// Asynchronous logging is very fast..
...
...
example/example.cpp
View file @
348390f9
...
...
@@ -69,7 +69,8 @@ int main(int, char* [])
spd
::
get
(
"console"
)
->
info
(
"loggers can be retrieved from a global registry using the spdlog::get(logger_name) function"
);
SPDLOG_TRACE
(
file_logger
,
"This is a trace message (only #ifdef _DEBUG)"
,
123
);
SPDLOG_TRACE
(
console
,
"Trace message - enabled only #ifdef SPDLOG_TRACE_ON..{} ,{}"
,
1
,
3.23
);
SPDLOG_DEBUG
(
console
,
"Debug message - enabled only #ifdef SPDLOG_DEBUG_ON.. {} ,{}"
,
1
,
3.23
);
//
// Asynchronous logging is easy..
...
...
include/spdlog/common.h
View file @
348390f9
...
...
@@ -55,13 +55,11 @@ typedef enum
CRITICAL
=
6
,
ALERT
=
7
,
EMERG
=
8
,
ALWAYS
=
9
,
OFF
=
10
OFF
=
9
}
level_enum
;
static
const
char
*
level_names
[]
{
"trace"
,
"debug"
,
"info"
,
"notice"
,
"warning"
,
"error"
,
"critical"
,
"alert"
,
"emerg"
,
""
,
""
};
static
const
char
*
level_names
[]
{
"trace"
,
"debug"
,
"info"
,
"notice"
,
"warning"
,
"error"
,
"critical"
,
"alert"
,
"emerg"
,
"off"
};
inline
const
char
*
to_str
(
spdlog
::
level
::
level_enum
l
)
{
return
level_names
[
l
];
...
...
include/spdlog/details/logger_impl.h
View file @
348390f9
...
...
@@ -30,7 +30,8 @@
#include "./line_logger.h"
/* public functions */
// create logger with given name, sinks and the default pattern formatter
// all other ctors will call this one
template
<
class
It
>
inline
spdlog
::
logger
::
logger
(
const
std
::
string
&
logger_name
,
const
It
&
begin
,
const
It
&
end
)
:
_name
(
logger_name
),
...
...
@@ -42,16 +43,18 @@ inline spdlog::logger::logger(const std::string& logger_name, const It& begin, c
_level
=
level
::
INFO
;
}
// ctor with sinks as init list
inline
spdlog
::
logger
::
logger
(
const
std
::
string
&
logger_name
,
sinks_init_list
sinks_list
)
:
logger
(
logger_name
,
sinks_list
.
begin
(),
sinks_list
.
end
())
{}
// ctor with single sink
inline
spdlog
::
logger
::
logger
(
const
std
::
string
&
logger_name
,
spdlog
::
sink_ptr
single_sink
)
:
logger
(
logger_name
,
{
single_sink
})
{}
inline
spdlog
::
logger
::
logger
(
const
std
::
string
&
logger_name
,
spdlog
::
sink_ptr
single_sink
)
:
logger
(
logger_name
,
{
single_sink
})
{}
inline
spdlog
::
logger
::~
logger
()
=
default
;
inline
spdlog
::
logger
::~
logger
()
{}
inline
void
spdlog
::
logger
::
set_formatter
(
spdlog
::
formatter_ptr
msg_formatter
)
{
...
...
@@ -64,10 +67,12 @@ inline void spdlog::logger::set_pattern(const std::string& pattern)
}
//
//
cppformat API of the form logger.info("hello {} {}", "world", 1);
//
log only if given level>=logger's log level
//
template
<
typename
...
Args
>
inline
spdlog
::
details
::
line_logger
spdlog
::
logger
::
_log
(
level
::
level_enum
lvl
,
const
char
*
fmt
,
const
Args
&
...
args
)
inline
spdlog
::
details
::
line_logger
spdlog
::
logger
::
_log
_if_enabled
(
level
::
level_enum
lvl
,
const
char
*
fmt
,
const
Args
&
...
args
)
{
bool
msg_enabled
=
should_log
(
lvl
);
details
::
line_logger
l
(
this
,
lvl
,
msg_enabled
);
...
...
@@ -75,130 +80,131 @@ inline spdlog::details::line_logger spdlog::logger::_log(level::level_enum lvl,
return
l
;
}
template
<
typename
...
Args
>
inline
spdlog
::
details
::
line_logger
spdlog
::
logger
::
log
(
const
char
*
fmt
,
const
Args
&
...
args
)
inline
spdlog
::
details
::
line_logger
spdlog
::
logger
::
_log_if_enabled
(
level
::
level_enum
lvl
)
{
return
_log
(
level
::
ALWAYS
,
fmt
,
args
...
);
return
details
::
line_logger
(
this
,
lvl
,
should_log
(
lvl
)
);
}
//
// following functions will log only if at the right level
//
template
<
typename
...
Args
>
inline
spdlog
::
details
::
line_logger
spdlog
::
logger
::
trace
(
const
char
*
fmt
,
const
Args
&
...
args
)
{
return
_log
(
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
(
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
(
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
(
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
(
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
(
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
(
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
(
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
(
level
::
EMERG
,
fmt
,
args
...);
return
_log
_if_enabled
(
level
::
EMERG
,
fmt
,
args
...);
}
//
//
//API to
support logger.info() << ".." calls
// support logger.info() << ".." calls
//
inline
spdlog
::
details
::
line_logger
spdlog
::
logger
::
_log
(
level
::
level_enum
lvl
)
{
bool
msg_enabled
=
should_log
(
lvl
);
details
::
line_logger
l
(
this
,
lvl
,
msg_enabled
);
return
l
;
}
inline
spdlog
::
details
::
line_logger
spdlog
::
logger
::
log
()
{
return
_log
(
level
::
ALWAYS
);
}
inline
spdlog
::
details
::
line_logger
spdlog
::
logger
::
trace
()
{
return
_log
(
level
::
TRACE
);
return
_log
_if_enabled
(
level
::
TRACE
);
}
inline
spdlog
::
details
::
line_logger
spdlog
::
logger
::
debug
()
{
return
_log
(
level
::
DEBUG
);
return
_log
_if_enabled
(
level
::
DEBUG
);
}
inline
spdlog
::
details
::
line_logger
spdlog
::
logger
::
info
()
{
return
_log
(
level
::
INFO
);
return
_log
_if_enabled
(
level
::
INFO
);
}
inline
spdlog
::
details
::
line_logger
spdlog
::
logger
::
notice
()
{
return
_log
(
level
::
NOTICE
);
return
_log
_if_enabled
(
level
::
NOTICE
);
}
inline
spdlog
::
details
::
line_logger
spdlog
::
logger
::
warn
()
{
return
_log
(
level
::
WARN
);
return
_log
_if_enabled
(
level
::
WARN
);
}
inline
spdlog
::
details
::
line_logger
spdlog
::
logger
::
error
()
{
return
_log
(
level
::
ERR
);
return
_log
_if_enabled
(
level
::
ERR
);
}
inline
spdlog
::
details
::
line_logger
spdlog
::
logger
::
critical
()
{
return
_log
(
level
::
CRITICAL
);
return
_log
_if_enabled
(
level
::
CRITICAL
);
}
inline
spdlog
::
details
::
line_logger
spdlog
::
logger
::
alert
()
{
return
_log
(
level
::
ALERT
);
return
_log
_if_enabled
(
level
::
ALERT
);
}
inline
spdlog
::
details
::
line_logger
spdlog
::
logger
::
emerg
()
{
return
_log
(
level
::
EMERG
);
return
_log
_if_enabled
(
level
::
EMERG
);
}
// always log, no matter what is the actual logger's log level
template
<
typename
...
Args
>
inline
spdlog
::
details
::
line_logger
spdlog
::
logger
::
force_log
(
level
::
level_enum
lvl
,
const
char
*
fmt
,
const
Args
&
...
args
)
{
details
::
line_logger
l
(
this
,
lvl
,
true
);
l
.
write
(
fmt
,
args
...);
return
l
;
}
//
// name and level
...
...
include/spdlog/logger.h
View file @
348390f9
...
...
@@ -65,20 +65,35 @@ public:
//Stop logging
void
stop
();
template
<
typename
...
Args
>
details
::
line_logger
log
(
const
char
*
fmt
,
const
Args
&
...
args
);
template
<
typename
...
Args
>
details
::
line_logger
trace
(
const
char
*
fmt
,
const
Args
&
...
args
);
template
<
typename
...
Args
>
details
::
line_logger
debug
(
const
char
*
fmt
,
const
Args
&
...
args
);
template
<
typename
...
Args
>
details
::
line_logger
info
(
const
char
*
fmt
,
const
Args
&
...
args
);
template
<
typename
...
Args
>
details
::
line_logger
notice
(
const
char
*
fmt
,
const
Args
&
...
args
);
template
<
typename
...
Args
>
details
::
line_logger
warn
(
const
char
*
fmt
,
const
Args
&
...
args
);
template
<
typename
...
Args
>
details
::
line_logger
error
(
const
char
*
fmt
,
const
Args
&
...
args
);
template
<
typename
...
Args
>
details
::
line_logger
critical
(
const
char
*
fmt
,
const
Args
&
...
args
);
template
<
typename
...
Args
>
details
::
line_logger
alert
(
const
char
*
fmt
,
const
Args
&
...
args
);
template
<
typename
...
Args
>
details
::
line_logger
emerg
(
const
char
*
fmt
,
const
Args
&
...
args
);
//API to support logger.info() << ".." calls
details
::
line_logger
log
();
template
<
typename
...
Args
>
details
::
line_logger
trace
(
const
char
*
fmt
,
const
Args
&
...
args
);
template
<
typename
...
Args
>
details
::
line_logger
debug
(
const
char
*
fmt
,
const
Args
&
...
args
);
template
<
typename
...
Args
>
details
::
line_logger
info
(
const
char
*
fmt
,
const
Args
&
...
args
);
template
<
typename
...
Args
>
details
::
line_logger
notice
(
const
char
*
fmt
,
const
Args
&
...
args
);
template
<
typename
...
Args
>
details
::
line_logger
warn
(
const
char
*
fmt
,
const
Args
&
...
args
);
template
<
typename
...
Args
>
details
::
line_logger
error
(
const
char
*
fmt
,
const
Args
&
...
args
);
template
<
typename
...
Args
>
details
::
line_logger
critical
(
const
char
*
fmt
,
const
Args
&
...
args
);
template
<
typename
...
Args
>
details
::
line_logger
alert
(
const
char
*
fmt
,
const
Args
&
...
args
);
template
<
typename
...
Args
>
details
::
line_logger
emerg
(
const
char
*
fmt
,
const
Args
&
...
args
);
//API to support logger.info() << ".." call style
details
::
line_logger
trace
();
details
::
line_logger
debug
();
details
::
line_logger
info
();
...
...
@@ -90,6 +105,11 @@ public:
details
::
line_logger
emerg
();
// Create log message with the given level, no matter what is the actual logger's level
template
<
typename
...
Args
>
details
::
line_logger
force_log
(
level
::
level_enum
lvl
,
const
char
*
fmt
,
const
Args
&
...
args
);
// Set the format of the log messages from this logger
void
set_pattern
(
const
std
::
string
&
);
void
set_formatter
(
formatter_ptr
);
...
...
@@ -99,8 +119,9 @@ protected:
virtual
void
_set_pattern
(
const
std
::
string
&
);
virtual
void
_set_formatter
(
formatter_ptr
);
virtual
void
_stop
();
details
::
line_logger
_log
(
level
::
level_enum
lvl
);
template
<
typename
...
Args
>
details
::
line_logger
_log
(
level
::
level_enum
lvl
,
const
char
*
fmt
,
const
Args
&
...
args
);
details
::
line_logger
_log_if_enabled
(
level
::
level_enum
lvl
);
template
<
typename
...
Args
>
details
::
line_logger
_log_if_enabled
(
level
::
level_enum
lvl
,
const
char
*
fmt
,
const
Args
&
...
args
);
friend
details
::
line_logger
;
...
...
include/spdlog/spdlog.h
View file @
348390f9
...
...
@@ -114,23 +114,35 @@ template <typename Sink, typename... Args>
std
::
shared_ptr
<
spdlog
::
logger
>
create
(
const
std
::
string
&
logger_name
,
const
Args
&
...);
// Stop logging by setting all the loggers to log level OFF
void
stop
();
//
// Trace macro enabled only at debug compile
// Example: SPDLOG_TRACE(my_logger, "Some trace message");
// Trace & debug macros to be switched on/off at compile time for zero cost debug statements.
// Note: using these mactors overrides the runtime log threshold of the logger.
//
// Example:
//
// Enable debug macro, must be defined before including spdlog.h
// #define SPDLOG_DEBUG_ON
// include "spdlog/spdlog.h"
// SPDLOG_DEBUG(my_logger, "Some debug message {} {}", 1, 3.2);
//
#ifdef _DEBUG
#define SPDLOG_TRACE(logger, ...) logger->log(__FILE__, " #", __LINE__,": " __VA_ARGS__)
#ifdef SPDLOG_TRACE_ON
#define SPDLOG_TRACE(logger, ...) logger->force_log(level::TRACE, __FILE__, " #", __LINE__,": " __VA_ARGS__)
#else
#define SPDLOG_TRACE(logger, ...)
{}
#define SPDLOG_TRACE(logger, ...)
#endif
#ifdef SPDLOG_DEBUG_ON
#define SPDLOG_DEBUG(logger, ...) logger->force_log(level::DEBUG, __VA_ARGS__)
#else
#define SPDLOG_DEBUG(logger, ...)
#endif
}
#include "details/spdlog_impl.h"
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