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
11472edd
Commit
11472edd
authored
Jul 17, 2019
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Catch sink exceptions without affecting other sinks
parent
12470f62
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
80 deletions
+25
-80
include/spdlog/async_logger-inl.h
include/spdlog/async_logger-inl.h
+2
-16
include/spdlog/logger-inl.h
include/spdlog/logger-inl.h
+13
-27
include/spdlog/logger.h
include/spdlog/logger.h
+10
-37
No files found.
include/spdlog/async_logger-inl.h
View file @
11472edd
...
@@ -65,14 +65,7 @@ SPDLOG_INLINE void spdlog::async_logger::backend_log_(const details::log_msg &in
...
@@ -65,14 +65,7 @@ SPDLOG_INLINE void spdlog::async_logger::backend_log_(const details::log_msg &in
}
}
}
}
}
}
catch
(
const
std
::
exception
&
ex
)
SPDLOG_LOGGER_CATCH
()
{
err_handler_
(
ex
.
what
());
}
catch
(...)
{
err_handler_
(
"Unknown exception in logger"
);
}
if
(
should_flush_
(
incoming_log_msg
))
if
(
should_flush_
(
incoming_log_msg
))
{
{
...
@@ -89,14 +82,7 @@ SPDLOG_INLINE void spdlog::async_logger::backend_flush_()
...
@@ -89,14 +82,7 @@ SPDLOG_INLINE void spdlog::async_logger::backend_flush_()
sink
->
flush
();
sink
->
flush
();
}
}
}
}
catch
(
const
std
::
exception
&
ex
)
SPDLOG_LOGGER_CATCH
()
{
err_handler_
(
ex
.
what
());
}
catch
(...)
{
err_handler_
(
"Unknown exception in logger"
);
}
}
}
SPDLOG_INLINE
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
async_logger
::
clone
(
std
::
string
new_name
)
SPDLOG_INLINE
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
async_logger
::
clone
(
std
::
string
new_name
)
...
...
include/spdlog/logger-inl.h
View file @
11472edd
...
@@ -65,19 +65,8 @@ SPDLOG_INLINE void logger::log(source_loc loc, level::level_enum lvl, string_vie
...
@@ -65,19 +65,8 @@ SPDLOG_INLINE void logger::log(source_loc loc, level::level_enum lvl, string_vie
return
;
return
;
}
}
try
details
::
log_msg
log_msg
(
loc
,
string_view_t
(
name_
),
lvl
,
msg
);
{
sink_it_
(
log_msg
);
details
::
log_msg
log_msg
(
loc
,
string_view_t
(
name_
),
lvl
,
msg
);
sink_it_
(
log_msg
);
}
catch
(
const
std
::
exception
&
ex
)
{
err_handler_
(
ex
.
what
());
}
catch
(...)
{
err_handler_
(
"Unknown exception in logger"
);
}
}
}
SPDLOG_INLINE
void
logger
::
log
(
level
::
level_enum
lvl
,
string_view_t
msg
)
SPDLOG_INLINE
void
logger
::
log
(
level
::
level_enum
lvl
,
string_view_t
msg
)
...
@@ -137,18 +126,7 @@ SPDLOG_INLINE void logger::set_pattern(std::string pattern, pattern_time_type ti
...
@@ -137,18 +126,7 @@ SPDLOG_INLINE void logger::set_pattern(std::string pattern, pattern_time_type ti
// flush functions
// flush functions
SPDLOG_INLINE
void
logger
::
flush
()
SPDLOG_INLINE
void
logger
::
flush
()
{
{
try
flush_
();
{
flush_
();
}
catch
(
const
std
::
exception
&
ex
)
{
err_handler_
(
ex
.
what
());
}
catch
(...)
{
err_handler_
(
"Unknown exception in logger"
);
}
}
}
SPDLOG_INLINE
void
logger
::
flush_on
(
level
::
level_enum
log_level
)
SPDLOG_INLINE
void
logger
::
flush_on
(
level
::
level_enum
log_level
)
...
@@ -193,7 +171,11 @@ SPDLOG_INLINE void logger::sink_it_(details::log_msg &msg)
...
@@ -193,7 +171,11 @@ SPDLOG_INLINE void logger::sink_it_(details::log_msg &msg)
{
{
if
(
sink
->
should_log
(
msg
.
level
))
if
(
sink
->
should_log
(
msg
.
level
))
{
{
sink
->
log
(
msg
);
try
{
sink
->
log
(
msg
);
}
SPDLOG_LOGGER_CATCH
()
}
}
}
}
...
@@ -207,7 +189,11 @@ SPDLOG_INLINE void logger::flush_()
...
@@ -207,7 +189,11 @@ SPDLOG_INLINE void logger::flush_()
{
{
for
(
auto
&
sink
:
sinks_
)
for
(
auto
&
sink
:
sinks_
)
{
{
sink
->
flush
();
try
{
sink
->
flush
();
}
SPDLOG_LOGGER_CATCH
()
}
}
}
}
...
...
include/spdlog/logger.h
View file @
11472edd
...
@@ -27,6 +27,10 @@
...
@@ -27,6 +27,10 @@
#include <vector>
#include <vector>
#include <functional>
#include <functional>
#define SPDLOG_LOGGER_CATCH() \
catch (const std::exception &ex) { err_handler_(ex.what());} \
catch (...) {err_handler_("Unknown exception in logger");}
namespace
spdlog
{
namespace
spdlog
{
class
logger
class
logger
{
{
...
@@ -72,14 +76,7 @@ public:
...
@@ -72,14 +76,7 @@ public:
details
::
log_msg
log_msg
(
loc
,
name_
,
lvl
,
string_view_t
(
buf
.
data
(),
buf
.
size
()));
details
::
log_msg
log_msg
(
loc
,
name_
,
lvl
,
string_view_t
(
buf
.
data
(),
buf
.
size
()));
sink_it_
(
log_msg
);
sink_it_
(
log_msg
);
}
}
catch
(
const
std
::
exception
&
ex
)
SPDLOG_LOGGER_CATCH
()
{
err_handler_
(
ex
.
what
());
}
catch
(...)
{
err_handler_
(
"Unknown exception in logger"
);
}
}
}
template
<
typename
...
Args
>
template
<
typename
...
Args
>
...
@@ -150,19 +147,9 @@ public:
...
@@ -150,19 +147,9 @@ public:
{
{
return
;
return
;
}
}
try
{
details
::
log_msg
log_msg
(
loc
,
name_
,
lvl
,
msg
);
details
::
log_msg
log_msg
(
loc
,
name_
,
lvl
,
msg
);
sink_it_
(
log_msg
);
sink_it_
(
log_msg
);
}
catch
(
const
std
::
exception
&
ex
)
{
err_handler_
(
ex
.
what
());
}
catch
(...)
{
err_handler_
(
"Unknown exception in logger"
);
}
}
}
// T cannot be statically converted to string_view
// T cannot be statically converted to string_view
...
@@ -180,14 +167,7 @@ public:
...
@@ -180,14 +167,7 @@ public:
details
::
log_msg
log_msg
(
loc
,
name_
,
lvl
,
string_view_t
(
buf
.
data
(),
buf
.
size
()));
details
::
log_msg
log_msg
(
loc
,
name_
,
lvl
,
string_view_t
(
buf
.
data
(),
buf
.
size
()));
sink_it_
(
log_msg
);
sink_it_
(
log_msg
);
}
}
catch
(
const
std
::
exception
&
ex
)
SPDLOG_LOGGER_CATCH
()
{
err_handler_
(
ex
.
what
());
}
catch
(...)
{
err_handler_
(
"Unknown exception in logger"
);
}
}
}
template
<
typename
T
>
template
<
typename
T
>
...
@@ -250,14 +230,7 @@ public:
...
@@ -250,14 +230,7 @@ public:
details
::
log_msg
log_msg
(
source
,
name_
,
lvl
,
string_view_t
(
buf
.
data
(),
buf
.
size
()));
details
::
log_msg
log_msg
(
source
,
name_
,
lvl
,
string_view_t
(
buf
.
data
(),
buf
.
size
()));
sink_it_
(
log_msg
);
sink_it_
(
log_msg
);
}
}
catch
(
const
std
::
exception
&
ex
)
SPDLOG_LOGGER_CATCH
()
{
err_handler_
(
ex
.
what
());
}
catch
(...)
{
err_handler_
(
"Unknown exception in logger"
);
}
}
}
template
<
typename
...
Args
>
template
<
typename
...
Args
>
...
...
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