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
91d8869f
Commit
91d8869f
authored
Aug 25, 2018
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added "clone()" support to loggers
parent
1f8b2cbb
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
2 deletions
+51
-2
example/example.cpp
example/example.cpp
+12
-1
include/spdlog/async_logger.h
include/spdlog/async_logger.h
+2
-0
include/spdlog/details/async_logger_impl.h
include/spdlog/details/async_logger_impl.h
+14
-0
include/spdlog/details/logger_impl.h
include/spdlog/details/logger_impl.h
+15
-0
include/spdlog/logger.h
include/spdlog/logger.h
+8
-1
No files found.
example/example.cpp
View file @
91d8869f
...
@@ -18,6 +18,7 @@ void multi_sink_example();
...
@@ -18,6 +18,7 @@ void multi_sink_example();
void
user_defined_example
();
void
user_defined_example
();
void
err_handler_example
();
void
err_handler_example
();
void
syslog_example
();
void
syslog_example
();
void
clone_example
();
#include "spdlog/spdlog.h"
#include "spdlog/spdlog.h"
...
@@ -34,6 +35,8 @@ int main(int, char *[])
...
@@ -34,6 +35,8 @@ int main(int, char *[])
rotating_example
();
rotating_example
();
daily_example
();
daily_example
();
clone_example
();
// async logging using a backing thread pool
// async logging using a backing thread pool
async_example
();
async_example
();
...
@@ -122,6 +125,14 @@ void daily_example()
...
@@ -122,6 +125,14 @@ void daily_example()
auto
daily_logger
=
spdlog
::
daily_logger_mt
(
"daily_logger"
,
"logs/daily.txt"
,
2
,
30
);
auto
daily_logger
=
spdlog
::
daily_logger_mt
(
"daily_logger"
,
"logs/daily.txt"
,
2
,
30
);
}
}
// clone a logger and give it new name.
// Useful for creating component/subsystem loggers from some "root" logger
void
clone_example
()
{
auto
network_logger
=
spdlog
::
get
(
"console"
)
->
clone
(
"network"
);
network_logger
->
info
(
"Logging network stuff.."
);
}
#include "spdlog/async.h"
#include "spdlog/async.h"
void
async_example
()
void
async_example
()
{
{
...
...
include/spdlog/async_logger.h
View file @
91d8869f
...
@@ -55,6 +55,8 @@ public:
...
@@ -55,6 +55,8 @@ public:
async_logger
(
std
::
string
logger_name
,
sink_ptr
single_sink
,
std
::
weak_ptr
<
details
::
thread_pool
>
tp
,
async_logger
(
std
::
string
logger_name
,
sink_ptr
single_sink
,
std
::
weak_ptr
<
details
::
thread_pool
>
tp
,
async_overflow_policy
overflow_policy
=
async_overflow_policy
::
block
);
async_overflow_policy
overflow_policy
=
async_overflow_policy
::
block
);
std
::
shared_ptr
<
logger
>
clone
(
std
::
string
new_name
)
override
;
protected:
protected:
void
sink_it_
(
details
::
log_msg
&
msg
)
override
;
void
sink_it_
(
details
::
log_msg
&
msg
)
override
;
void
flush_
()
override
;
void
flush_
()
override
;
...
...
include/spdlog/details/async_logger_impl.h
View file @
91d8869f
...
@@ -98,3 +98,17 @@ inline void spdlog::async_logger::backend_flush_()
...
@@ -98,3 +98,17 @@ inline void spdlog::async_logger::backend_flush_()
}
}
SPDLOG_CATCH_AND_HANDLE
SPDLOG_CATCH_AND_HANDLE
}
}
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
async_logger
::
clone
(
std
::
string
new_name
)
{
auto
cloned
=
std
::
make_shared
<
spdlog
::
async_logger
>
(
std
::
move
(
new_name
),
sinks_
.
begin
(),
sinks_
.
end
(),
thread_pool_
,
overflow_policy_
);
cloned
->
set_level
(
this
->
level
());
cloned
->
flush_on
(
this
->
flush_level
());
cloned
->
set_error_handler
(
this
->
error_handler
());
return
std
::
move
(
cloned
);
}
\ No newline at end of file
include/spdlog/details/logger_impl.h
View file @
91d8869f
...
@@ -271,6 +271,12 @@ inline void spdlog::logger::flush_on(level::level_enum log_level)
...
@@ -271,6 +271,12 @@ inline void spdlog::logger::flush_on(level::level_enum log_level)
flush_level_
.
store
(
log_level
);
flush_level_
.
store
(
log_level
);
}
}
inline
spdlog
::
level
::
level_enum
spdlog
::
logger
::
flush_level
()
const
{
return
static_cast
<
spdlog
::
level
::
level_enum
>
(
flush_level_
.
load
(
std
::
memory_order_relaxed
));
}
inline
bool
spdlog
::
logger
::
should_flush_
(
const
details
::
log_msg
&
msg
)
inline
bool
spdlog
::
logger
::
should_flush_
(
const
details
::
log_msg
&
msg
)
{
{
auto
flush_level
=
flush_level_
.
load
(
std
::
memory_order_relaxed
);
auto
flush_level
=
flush_level_
.
load
(
std
::
memory_order_relaxed
);
...
@@ -346,3 +352,12 @@ inline std::vector<spdlog::sink_ptr> &spdlog::logger::sinks()
...
@@ -346,3 +352,12 @@ inline std::vector<spdlog::sink_ptr> &spdlog::logger::sinks()
{
{
return
sinks_
;
return
sinks_
;
}
}
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
logger
::
clone
(
std
::
string
logger_name
)
{
auto
cloned
=
std
::
make_shared
<
spdlog
::
logger
>
(
std
::
move
(
logger_name
),
sinks_
.
begin
(),
sinks_
.
end
());
cloned
->
set_level
(
this
->
level
());
cloned
->
flush_on
(
this
->
flush_level
());
cloned
->
set_error_handler
(
this
->
error_handler
());
return
std
::
move
(
cloned
);
}
\ No newline at end of file
include/spdlog/logger.h
View file @
91d8869f
...
@@ -115,21 +115,28 @@ public:
...
@@ -115,21 +115,28 @@ public:
level
::
level_enum
level
()
const
;
level
::
level_enum
level
()
const
;
const
std
::
string
&
name
()
const
;
const
std
::
string
&
name
()
const
;
// set formatting for the sinks in this logger.
// set formatting for the sinks in this logger.
// each sink will get a seperate instance of the formatter object.
// each sink will get a seperate instance of the formatter object.
void
set_formatter
(
std
::
unique_ptr
<
formatter
>
formatter
);
void
set_formatter
(
std
::
unique_ptr
<
formatter
>
formatter
);
void
set_pattern
(
std
::
string
pattern
,
pattern_time_type
time_type
=
pattern_time_type
::
local
);
void
set_pattern
(
std
::
string
pattern
,
pattern_time_type
time_type
=
pattern_time_type
::
local
);
// flush functions
void
flush
();
void
flush
();
void
flush_on
(
level
::
level_enum
log_level
);
void
flush_on
(
level
::
level_enum
log_level
);
level
::
level_enum
flush_level
()
const
;
// sinks
const
std
::
vector
<
sink_ptr
>
&
sinks
()
const
;
const
std
::
vector
<
sink_ptr
>
&
sinks
()
const
;
std
::
vector
<
sink_ptr
>
&
sinks
();
std
::
vector
<
sink_ptr
>
&
sinks
();
// error handler
void
set_error_handler
(
log_err_handler
err_handler
);
void
set_error_handler
(
log_err_handler
err_handler
);
log_err_handler
error_handler
();
log_err_handler
error_handler
();
// create new logger with same sinks and configuration.
virtual
std
::
shared_ptr
<
logger
>
clone
(
std
::
string
logger_name
);
protected:
protected:
virtual
void
sink_it_
(
details
::
log_msg
&
msg
);
virtual
void
sink_it_
(
details
::
log_msg
&
msg
);
virtual
void
flush_
();
virtual
void
flush_
();
...
...
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