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
a7f7984c
Commit
a7f7984c
authored
Aug 25, 2019
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
backtrace support api
parent
dd33c16a
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
97 additions
and
21 deletions
+97
-21
include/spdlog/details/registry-inl.h
include/spdlog/details/registry-inl.h
+10
-0
include/spdlog/details/registry.h
include/spdlog/details/registry.h
+2
-0
include/spdlog/logger-inl.h
include/spdlog/logger-inl.h
+42
-17
include/spdlog/logger.h
include/spdlog/logger.h
+3
-1
include/spdlog/sinks/backtrace-sink.h
include/spdlog/sinks/backtrace-sink.h
+18
-3
include/spdlog/sinks/dist_sink.h
include/spdlog/sinks/dist_sink.h
+6
-0
include/spdlog/spdlog-inl.h
include/spdlog/spdlog-inl.h
+10
-0
include/spdlog/spdlog.h
include/spdlog/spdlog.h
+6
-0
No files found.
include/spdlog/details/registry-inl.h
View file @
a7f7984c
...
...
@@ -151,6 +151,16 @@ SPDLOG_INLINE void registry::enable_backtrace(size_t n_messages)
}
}
SPDLOG_INLINE
void
registry
::
disable_backtrace
()
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
logger_map_mutex_
);
for
(
auto
&
l
:
loggers_
)
{
l
.
second
->
disable_backtrace
();
}
}
SPDLOG_INLINE
void
registry
::
set_level
(
level
::
level_enum
log_level
)
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
logger_map_mutex_
);
...
...
include/spdlog/details/registry.h
View file @
a7f7984c
...
...
@@ -54,6 +54,8 @@ public:
void
enable_backtrace
(
size_t
n_messages
);
void
disable_backtrace
();
void
set_level
(
level
::
level_enum
log_level
);
void
flush_on
(
level
::
level_enum
log_level
);
...
...
include/spdlog/logger-inl.h
View file @
a7f7984c
...
...
@@ -22,13 +22,17 @@ SPDLOG_INLINE logger::logger(const logger &other)
,
level_
(
other
.
level_
.
load
(
std
::
memory_order_relaxed
))
,
flush_level_
(
other
.
flush_level_
.
load
(
std
::
memory_order_relaxed
))
,
custom_err_handler_
(
other
.
custom_err_handler_
)
,
backtrace_sink_
(
other
.
backtrace_sink_
)
{}
SPDLOG_INLINE
logger
::
logger
(
logger
&&
other
)
SPDLOG_NOEXCEPT
:
name_
(
std
::
move
(
other
.
name_
)),
sinks_
(
std
::
move
(
other
.
sinks_
)),
level_
(
other
.
level_
.
load
(
std
::
memory_order_relaxed
)),
flush_level_
(
other
.
flush_level_
.
load
(
std
::
memory_order_relaxed
)),
custom_err_handler_
(
std
::
move
(
other
.
custom_err_handler_
))
SPDLOG_INLINE
logger
::
logger
(
logger
&&
other
)
SPDLOG_NOEXCEPT
:
name_
(
std
::
move
(
other
.
name_
)),
sinks_
(
std
::
move
(
other
.
sinks_
)),
level_
(
other
.
level_
.
load
(
std
::
memory_order_relaxed
)),
flush_level_
(
other
.
flush_level_
.
load
(
std
::
memory_order_relaxed
)),
custom_err_handler_
(
std
::
move
(
other
.
custom_err_handler_
)),
backtrace_sink_
(
std
::
move
(
other
.
backtrace_sink_
))
{}
SPDLOG_INLINE
logger
&
logger
::
operator
=
(
logger
other
)
SPDLOG_NOEXCEPT
...
...
@@ -53,6 +57,7 @@ SPDLOG_INLINE void logger::swap(spdlog::logger &other) SPDLOG_NOEXCEPT
other
.
flush_level_
.
store
(
tmp
);
custom_err_handler_
.
swap
(
other
.
custom_err_handler_
);
backtrace_sink_
.
swap
(
other
.
backtrace_sink_
);
}
SPDLOG_INLINE
void
swap
(
logger
&
a
,
logger
&
b
)
...
...
@@ -83,7 +88,16 @@ SPDLOG_INLINE bool logger::should_log(level::level_enum msg_level) const
SPDLOG_INLINE
void
logger
::
set_level
(
level
::
level_enum
log_level
)
{
level_
.
store
(
log_level
);
if
(
backtrace_sink_
)
{
auto
tracer
=
static_cast
<
sinks
::
backtrace_sink_mt
*>
(
backtrace_sink_
.
get
());
tracer
->
set_filter_level
(
log_level
);
level_
.
store
(
level
::
trace
);
}
else
{
level_
.
store
(
log_level
);
}
}
SPDLOG_INLINE
level
::
level_enum
logger
::
level
()
const
...
...
@@ -120,26 +134,37 @@ SPDLOG_INLINE void logger::set_pattern(std::string pattern, pattern_time_type ti
set_formatter
(
std
::
move
(
new_formatter
));
}
// create new backtrace sink and
hand it all
sinks
// create new backtrace sink and
move to it all our child
sinks
SPDLOG_INLINE
void
logger
::
enable_backtrace
(
size_t
n_messages
)
{
if
(
!
backtrace_enabled_
)
if
(
!
backtrace_sink_
)
{
auto
new_backtrace_sink
=
new
spdlog
::
sinks
::
backtrace_sink_mt
(
level
(),
n_messages
);
new_backtrace_sink
->
set_sinks
(
std
::
move
(
sinks_
));
backtrace_sink_
.
reset
(
new_backtrace_sink
);
sinks
().
push_back
(
backtrace_sink_
);
assert
(
sinks
().
size
()
==
1
);
level_
.
store
(
level
::
trace
);
}
}
// restore orig sinks and level and delete the backtrace sink
SPDLOG_INLINE
void
logger
::
disable_backtrace
()
{
if
(
backtrace_sink_
)
{
backtrace_enabled_
=
true
;
auto
backtrace_sink
=
std
::
make_shared
<
spdlog
::
sinks
::
backtrace_sink_mt
>
(
n_messages
);
backtrace_sink
->
set_sinks
(
std
::
move
(
sinks
()));
sinks
().
push_back
(
std
::
move
(
backtrace_sink
));
this
->
set_level
(
spdlog
::
level
::
trace
);
auto
tracer
=
static_cast
<
sinks
::
backtrace_sink_mt
*>
(
backtrace_sink_
.
get
());
sinks_
=
std
::
move
(
tracer
->
sinks
());
level_
.
store
(
tracer
->
get_filter_level
());
backtrace_sink_
.
reset
();
}
}
SPDLOG_INLINE
void
logger
::
dump_backtrace
()
{
if
(
backtrace_
enabled
_
)
if
(
backtrace_
sink
_
)
{
// auto backtrace_sink = static_cast<std::shared_ptr<sinks::backtrace_sink_mt>>(sinks_[0]);
auto
*
first_sink
=
sinks_
[
0
].
get
();
auto
tracer
=
static_cast
<
sinks
::
backtrace_sink_mt
*>
(
first_sink
);
auto
tracer
=
static_cast
<
sinks
::
backtrace_sink_mt
*>
(
backtrace_sink_
.
get
());
tracer
->
dump_backtrace
();
}
}
...
...
include/spdlog/logger.h
View file @
a7f7984c
...
...
@@ -324,6 +324,7 @@ public:
void
set_pattern
(
std
::
string
pattern
,
pattern_time_type
time_type
=
pattern_time_type
::
local
);
void
enable_backtrace
(
size_t
n_messages
=
16
);
void
disable_backtrace
();
void
dump_backtrace
();
...
...
@@ -349,7 +350,8 @@ protected:
spdlog
::
level_t
level_
{
level
::
info
};
spdlog
::
level_t
flush_level_
{
level
::
off
};
err_handler
custom_err_handler_
{
nullptr
};
bool
backtrace_enabled_
{
false
};
sink_ptr
backtrace_sink_
;
//bool backtrace_enabled_{false};
virtual
void
sink_it_
(
const
details
::
log_msg
&
msg
);
virtual
void
flush_
();
...
...
include/spdlog/sinks/backtrace-sink.h
View file @
a7f7984c
...
...
@@ -4,6 +4,7 @@
#pragma once
#include "dist_sink.h"
#include "spdlog/common.h"
#include "spdlog/details/null_mutex.h"
#include "spdlog/details/log_msg_buffer.h"
#include "spdlog/details/circular_q.h"
...
...
@@ -22,10 +23,23 @@ template<typename Mutex>
class
backtrace_sink
:
public
dist_sink
<
Mutex
>
{
public:
explicit
backtrace_sink
(
size_t
n_messages
=
16
)
:
traceback_msgs_
{
n_messages
}
explicit
backtrace_sink
(
spdlog
::
level
::
level_enum
filter_level
,
size_t
n_messages
)
:
filter_level_
{
filter_level
}
,
traceback_msgs_
{
n_messages
}
{}
void
set_filter_level
(
spdlog
::
level
::
level_enum
filter_level
)
{
std
::
lock_guard
<
Mutex
>
lock
(
base_sink
<
Mutex
>::
mutex_
);
filter_level_
=
filter_level
;
}
spdlog
::
level
::
level_enum
get_filter_level
()
{
std
::
lock_guard
<
Mutex
>
lock
(
base_sink
<
Mutex
>::
mutex_
);
return
filter_level_
;
}
void
dump_backtrace
()
{
std
::
lock_guard
<
Mutex
>
lock
(
base_sink
<
Mutex
>::
mutex_
);
...
...
@@ -33,6 +47,7 @@ public:
}
protected:
spdlog
::
level
::
level_enum
filter_level_
;
details
::
circular_q
<
details
::
log_msg_buffer
>
traceback_msgs_
;
// save the messages in a circular queue
...
...
@@ -40,7 +55,7 @@ protected:
{
traceback_msgs_
.
push_back
(
details
::
log_msg_buffer
(
msg
));
if
(
msg
.
level
>
level
::
debug
)
if
(
msg
.
level
>
=
filter_level_
)
{
dist_sink
<
Mutex
>::
sink_it_
(
msg
);
}
...
...
include/spdlog/sinks/dist_sink.h
View file @
a7f7984c
...
...
@@ -45,6 +45,12 @@ public:
sinks_
=
std
::
move
(
sinks
);
}
std
::
vector
<
std
::
shared_ptr
<
sink
>>&
sinks
()
{
return
sinks_
;
}
protected:
void
sink_it_
(
const
details
::
log_msg
&
msg
)
override
{
...
...
include/spdlog/spdlog-inl.h
View file @
a7f7984c
...
...
@@ -37,6 +37,16 @@ SPDLOG_INLINE void enable_backtrace(size_t n_messages)
details
::
registry
::
instance
().
enable_backtrace
(
n_messages
);
}
SPDLOG_INLINE
void
disable_backtrace
()
{
details
::
registry
::
instance
().
disable_backtrace
();
}
SPDLOG_INLINE
void
dump_backtrace
()
{
default_logger_raw
()
->
dump_backtrace
();
}
SPDLOG_INLINE
void
set_level
(
level
::
level_enum
log_level
)
{
details
::
registry
::
instance
().
set_level
(
log_level
);
...
...
include/spdlog/spdlog.h
View file @
a7f7984c
...
...
@@ -63,6 +63,12 @@ void set_pattern(std::string pattern, pattern_time_type time_type = pattern_time
// enable global backtrace support
void
enable_backtrace
(
size_t
n_messages
);
// disable global backtrace support
void
disable_backtrace
();
// call dump backtrace on default logger
void
dump_backtrace
();
// Set global logging level
void
set_level
(
level
::
level_enum
log_level
);
...
...
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