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
e1be7f3d
Commit
e1be7f3d
authored
Aug 27, 2019
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring to better support backtrace
parent
04a8485b
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
73 deletions
+27
-73
include/spdlog/details/backtracer.h
include/spdlog/details/backtracer.h
+1
-1
include/spdlog/logger-inl.h
include/spdlog/logger-inl.h
+2
-22
include/spdlog/logger.h
include/spdlog/logger.h
+22
-44
include/spdlog/spdlog.h
include/spdlog/spdlog.h
+2
-6
No files found.
include/spdlog/details/backtracer.h
View file @
e1be7f3d
...
@@ -24,7 +24,7 @@ public:
...
@@ -24,7 +24,7 @@ public:
:
messages_
{
n_message
}
:
messages_
{
n_message
}
{}
{}
void
add
_msg
(
const
log_msg
&
msg
)
void
add
(
const
log_msg
&
msg
)
{
{
std
::
lock_guard
<
std
::
mutex
>
lock
{
mutex_
};
std
::
lock_guard
<
std
::
mutex
>
lock
{
mutex_
};
messages_
.
push_back
(
log_msg_buffer
{
msg
});
messages_
.
push_back
(
log_msg_buffer
{
msg
});
...
...
include/spdlog/logger-inl.h
View file @
e1be7f3d
...
@@ -64,26 +64,6 @@ SPDLOG_INLINE void swap(logger &a, logger &b)
...
@@ -64,26 +64,6 @@ SPDLOG_INLINE void swap(logger &a, logger &b)
a
.
swap
(
b
);
a
.
swap
(
b
);
}
}
SPDLOG_INLINE
void
logger
::
log
(
source_loc
loc
,
level
::
level_enum
lvl
,
string_view_t
msg
)
{
if
(
tracer_
)
{
save_backtrace_
(
details
::
log_msg
(
loc
,
string_view_t
(
name_
),
lvl
,
msg
));
}
if
(
!
should_log
(
lvl
))
{
return
;
}
details
::
log_msg
log_msg
(
loc
,
string_view_t
(
name_
),
lvl
,
msg
);
sink_it_
(
log_msg
);
}
SPDLOG_INLINE
void
logger
::
log
(
level
::
level_enum
lvl
,
string_view_t
msg
)
{
log
(
source_loc
{},
lvl
,
msg
);
}
SPDLOG_INLINE
bool
logger
::
should_log
(
level
::
level_enum
msg_level
)
const
SPDLOG_INLINE
bool
logger
::
should_log
(
level
::
level_enum
msg_level
)
const
{
{
...
@@ -220,9 +200,9 @@ SPDLOG_INLINE void logger::flush_()
...
@@ -220,9 +200,9 @@ SPDLOG_INLINE void logger::flush_()
}
}
}
}
SPDLOG_INLINE
void
logger
::
save_backtrace
_
(
const
details
::
log_msg
&
msg
)
SPDLOG_INLINE
void
logger
::
backtrace_add
_
(
const
details
::
log_msg
&
msg
)
{
{
tracer_
->
add
_msg
(
msg
);
tracer_
->
add
(
msg
);
}
}
SPDLOG_INLINE
void
logger
::
dump_backtrace_
()
SPDLOG_INLINE
void
logger
::
dump_backtrace_
()
...
...
include/spdlog/logger.h
View file @
e1be7f3d
...
@@ -78,40 +78,30 @@ public:
...
@@ -78,40 +78,30 @@ public:
void
swap
(
spdlog
::
logger
&
other
)
SPDLOG_NOEXCEPT
;
void
swap
(
spdlog
::
logger
&
other
)
SPDLOG_NOEXCEPT
;
template
<
typename
...
Args
>
template
<
typename
...
Args
>
void
force_log
(
source_loc
loc
,
level
::
level_enum
lvl
,
string_view_t
fmt
,
const
Args
&
...
args
)
void
log
(
source_loc
loc
,
level
::
level_enum
lvl
,
string_view_t
fmt
,
const
Args
&
...
args
)
{
auto
level_enabled
=
should_log
(
lvl
);
if
(
!
level_enabled
&&
!
tracer_
)
{
{
return
;
}
SPDLOG_TRY
SPDLOG_TRY
{
{
fmt
::
memory_buffer
buf
;
fmt
::
memory_buffer
buf
;
fmt
::
format_to
(
buf
,
fmt
,
args
...);
fmt
::
format_to
(
buf
,
fmt
,
args
...);
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
);
if
(
level_enabled
)
sink_it_
(
log_msg
);
if
(
tracer_
)
if
(
tracer_
)
backtrace_add_
(
log_msg
);
{
save_backtrace_
(
log_msg
);
}
}
}
SPDLOG_LOGGER_CATCH
()
SPDLOG_LOGGER_CATCH
()
}
}
template
<
typename
...
Args
>
void
log
(
source_loc
loc
,
level
::
level_enum
lvl
,
string_view_t
fmt
,
const
Args
&
...
args
)
{
if
(
should_log
(
lvl
))
{
force_log
(
loc
,
lvl
,
fmt
,
args
...);
}
}
template
<
typename
...
Args
>
template
<
typename
...
Args
>
void
log
(
level
::
level_enum
lvl
,
string_view_t
fmt
,
const
Args
&
...
args
)
void
log
(
level
::
level_enum
lvl
,
string_view_t
fmt
,
const
Args
&
...
args
)
{
{
log
(
source_loc
{},
lvl
,
fmt
,
args
...);
log
(
source_loc
{},
lvl
,
fmt
,
args
...);
}
}
void
log
(
source_loc
loc
,
level
::
level_enum
lvl
,
const
string_view_t
msg
);
void
log
(
level
::
level_enum
lvl
,
string_view_t
msg
);
template
<
typename
...
Args
>
template
<
typename
...
Args
>
void
trace
(
string_view_t
fmt
,
const
Args
&
...
args
)
void
trace
(
string_view_t
fmt
,
const
Args
&
...
args
)
{
{
...
@@ -158,17 +148,23 @@ public:
...
@@ -158,17 +148,23 @@ public:
template
<
class
T
,
typename
std
::
enable_if
<
std
::
is_convertible
<
const
T
&
,
spdlog
::
string_view_t
>
::
value
,
T
>::
type
*
=
nullptr
>
template
<
class
T
,
typename
std
::
enable_if
<
std
::
is_convertible
<
const
T
&
,
spdlog
::
string_view_t
>
::
value
,
T
>::
type
*
=
nullptr
>
void
log
(
source_loc
loc
,
level
::
level_enum
lvl
,
const
T
&
msg
)
void
log
(
source_loc
loc
,
level
::
level_enum
lvl
,
const
T
&
msg
)
{
{
if
(
tracer_
)
auto
level_enabled
=
should_log
(
lvl
);
if
(
!
level_enabled
&&
!
tracer_
)
{
{
save_backtrace_
(
details
::
log_msg
(
loc
,
name_
,
lvl
,
msg
))
;
return
;
}
}
if
(
!
should_log
(
lvl
))
SPDLOG_TRY
{
{
return
;
details
::
log_msg
log_msg
(
loc
,
name_
,
lvl
,
msg
);
if
(
level_enabled
)
sink_it_
(
log_msg
);
if
(
tracer_
)
backtrace_add_
(
log_msg
);
}
SPDLOG_LOGGER_CATCH
()
}
}
details
::
log_msg
log_msg
(
loc
,
name_
,
lvl
,
msg
);
void
log
(
level
::
level_enum
lvl
,
string_view_t
msg
)
sink_it_
(
log_msg
);
{
log
(
source_loc
{},
lvl
,
msg
);
}
}
// T cannot be statically converted to string_view or wstring_view
// T cannot be statically converted to string_view or wstring_view
...
@@ -177,25 +173,7 @@ public:
...
@@ -177,25 +173,7 @@ public:
T
>::
type
*
=
nullptr
>
T
>::
type
*
=
nullptr
>
void
log
(
source_loc
loc
,
level
::
level_enum
lvl
,
const
T
&
msg
)
void
log
(
source_loc
loc
,
level
::
level_enum
lvl
,
const
T
&
msg
)
{
{
if
(
tracer_
)
log
(
loc
,
lvl
,
"{}"
,
msg
);
{
fmt
::
memory_buffer
buf
;
fmt
::
format_to
(
buf
,
"{}"
,
msg
);
save_backtrace_
(
details
::
log_msg
(
loc
,
name_
,
lvl
,
string_view_t
(
buf
.
data
(),
buf
.
size
())));
}
if
(
!
should_log
(
lvl
))
{
return
;
}
SPDLOG_TRY
{
fmt
::
memory_buffer
buf
;
fmt
::
format_to
(
buf
,
"{}"
,
msg
);
details
::
log_msg
log_msg
(
loc
,
name_
,
lvl
,
string_view_t
(
buf
.
data
(),
buf
.
size
()));
sink_it_
(
log_msg
);
}
SPDLOG_LOGGER_CATCH
()
}
}
template
<
typename
T
>
template
<
typename
T
>
...
@@ -376,7 +354,7 @@ protected:
...
@@ -376,7 +354,7 @@ protected:
virtual
void
sink_it_
(
const
details
::
log_msg
&
msg
);
virtual
void
sink_it_
(
const
details
::
log_msg
&
msg
);
virtual
void
flush_
();
virtual
void
flush_
();
void
save_backtrace
_
(
const
details
::
log_msg
&
msg
);
void
backtrace_add
_
(
const
details
::
log_msg
&
msg
);
void
dump_backtrace_
();
void
dump_backtrace_
();
bool
should_flush_
(
const
details
::
log_msg
&
msg
);
bool
should_flush_
(
const
details
::
log_msg
&
msg
);
...
...
include/spdlog/spdlog.h
View file @
e1be7f3d
...
@@ -285,12 +285,8 @@ inline void critical(wstring_view_t fmt, const Args &... args)
...
@@ -285,12 +285,8 @@ inline void critical(wstring_view_t fmt, const Args &... args)
// SPDLOG_LEVEL_OFF
// SPDLOG_LEVEL_OFF
//
//
#define SPDLOG_LOGGER_CALL(logger, level, ...) \
#define SPDLOG_LOGGER_CALL(logger, level, ...)\
do \
logger->log(spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, level, __VA_ARGS__); \
{ \
if (logger->should_log(level)) \
logger->force_log(spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, level, __VA_ARGS__); \
} while (0)
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
#define SPDLOG_LOGGER_TRACE(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::trace, __VA_ARGS__)
#define SPDLOG_LOGGER_TRACE(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::trace, __VA_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