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
1df30a07
Commit
1df30a07
authored
Sep 02, 2016
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support flush_on(..) in async loggers too
parent
3a12f3c5
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
4 deletions
+17
-4
example.cpp
example/example.cpp
+4
-0
async_logger_impl.h
include/spdlog/details/async_logger_impl.h
+2
-1
logger_impl.h
include/spdlog/details/logger_impl.h
+7
-3
logger.h
include/spdlog/logger.h
+4
-0
No files found.
example/example.cpp
View file @
1df30a07
...
...
@@ -102,6 +102,10 @@ void async_example()
size_t
q_size
=
4096
;
//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"
);
// auto flush if the log severity is error or higher
async_file
->
flush_on
(
spd
::
level
::
err
);
for
(
int
i
=
0
;
i
<
100
;
++
i
)
async_file
->
info
(
"Async message #{}"
,
i
);
}
...
...
include/spdlog/details/async_logger_impl.h
View file @
1df30a07
...
...
@@ -54,7 +54,6 @@ inline spdlog::async_logger::async_logger(const std::string& logger_name,
inline
void
spdlog
::
async_logger
::
flush
()
{
_async_log_helper
->
flush
();
}
...
...
@@ -76,6 +75,8 @@ inline void spdlog::async_logger::_sink_it(details::log_msg& msg)
try
{
_async_log_helper
->
log
(
msg
);
if
(
_should_flush_on
(
msg
))
flush
();
}
catch
(
const
std
::
exception
&
ex
)
{
...
...
include/spdlog/details/logger_impl.h
View file @
1df30a07
...
...
@@ -244,13 +244,11 @@ inline bool spdlog::logger::should_log(spdlog::level::level_enum msg_level) cons
//
inline
void
spdlog
::
logger
::
_sink_it
(
details
::
log_msg
&
msg
)
{
_formatter
->
format
(
msg
);
for
(
auto
&
sink
:
_sinks
)
sink
->
log
(
msg
);
const
auto
flush_level
=
_flush_level
.
load
(
std
::
memory_order_relaxed
);
if
(
msg
.
level
>=
flush_level
)
if
(
_should_flush_on
(
msg
))
flush
();
}
...
...
@@ -282,3 +280,9 @@ inline void spdlog::logger::_default_err_handler(const std::string &msg)
sinks
::
stderr_sink_mt
::
instance
()
->
log
(
err_msg
);
_last_err_time
=
now
;
}
inline
bool
spdlog
::
logger
::
_should_flush_on
(
const
details
::
log_msg
&
msg
)
{
const
auto
flush_level
=
_flush_level
.
load
(
std
::
memory_order_relaxed
);
return
(
msg
.
level
>=
flush_level
)
&&
(
msg
.
level
!=
level
::
off
);
}
include/spdlog/logger.h
View file @
1df30a07
...
...
@@ -65,6 +65,7 @@ public:
// automatically call flush() if message level >= log_level
void
flush_on
(
level
::
level_enum
log_level
);
virtual
void
flush
();
protected
:
...
...
@@ -75,6 +76,9 @@ protected:
// default error handler: print the error to stderr with the max rate of 1 message/minute
virtual
void
_default_err_handler
(
const
std
::
string
&
msg
);
// return true if the given message level should trigger a flush
bool
_should_flush_on
(
const
details
::
log_msg
&
);
const
std
::
string
_name
;
std
::
vector
<
sink_ptr
>
_sinks
;
formatter_ptr
_formatter
;
...
...
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