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
3c30f77d
Commit
3c30f77d
authored
Jul 17, 2019
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
limit default error handler to 1 message/second to avoid flood
parent
bcb64840
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
4 deletions
+20
-4
logger-inl.h
include/spdlog/logger-inl.h
+18
-2
logger.h
include/spdlog/logger.h
+2
-2
No files found.
include/spdlog/logger-inl.h
View file @
3c30f77d
...
...
@@ -10,6 +10,8 @@
#include "spdlog/sinks/sink.h"
#include "spdlog/details/pattern_formatter.h"
#include <cstdio>
namespace
spdlog
{
// public methods
...
...
@@ -203,18 +205,32 @@ SPDLOG_INLINE bool logger::should_flush_(const details::log_msg &msg)
return
(
msg
.
level
>=
flush_level
)
&&
(
msg
.
level
!=
level
::
off
);
}
SPDLOG_INLINE
void
logger
::
err_handler_
(
const
std
::
string
&
msg
)
{
if
(
custom_err_handler_
)
{
custom_err_handler_
(
msg
);
}
else
{
auto
tm_time
=
details
::
os
::
localtime
();
using
std
::
chrono
::
system_clock
;
static
std
::
mutex
mutex
;
static
std
::
chrono
::
system_clock
::
time_point
last_report_time
;
static
size_t
err_counter
=
0
;
std
::
lock_guard
<
std
::
mutex
>
lk
{
mutex
};
auto
now
=
system_clock
::
now
();
err_counter
++
;
if
(
now
-
last_report_time
<
std
::
chrono
::
seconds
(
1
))
{
return
;
}
last_report_time
=
now
;
auto
tm_time
=
details
::
os
::
localtime
(
system_clock
::
to_time_t
(
now
));
char
date_buf
[
64
];
std
::
strftime
(
date_buf
,
sizeof
(
date_buf
),
"%Y-%m-%d %H:%M:%S"
,
&
tm_time
);
f
mt
::
print
(
stderr
,
"[*** LOG ERROR ***] [{}] [{}] {}
\n
"
,
date_buf
,
name
(),
msg
);
f
printf
(
stderr
,
"[*** LOG ERROR #%04zu ***] [%s] [%s] {%s}
\n
"
,
err_counter
,
date_buf
,
name
().
c_str
(),
msg
.
c_str
()
);
}
}
}
// namespace spdlog
include/spdlog/logger.h
View file @
3c30f77d
...
...
@@ -317,8 +317,8 @@ protected:
virtual
void
flush_
();
bool
should_flush_
(
const
details
::
log_msg
&
msg
);
//
default error handler
.
//
print the error to stderr with the max rate of 1 message/minute
.
//
handle errors during logging
.
//
default handler prints the error to stderr at max rate of 1 message/sec
.
void
err_handler_
(
const
std
::
string
&
msg
);
};
...
...
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