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
a6d8b526
Commit
a6d8b526
authored
Aug 23, 2019
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added enable_backtrace to spdlog_api
parent
65407539
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
46 additions
and
3 deletions
+46
-3
include/spdlog/details/registry-inl.h
include/spdlog/details/registry-inl.h
+19
-0
include/spdlog/details/registry.h
include/spdlog/details/registry.h
+4
-0
include/spdlog/logger-inl.h
include/spdlog/logger-inl.h
+10
-0
include/spdlog/logger.h
include/spdlog/logger.h
+2
-0
include/spdlog/sinks/backtrace-sink.h
include/spdlog/sinks/backtrace-sink.h
+3
-3
include/spdlog/spdlog-inl.h
include/spdlog/spdlog-inl.h
+5
-0
include/spdlog/spdlog.h
include/spdlog/spdlog.h
+3
-0
No files found.
include/spdlog/details/registry-inl.h
View file @
a6d8b526
...
...
@@ -67,10 +67,17 @@ SPDLOG_INLINE void registry::initialize_logger(std::shared_ptr<logger> new_logge
new_logger
->
set_level
(
level_
);
new_logger
->
flush_on
(
flush_level_
);
if
(
backtrace_level_
!=
level
::
off
)
{
new_logger
->
enable_backtrace
(
backtrace_level_
,
backtrace_n_messages_
);
}
if
(
automatic_registration_
)
{
register_logger_
(
std
::
move
(
new_logger
));
}
}
SPDLOG_INLINE
std
::
shared_ptr
<
logger
>
registry
::
get
(
const
std
::
string
&
logger_name
)
...
...
@@ -135,6 +142,18 @@ 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
)
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
logger_map_mutex_
);
backtrace_level_
=
trigger_level
;
backtrace_n_messages_
=
n_messages
;
for
(
auto
&
l
:
loggers_
)
{
l
.
second
->
enable_backtrace
(
trigger_level
,
n_messages
);
}
}
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 @
a6d8b526
...
...
@@ -52,6 +52,8 @@ public:
// Set global formatter. Each sink in each logger will get a clone of this object
void
set_formatter
(
std
::
unique_ptr
<
formatter
>
formatter
);
void
enable_backtrace
(
level
::
level_enum
trigger_level
,
size_t
n_messages
);
void
set_level
(
level
::
level_enum
log_level
);
void
flush_on
(
level
::
level_enum
log_level
);
...
...
@@ -94,6 +96,8 @@ private:
std
::
unique_ptr
<
periodic_worker
>
periodic_flusher_
;
std
::
shared_ptr
<
logger
>
default_logger_
;
bool
automatic_registration_
=
true
;
level
::
level_enum
backtrace_level_
=
level
::
off
;
size_t
backtrace_n_messages_
=
0
;
};
}
// namespace details
...
...
include/spdlog/logger-inl.h
View file @
a6d8b526
...
...
@@ -8,6 +8,7 @@
#endif
#include "spdlog/sinks/sink.h"
#include "spdlog/sinks/backtrace-sink.h"
#include "spdlog/details/pattern_formatter.h"
#include <cstdio>
...
...
@@ -119,6 +120,15 @@ SPDLOG_INLINE void logger::set_pattern(std::string pattern, pattern_time_type ti
set_formatter
(
std
::
move
(
new_formatter
));
}
SPDLOG_INLINE
void
logger
::
enable_backtrace
(
level
::
level_enum
trigger_level
,
size_t
n_messages
)
{
auto
backtrace_sink
=
std
::
make_shared
<
spdlog
::
sinks
::
backtrace_sink_mt
>
(
trigger_level
,
n_messages
);
backtrace_sink
->
set_sinks
(
std
::
move
(
sinks
()));
sinks
().
push_back
(
std
::
move
(
backtrace_sink
));
this
->
set_level
(
spdlog
::
level
::
trace
);
}
// flush functions
SPDLOG_INLINE
void
logger
::
flush
()
{
...
...
include/spdlog/logger.h
View file @
a6d8b526
...
...
@@ -323,6 +323,8 @@ public:
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
);
// flush functions
void
flush
();
void
flush_on
(
level
::
level_enum
log_level
);
...
...
include/spdlog/sinks/backtrace-sink.h
View file @
a6d8b526
...
...
@@ -40,7 +40,7 @@ template<typename Mutex>
class
backtrace_sink
:
public
dist_sink
<
Mutex
>
{
public:
explicit
backtrace_sink
(
level
::
level_enum
trigger_level
=
spdlog
::
level
::
warn
,
size_t
n_messages
=
32
)
explicit
backtrace_sink
(
level
::
level_enum
trigger_level
=
spdlog
::
level
::
err
,
size_t
n_messages
=
16
)
:
trigger_level_
{
trigger_level
}
,
traceback_msgs_
{
n_messages
}
{}
...
...
@@ -76,7 +76,7 @@ protected:
}
dist_sink
<
Mutex
>::
sink_it_
(
details
::
log_msg
{
logger_name
,
level
::
info
,
"*********************
[Backtrace Start]
*********************"
});
details
::
log_msg
{
logger_name
,
level
::
info
,
"*********************
Backtrace Start
*********************"
});
do
{
...
...
@@ -86,7 +86,7 @@ protected:
}
while
(
!
traceback_msgs_
.
empty
());
dist_sink
<
Mutex
>::
sink_it_
(
details
::
log_msg
{
logger_name
,
level
::
info
,
"*********************
[Backtrace End]
***********************"
});
details
::
log_msg
{
logger_name
,
level
::
info
,
"*********************
Backtrace End
***********************"
});
}
};
...
...
include/spdlog/spdlog-inl.h
View file @
a6d8b526
...
...
@@ -32,6 +32,11 @@ 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
)));
}
SPDLOG_INLINE
void
enable_backtrace
(
level
::
level_enum
trigger_level
,
size_t
n_messages
)
{
details
::
registry
::
instance
().
enable_backtrace
(
trigger_level
,
n_messages
);
}
SPDLOG_INLINE
void
set_level
(
level
::
level_enum
log_level
)
{
details
::
registry
::
instance
().
set_level
(
log_level
);
...
...
include/spdlog/spdlog.h
View file @
a6d8b526
...
...
@@ -60,6 +60,9 @@ void set_formatter(std::unique_ptr<spdlog::formatter> formatter);
// example: spdlog::set_pattern("%Y-%m-%d %H:%M:%S.%e %l : %v");
void
set_pattern
(
std
::
string
pattern
,
pattern_time_type
time_type
=
pattern_time_type
::
local
);
// enable global backtrace support
void
enable_backtrace
(
level
::
level_enum
trigger_level
=
level
::
err
,
size_t
n_messages
=
16
);
// 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