Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
S
spdlog
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
spdlog
Commits
9369fe8c
Commit
9369fe8c
authored
Oct 09, 2019
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #1262
parent
1549ff12
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
1 deletion
+23
-1
logger-inl.h
include/spdlog/logger-inl.h
+5
-0
logger.h
include/spdlog/logger.h
+4
-0
spdlog.h
include/spdlog/spdlog.h
+4
-1
test_macros.cpp
tests/test_macros.cpp
+10
-0
No files found.
include/spdlog/logger-inl.h
View file @
9369fe8c
...
...
@@ -69,6 +69,11 @@ SPDLOG_INLINE bool logger::should_log(level::level_enum msg_level) const
return
msg_level
>=
level_
.
load
(
std
::
memory_order_relaxed
);
}
SPDLOG_INLINE
bool
logger
::
should_backtrace
()
const
{
return
tracer_
.
enabled
();
}
SPDLOG_INLINE
void
logger
::
set_level
(
level
::
level_enum
log_level
)
{
level_
.
store
(
log_level
);
...
...
include/spdlog/logger.h
View file @
9369fe8c
...
...
@@ -319,8 +319,12 @@ public:
#endif // _WIN32
#endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT
// return true logging is enabled for the given level.
bool
should_log
(
level
::
level_enum
msg_level
)
const
;
// return true if backtrace logging is enabled.
bool
should_backtrace
()
const
;
void
set_level
(
level
::
level_enum
log_level
);
level
::
level_enum
level
()
const
;
...
...
include/spdlog/spdlog.h
View file @
9369fe8c
...
...
@@ -285,7 +285,10 @@ inline void critical(wstring_view_t fmt, const Args &... args)
// SPDLOG_LEVEL_OFF
//
#define SPDLOG_LOGGER_CALL(logger, level, ...) logger->log(spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, level, __VA_ARGS__)
#define SPDLOG_LOGGER_CALL(logger, level, ...) do {\
if(logger->should_log(level) || logger->should_backtrace()) \
logger->log(spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, level, __VA_ARGS__);\
} while(0)
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
#define SPDLOG_LOGGER_TRACE(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::trace, __VA_ARGS__)
...
...
tests/test_macros.cpp
View file @
9369fe8c
...
...
@@ -39,3 +39,13 @@ TEST_CASE("disable param evaluation", "[macros]")
{
SPDLOG_TRACE
(
"Test message {}"
,
throw
std
::
runtime_error
(
"Should not be evaluated"
));
}
// ensure that even if right macro level is on- don't eavluate if the logger's level is not high enough
TEST_CASE
(
"disable param evaluation2"
,
"[macros]"
)
{
auto
logger
=
std
::
make_shared
<
spdlog
::
logger
>
(
"test-macro"
);
logger
->
set_level
(
spdlog
::
level
::
off
);
int
x
=
0
;
SPDLOG_LOGGER_DEBUG
(
logger
,
"Test message {}"
,
++
x
);
REQUIRE
(
x
==
0
);
}
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