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
dd33c16a
Commit
dd33c16a
authored
Aug 23, 2019
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace backtrace trigger with dump_backtrace()
parent
8d8aacf5
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
38 additions
and
33 deletions
+38
-33
include/spdlog/details/registry-inl.h
include/spdlog/details/registry-inl.h
+4
-5
include/spdlog/details/registry.h
include/spdlog/details/registry.h
+1
-2
include/spdlog/logger-inl.h
include/spdlog/logger-inl.h
+13
-4
include/spdlog/logger.h
include/spdlog/logger.h
+4
-2
include/spdlog/sinks/backtrace-sink.h
include/spdlog/sinks/backtrace-sink.h
+13
-17
include/spdlog/spdlog-inl.h
include/spdlog/spdlog-inl.h
+2
-2
include/spdlog/spdlog.h
include/spdlog/spdlog.h
+1
-1
No files found.
include/spdlog/details/registry-inl.h
View file @
dd33c16a
...
@@ -67,9 +67,9 @@ SPDLOG_INLINE void registry::initialize_logger(std::shared_ptr<logger> new_logge
...
@@ -67,9 +67,9 @@ SPDLOG_INLINE void registry::initialize_logger(std::shared_ptr<logger> new_logge
new_logger
->
set_level
(
level_
);
new_logger
->
set_level
(
level_
);
new_logger
->
flush_on
(
flush_level_
);
new_logger
->
flush_on
(
flush_level_
);
if
(
backtrace_
level_
!=
level
::
off
)
if
(
backtrace_
n_messages_
>
0
)
{
{
new_logger
->
enable_backtrace
(
backtrace_
level_
,
backtrace_
n_messages_
);
new_logger
->
enable_backtrace
(
backtrace_n_messages_
);
}
}
if
(
automatic_registration_
)
if
(
automatic_registration_
)
...
@@ -140,15 +140,14 @@ SPDLOG_INLINE void registry::set_formatter(std::unique_ptr<formatter> formatter)
...
@@ -140,15 +140,14 @@ SPDLOG_INLINE void registry::set_formatter(std::unique_ptr<formatter> formatter)
}
}
}
}
SPDLOG_INLINE
void
registry
::
enable_backtrace
(
level
::
level_enum
trigger_level
,
size_t
n_messages
)
SPDLOG_INLINE
void
registry
::
enable_backtrace
(
size_t
n_messages
)
{
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
logger_map_mutex_
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
logger_map_mutex_
);
backtrace_level_
=
trigger_level
;
backtrace_n_messages_
=
n_messages
;
backtrace_n_messages_
=
n_messages
;
for
(
auto
&
l
:
loggers_
)
for
(
auto
&
l
:
loggers_
)
{
{
l
.
second
->
enable_backtrace
(
trigger_level
,
n_messages
);
l
.
second
->
enable_backtrace
(
n_messages
);
}
}
}
}
...
...
include/spdlog/details/registry.h
View file @
dd33c16a
...
@@ -52,7 +52,7 @@ public:
...
@@ -52,7 +52,7 @@ public:
// Set global formatter. Each sink in each logger will get a clone of this object
// Set global formatter. Each sink in each logger will get a clone of this object
void
set_formatter
(
std
::
unique_ptr
<
formatter
>
formatter
);
void
set_formatter
(
std
::
unique_ptr
<
formatter
>
formatter
);
void
enable_backtrace
(
level
::
level_enum
trigger_level
,
size_t
n_messages
);
void
enable_backtrace
(
size_t
n_messages
);
void
set_level
(
level
::
level_enum
log_level
);
void
set_level
(
level
::
level_enum
log_level
);
...
@@ -96,7 +96,6 @@ private:
...
@@ -96,7 +96,6 @@ private:
std
::
unique_ptr
<
periodic_worker
>
periodic_flusher_
;
std
::
unique_ptr
<
periodic_worker
>
periodic_flusher_
;
std
::
shared_ptr
<
logger
>
default_logger_
;
std
::
shared_ptr
<
logger
>
default_logger_
;
bool
automatic_registration_
=
true
;
bool
automatic_registration_
=
true
;
level
::
level_enum
backtrace_level_
=
level
::
off
;
size_t
backtrace_n_messages_
=
0
;
size_t
backtrace_n_messages_
=
0
;
};
};
...
...
include/spdlog/logger-inl.h
View file @
dd33c16a
...
@@ -120,20 +120,29 @@ SPDLOG_INLINE void logger::set_pattern(std::string pattern, pattern_time_type ti
...
@@ -120,20 +120,29 @@ SPDLOG_INLINE void logger::set_pattern(std::string pattern, pattern_time_type ti
set_formatter
(
std
::
move
(
new_formatter
));
set_formatter
(
std
::
move
(
new_formatter
));
}
}
// create new backtrace sink and hand it all sinks
// create new backtrace sink and hand it all sinks
SPDLOG_INLINE
void
logger
::
enable_backtrace
(
level
::
level_enum
trigger_level
,
size_t
n_messages
)
SPDLOG_INLINE
void
logger
::
enable_backtrace
(
size_t
n_messages
)
{
{
if
(
!
backtrace_enabled_
)
if
(
!
backtrace_enabled_
)
{
{
backtrace_enabled_
=
true
;
backtrace_enabled_
=
true
;
auto
backtrace_sink
=
std
::
make_shared
<
spdlog
::
sinks
::
backtrace_sink_mt
>
(
trigger_level
,
n_messages
);
auto
backtrace_sink
=
std
::
make_shared
<
spdlog
::
sinks
::
backtrace_sink_mt
>
(
n_messages
);
backtrace_sink
->
set_sinks
(
std
::
move
(
sinks
()));
backtrace_sink
->
set_sinks
(
std
::
move
(
sinks
()));
sinks
().
push_back
(
std
::
move
(
backtrace_sink
));
sinks
().
push_back
(
std
::
move
(
backtrace_sink
));
this
->
set_level
(
spdlog
::
level
::
trace
);
this
->
set_level
(
spdlog
::
level
::
trace
);
}
}
}
}
SPDLOG_INLINE
void
logger
::
dump_backtrace
()
{
if
(
backtrace_enabled_
)
{
// 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
);
tracer
->
dump_backtrace
();
}
}
// flush functions
// flush functions
SPDLOG_INLINE
void
logger
::
flush
()
SPDLOG_INLINE
void
logger
::
flush
()
...
...
include/spdlog/logger.h
View file @
dd33c16a
...
@@ -323,7 +323,9 @@ public:
...
@@ -323,7 +323,9 @@ public:
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
);
void
enable_backtrace
(
level
::
level_enum
trigger_level
=
level
::
err
,
size_t
n_messages
=
16
);
void
enable_backtrace
(
size_t
n_messages
=
16
);
void
dump_backtrace
();
// flush functions
// flush functions
void
flush
();
void
flush
();
...
@@ -347,7 +349,7 @@ protected:
...
@@ -347,7 +349,7 @@ protected:
spdlog
::
level_t
level_
{
level
::
info
};
spdlog
::
level_t
level_
{
level
::
info
};
spdlog
::
level_t
flush_level_
{
level
::
off
};
spdlog
::
level_t
flush_level_
{
level
::
off
};
err_handler
custom_err_handler_
{
nullptr
};
err_handler
custom_err_handler_
{
nullptr
};
bool
backtrace_enabled_
{
false
};
bool
backtrace_enabled_
{
false
};
virtual
void
sink_it_
(
const
details
::
log_msg
&
msg
);
virtual
void
sink_it_
(
const
details
::
log_msg
&
msg
);
virtual
void
flush_
();
virtual
void
flush_
();
...
...
include/spdlog/sinks/backtrace-sink.h
View file @
dd33c16a
...
@@ -22,41 +22,37 @@ template<typename Mutex>
...
@@ -22,41 +22,37 @@ template<typename Mutex>
class
backtrace_sink
:
public
dist_sink
<
Mutex
>
class
backtrace_sink
:
public
dist_sink
<
Mutex
>
{
{
public:
public:
explicit
backtrace_sink
(
level
::
level_enum
trigger_level
=
spdlog
::
level
::
err
,
size_t
n_messages
=
16
)
explicit
backtrace_sink
(
size_t
n_messages
=
16
)
:
trigger_level_
{
trigger_level
}
:
traceback_msgs_
{
n_messages
}
,
traceback_msgs_
{
n_messages
}
{}
{}
protected:
void
dump_backtrace
()
level
::
level_enum
trigger_level_
;
{
std
::
lock_guard
<
Mutex
>
lock
(
base_sink
<
Mutex
>::
mutex_
);
dump_backtrace_
();
}
protected:
details
::
circular_q
<
details
::
log_msg_buffer
>
traceback_msgs_
;
details
::
circular_q
<
details
::
log_msg_buffer
>
traceback_msgs_
;
// if current message is high enough, trigger a backtrace log,
// save the messages in a circular queue
// otherwise save the message in the queue for future trigger.
void
sink_it_
(
const
details
::
log_msg
&
msg
)
override
void
sink_it_
(
const
details
::
log_msg
&
msg
)
override
{
{
if
(
msg
.
level
<
trigger_level_
)
traceback_msgs_
.
push_back
(
details
::
log_msg_buffer
(
msg
));
{
traceback_msgs_
.
push_back
(
details
::
log_msg_buffer
(
msg
));
}
if
(
msg
.
level
>
level
::
debug
)
if
(
msg
.
level
>
level
::
debug
)
{
{
dist_sink
<
Mutex
>::
sink_it_
(
msg
);
dist_sink
<
Mutex
>::
sink_it_
(
msg
);
}
}
if
(
msg
.
level
>=
trigger_level_
)
{
log_backtrace_
(
msg
.
logger_name
);
}
}
}
void
log_backtrace_
(
const
string_view_t
&
logger_name
)
void
dump_backtrace_
(
)
{
{
if
(
traceback_msgs_
.
empty
())
if
(
traceback_msgs_
.
empty
())
{
{
return
;
return
;
}
}
const
char
*
logger_name
=
"??????"
;
dist_sink
<
Mutex
>::
sink_it_
(
dist_sink
<
Mutex
>::
sink_it_
(
details
::
log_msg
{
logger_name
,
level
::
info
,
"********************* Backtrace Start *********************"
});
details
::
log_msg
{
logger_name
,
level
::
info
,
"********************* Backtrace Start *********************"
});
...
...
include/spdlog/spdlog-inl.h
View file @
dd33c16a
...
@@ -32,9 +32,9 @@ SPDLOG_INLINE void set_pattern(std::string pattern, pattern_time_type time_type)
...
@@ -32,9 +32,9 @@ SPDLOG_INLINE void set_pattern(std::string pattern, pattern_time_type time_type)
set_formatter
(
std
::
unique_ptr
<
spdlog
::
formatter
>
(
new
pattern_formatter
(
std
::
move
(
pattern
),
time_type
)));
set_formatter
(
std
::
unique_ptr
<
spdlog
::
formatter
>
(
new
pattern_formatter
(
std
::
move
(
pattern
),
time_type
)));
}
}
SPDLOG_INLINE
void
enable_backtrace
(
level
::
level_enum
trigger_level
,
size_t
n_messages
)
SPDLOG_INLINE
void
enable_backtrace
(
size_t
n_messages
)
{
{
details
::
registry
::
instance
().
enable_backtrace
(
trigger_level
,
n_messages
);
details
::
registry
::
instance
().
enable_backtrace
(
n_messages
);
}
}
SPDLOG_INLINE
void
set_level
(
level
::
level_enum
log_level
)
SPDLOG_INLINE
void
set_level
(
level
::
level_enum
log_level
)
...
...
include/spdlog/spdlog.h
View file @
dd33c16a
...
@@ -61,7 +61,7 @@ void set_formatter(std::unique_ptr<spdlog::formatter> formatter);
...
@@ -61,7 +61,7 @@ void set_formatter(std::unique_ptr<spdlog::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
);
// enable global backtrace support
// enable global backtrace support
void
enable_backtrace
(
level
::
level_enum
trigger_level
=
level
::
err
,
size_t
n_messages
=
16
);
void
enable_backtrace
(
size_t
n_messages
);
// Set global logging level
// Set global logging level
void
set_level
(
level
::
level_enum
log_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