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
3a68eecb
Commit
3a68eecb
authored
Sep 25, 2020
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix issue #1680
parent
54a8259b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
20 deletions
+57
-20
include/spdlog/cfg/log_levels.h
include/spdlog/cfg/log_levels.h
+16
-16
include/spdlog/details/registry-inl.h
include/spdlog/details/registry-inl.h
+3
-2
tests/test_cfg.cpp
tests/test_cfg.cpp
+38
-2
No files found.
include/spdlog/cfg/log_levels.h
View file @
3a68eecb
...
...
@@ -3,7 +3,7 @@
#pragma once
#include <spdlog/
common
.h>
#include <spdlog/
logger
.h>
#include <string>
#include <unordered_map>
...
...
@@ -16,31 +16,31 @@ class log_levels
public:
void
set
(
const
std
::
string
&
logger_name
,
level
::
level_enum
lvl
)
{
if
(
logger_name
.
empty
())
{
default_level_
=
lvl
;
}
else
{
levels_
[
logger_name
]
=
lvl
;
}
}
void
set_default
(
level
::
level_enum
lvl
)
{
default_level_
=
lvl
;
levels_
[
""
]
=
lvl
;
}
level
::
level_enum
get
(
const
std
::
string
&
logger_name
)
// configure log level of given logger if it appears in the config list or if default level is set
void
update_logger_level
(
spdlog
::
logger
&
logger
)
{
auto
&
logger_name
=
logger
.
name
();
auto
it
=
levels_
.
find
(
logger_name
);
return
it
!=
levels_
.
end
()
?
it
->
second
:
default_level_
;
// if logger was not configured, check if default log level was configured
if
(
it
==
levels_
.
end
())
{
it
=
levels_
.
find
(
""
);
//
}
level
::
level_enum
default_level
(
)
if
(
it
!=
levels_
.
end
()
)
{
return
default_level_
;
logger
.
set_level
(
it
->
second
);
}
}
};
}
// namespace cfg
...
...
include/spdlog/details/registry-inl.h
View file @
3a68eecb
...
...
@@ -67,7 +67,8 @@ SPDLOG_INLINE void registry::initialize_logger(std::shared_ptr<logger> new_logge
new_logger
->
set_error_handler
(
err_handler_
);
}
new_logger
->
set_level
(
levels_
.
get
(
new_logger
->
name
()));
levels_
.
update_logger_level
(
*
new_logger
);
new_logger
->
flush_on
(
flush_level_
);
if
(
backtrace_n_messages_
>
0
)
...
...
@@ -270,7 +271,7 @@ SPDLOG_INLINE void registry::update_levels(cfg::log_levels levels)
for
(
auto
&
l
:
loggers_
)
{
auto
&
logger
=
l
.
second
;
l
ogger
->
set_level
(
levels_
.
get
(
logger
->
name
())
);
l
evels_
.
update_logger_level
(
*
logger
);
}
}
...
...
tests/test_cfg.cpp
View file @
3a68eecb
...
...
@@ -92,7 +92,7 @@ TEST_CASE("argv7", "[cfg]")
spdlog
::
set_level
(
spdlog
::
level
::
info
);
}
TEST_CASE
(
"level-not-
found
-test1"
,
"[cfg]"
)
TEST_CASE
(
"level-not-
set
-test1"
,
"[cfg]"
)
{
spdlog
::
drop
(
"l1"
);
const
char
*
argv
[]
=
{
"ignore"
,
""
};
...
...
@@ -103,10 +103,30 @@ TEST_CASE("level-not-found-test1", "[cfg]")
REQUIRE
(
spdlog
::
default_logger
()
->
level
()
==
spdlog
::
level
::
info
);
}
TEST_CASE
(
"level-not-
found
-test2"
,
"[cfg]"
)
TEST_CASE
(
"level-not-
set
-test2"
,
"[cfg]"
)
{
spdlog
::
drop
(
"l1"
);
spdlog
::
drop
(
"l2"
);
const
char
*
argv
[]
=
{
"ignore"
,
"SPDLOG_LEVEL=l1=trace"
};
auto
l1
=
spdlog
::
create
<
spdlog
::
sinks
::
test_sink_st
>
(
"l1"
);
l1
->
set_level
(
spdlog
::
level
::
warn
);
auto
l2
=
spdlog
::
create
<
spdlog
::
sinks
::
test_sink_st
>
(
"l2"
);
l2
->
set_level
(
spdlog
::
level
::
warn
);
load_argv_levels
(
2
,
argv
);
REQUIRE
(
l1
->
level
()
==
spdlog
::
level
::
trace
);
REQUIRE
(
l2
->
level
()
==
spdlog
::
level
::
warn
);
REQUIRE
(
spdlog
::
default_logger
()
->
level
()
==
spdlog
::
level
::
info
);
}
TEST_CASE
(
"level-not-set-test3"
,
"[cfg]"
)
{
spdlog
::
drop
(
"l1"
);
spdlog
::
drop
(
"l2"
);
const
char
*
argv
[]
=
{
"ignore"
,
"SPDLOG_LEVEL=l1=trace"
};
load_argv_levels
(
2
,
argv
);
auto
l1
=
spdlog
::
create
<
spdlog
::
sinks
::
test_sink_st
>
(
"l1"
);
...
...
@@ -116,3 +136,19 @@ TEST_CASE("level-not-found-test2", "[cfg]")
REQUIRE
(
l2
->
level
()
==
spdlog
::
level
::
info
);
REQUIRE
(
spdlog
::
default_logger
()
->
level
()
==
spdlog
::
level
::
info
);
}
TEST_CASE
(
"level-not-set-test4"
,
"[cfg]"
)
{
spdlog
::
drop
(
"l1"
);
spdlog
::
drop
(
"l2"
);
const
char
*
argv
[]
=
{
"ignore"
,
"SPDLOG_LEVEL=l1=trace,warn"
};
load_argv_levels
(
2
,
argv
);
auto
l1
=
spdlog
::
create
<
spdlog
::
sinks
::
test_sink_st
>
(
"l1"
);
auto
l2
=
spdlog
::
create
<
spdlog
::
sinks
::
test_sink_st
>
(
"l2"
);
REQUIRE
(
l1
->
level
()
==
spdlog
::
level
::
trace
);
REQUIRE
(
l2
->
level
()
==
spdlog
::
level
::
warn
);
REQUIRE
(
spdlog
::
default_logger
()
->
level
()
==
spdlog
::
level
::
warn
);
}
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