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
b7d73344
Commit
b7d73344
authored
Mar 06, 2020
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Renamed level loaders
parent
c861e2d9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
14 additions
and
14 deletions
+14
-14
example/example.cpp
example/example.cpp
+2
-2
include/spdlog/cfg/argv.h
include/spdlog/cfg/argv.h
+1
-1
include/spdlog/cfg/env.h
include/spdlog/cfg/env.h
+1
-1
tests/test_cfg.cpp
tests/test_cfg.cpp
+10
-10
No files found.
example/example.cpp
View file @
b7d73344
...
@@ -28,11 +28,11 @@ int main(int, char *[])
...
@@ -28,11 +28,11 @@ int main(int, char *[])
// Optionally load log levels from the SPDLOG_LEVEL env variable or from argv.
// Optionally load log levels from the SPDLOG_LEVEL env variable or from argv.
// For example: set the global level to info and mylogger to to trace:
// For example: set the global level to info and mylogger to to trace:
// SPDLOG_LEVEL=info,mylogger=trace && ./example
// SPDLOG_LEVEL=info,mylogger=trace && ./example
spdlog
::
cfg
::
load_env
();
spdlog
::
cfg
::
load_env
_levels
();
// or from command line: "./example SPDLOG_LEVEL=info,mylogger=trace"
// or from command line: "./example SPDLOG_LEVEL=info,mylogger=trace"
// #include "spdlog/cfg/argv.h" // for loading levels from argv
// #include "spdlog/cfg/argv.h" // for loading levels from argv
// spdlog::cfg::load_argv(args, argv);
// spdlog::cfg::load_argv
_levels
(args, argv);
spdlog
::
warn
(
"Easy padding in numbers like {:08d}"
,
12
);
spdlog
::
warn
(
"Easy padding in numbers like {:08d}"
,
12
);
spdlog
::
critical
(
"Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}"
,
42
);
spdlog
::
critical
(
"Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}"
,
42
);
...
...
include/spdlog/cfg/argv.h
View file @
b7d73344
...
@@ -21,7 +21,7 @@ namespace spdlog {
...
@@ -21,7 +21,7 @@ namespace spdlog {
namespace
cfg
{
namespace
cfg
{
// search for SPDLOG_LEVEL= in the args and use it to init the levels
// search for SPDLOG_LEVEL= in the args and use it to init the levels
void
load_argv
(
int
args
,
char
**
argv
)
void
load_argv
_levels
(
int
args
,
char
**
argv
)
{
{
const
std
::
string
spdlog_level_prefix
=
"SPDLOG_LEVEL="
;
const
std
::
string
spdlog_level_prefix
=
"SPDLOG_LEVEL="
;
for
(
int
i
=
1
;
i
<
args
;
i
++
)
for
(
int
i
=
1
;
i
<
args
;
i
++
)
...
...
include/spdlog/cfg/env.h
View file @
b7d73344
...
@@ -25,7 +25,7 @@
...
@@ -25,7 +25,7 @@
namespace
spdlog
{
namespace
spdlog
{
namespace
cfg
{
namespace
cfg
{
void
load_env
()
void
load_env
_levels
()
{
{
auto
env_val
=
details
::
os
::
getenv
(
"SPDLOG_LEVEL"
);
auto
env_val
=
details
::
os
::
getenv
(
"SPDLOG_LEVEL"
);
auto
levels
=
helpers
::
extract_levels
(
env_val
);
auto
levels
=
helpers
::
extract_levels
(
env_val
);
...
...
tests/test_cfg.cpp
View file @
b7d73344
...
@@ -4,8 +4,8 @@
...
@@ -4,8 +4,8 @@
#include <spdlog/cfg/env.h>
#include <spdlog/cfg/env.h>
#include <spdlog/cfg/argv.h>
#include <spdlog/cfg/argv.h>
using
spdlog
::
cfg
::
load_argv
;
using
spdlog
::
cfg
::
load_argv
_levels
;
using
spdlog
::
cfg
::
load_env
;
using
spdlog
::
cfg
::
load_env
_levels
;
using
spdlog
::
sinks
::
test_sink_st
;
using
spdlog
::
sinks
::
test_sink_st
;
TEST_CASE
(
"env"
,
"[cfg]"
)
TEST_CASE
(
"env"
,
"[cfg]"
)
...
@@ -17,7 +17,7 @@ TEST_CASE("env", "[cfg]")
...
@@ -17,7 +17,7 @@ TEST_CASE("env", "[cfg]")
#else
#else
setenv
(
"SPDLOG_LEVEL"
,
"l1=warn"
,
1
);
setenv
(
"SPDLOG_LEVEL"
,
"l1=warn"
,
1
);
#endif
#endif
load_env
();
load_env
_levels
();
REQUIRE
(
l1
->
level
()
==
spdlog
::
level
::
warn
);
REQUIRE
(
l1
->
level
()
==
spdlog
::
level
::
warn
);
spdlog
::
set_default_logger
(
spdlog
::
create
<
test_sink_st
>
(
"cfg-default"
));
spdlog
::
set_default_logger
(
spdlog
::
create
<
test_sink_st
>
(
"cfg-default"
));
REQUIRE
(
spdlog
::
default_logger
()
->
level
()
==
spdlog
::
level
::
info
);
REQUIRE
(
spdlog
::
default_logger
()
->
level
()
==
spdlog
::
level
::
info
);
...
@@ -27,7 +27,7 @@ TEST_CASE("argv1", "[cfg]")
...
@@ -27,7 +27,7 @@ TEST_CASE("argv1", "[cfg]")
{
{
spdlog
::
drop
(
"l1"
);
spdlog
::
drop
(
"l1"
);
const
char
*
argv
[]
=
{
"ignore"
,
"SPDLOG_LEVEL=l1=warn"
};
const
char
*
argv
[]
=
{
"ignore"
,
"SPDLOG_LEVEL=l1=warn"
};
load_argv
(
2
,
const_cast
<
char
**>
(
argv
));
load_argv
_levels
(
2
,
const_cast
<
char
**>
(
argv
));
auto
l1
=
spdlog
::
create
<
spdlog
::
sinks
::
test_sink_st
>
(
"l1"
);
auto
l1
=
spdlog
::
create
<
spdlog
::
sinks
::
test_sink_st
>
(
"l1"
);
REQUIRE
(
l1
->
level
()
==
spdlog
::
level
::
warn
);
REQUIRE
(
l1
->
level
()
==
spdlog
::
level
::
warn
);
REQUIRE
(
spdlog
::
default_logger
()
->
level
()
==
spdlog
::
level
::
info
);
REQUIRE
(
spdlog
::
default_logger
()
->
level
()
==
spdlog
::
level
::
info
);
...
@@ -37,7 +37,7 @@ TEST_CASE("argv2", "[cfg]")
...
@@ -37,7 +37,7 @@ TEST_CASE("argv2", "[cfg]")
{
{
spdlog
::
drop
(
"l1"
);
spdlog
::
drop
(
"l1"
);
const
char
*
argv
[]
=
{
"ignore"
,
"SPDLOG_LEVEL=l1=warn,trace"
};
const
char
*
argv
[]
=
{
"ignore"
,
"SPDLOG_LEVEL=l1=warn,trace"
};
load_argv
(
2
,
const_cast
<
char
**>
(
argv
));
load_argv
_levels
(
2
,
const_cast
<
char
**>
(
argv
));
auto
l1
=
spdlog
::
create
<
test_sink_st
>
(
"l1"
);
auto
l1
=
spdlog
::
create
<
test_sink_st
>
(
"l1"
);
REQUIRE
(
l1
->
level
()
==
spdlog
::
level
::
warn
);
REQUIRE
(
l1
->
level
()
==
spdlog
::
level
::
warn
);
REQUIRE
(
spdlog
::
default_logger
()
->
level
()
==
spdlog
::
level
::
trace
);
REQUIRE
(
spdlog
::
default_logger
()
->
level
()
==
spdlog
::
level
::
trace
);
...
@@ -48,7 +48,7 @@ TEST_CASE("argv3", "[cfg]")
...
@@ -48,7 +48,7 @@ TEST_CASE("argv3", "[cfg]")
{
{
spdlog
::
drop
(
"l1"
);
spdlog
::
drop
(
"l1"
);
const
char
*
argv
[]
=
{
"ignore"
,
"SPDLOG_LEVEL="
};
const
char
*
argv
[]
=
{
"ignore"
,
"SPDLOG_LEVEL="
};
load_argv
(
2
,
const_cast
<
char
**>
(
argv
));
load_argv
_levels
(
2
,
const_cast
<
char
**>
(
argv
));
auto
l1
=
spdlog
::
create
<
test_sink_st
>
(
"l1"
);
auto
l1
=
spdlog
::
create
<
test_sink_st
>
(
"l1"
);
REQUIRE
(
l1
->
level
()
==
spdlog
::
level
::
info
);
REQUIRE
(
l1
->
level
()
==
spdlog
::
level
::
info
);
REQUIRE
(
spdlog
::
default_logger
()
->
level
()
==
spdlog
::
level
::
info
);
REQUIRE
(
spdlog
::
default_logger
()
->
level
()
==
spdlog
::
level
::
info
);
...
@@ -58,7 +58,7 @@ TEST_CASE("argv4", "[cfg]")
...
@@ -58,7 +58,7 @@ TEST_CASE("argv4", "[cfg]")
{
{
spdlog
::
drop
(
"l1"
);
spdlog
::
drop
(
"l1"
);
const
char
*
argv
[]
=
{
"ignore"
,
"SPDLOG_LEVEL=junk"
};
const
char
*
argv
[]
=
{
"ignore"
,
"SPDLOG_LEVEL=junk"
};
load_argv
(
2
,
const_cast
<
char
**>
(
argv
));
load_argv
_levels
(
2
,
const_cast
<
char
**>
(
argv
));
auto
l1
=
spdlog
::
create
<
test_sink_st
>
(
"l1"
);
auto
l1
=
spdlog
::
create
<
test_sink_st
>
(
"l1"
);
REQUIRE
(
l1
->
level
()
==
spdlog
::
level
::
info
);
REQUIRE
(
l1
->
level
()
==
spdlog
::
level
::
info
);
}
}
...
@@ -67,7 +67,7 @@ TEST_CASE("argv5", "[cfg]")
...
@@ -67,7 +67,7 @@ TEST_CASE("argv5", "[cfg]")
{
{
spdlog
::
drop
(
"l1"
);
spdlog
::
drop
(
"l1"
);
const
char
*
argv
[]
=
{
"ignore"
,
"ignore"
,
"SPDLOG_LEVEL=l1=warn,trace"
};
const
char
*
argv
[]
=
{
"ignore"
,
"ignore"
,
"SPDLOG_LEVEL=l1=warn,trace"
};
load_argv
(
3
,
const_cast
<
char
**>
(
argv
));
load_argv
_levels
(
3
,
const_cast
<
char
**>
(
argv
));
auto
l1
=
spdlog
::
create
<
test_sink_st
>
(
"l1"
);
auto
l1
=
spdlog
::
create
<
test_sink_st
>
(
"l1"
);
REQUIRE
(
l1
->
level
()
==
spdlog
::
level
::
warn
);
REQUIRE
(
l1
->
level
()
==
spdlog
::
level
::
warn
);
REQUIRE
(
spdlog
::
default_logger
()
->
level
()
==
spdlog
::
level
::
trace
);
REQUIRE
(
spdlog
::
default_logger
()
->
level
()
==
spdlog
::
level
::
trace
);
...
@@ -78,7 +78,7 @@ TEST_CASE("argv6", "[cfg]")
...
@@ -78,7 +78,7 @@ TEST_CASE("argv6", "[cfg]")
{
{
spdlog
::
set_level
(
spdlog
::
level
::
err
);
spdlog
::
set_level
(
spdlog
::
level
::
err
);
const
char
*
argv
[]
=
{
""
};
const
char
*
argv
[]
=
{
""
};
load_argv
(
1
,
const_cast
<
char
**>
(
argv
));
load_argv
_levels
(
1
,
const_cast
<
char
**>
(
argv
));
REQUIRE
(
spdlog
::
default_logger
()
->
level
()
==
spdlog
::
level
::
err
);
REQUIRE
(
spdlog
::
default_logger
()
->
level
()
==
spdlog
::
level
::
err
);
spdlog
::
set_level
(
spdlog
::
level
::
info
);
spdlog
::
set_level
(
spdlog
::
level
::
info
);
}
}
...
@@ -87,7 +87,7 @@ TEST_CASE("argv7", "[cfg]")
...
@@ -87,7 +87,7 @@ TEST_CASE("argv7", "[cfg]")
{
{
spdlog
::
set_level
(
spdlog
::
level
::
err
);
spdlog
::
set_level
(
spdlog
::
level
::
err
);
const
char
*
argv
[]
=
{
""
};
const
char
*
argv
[]
=
{
""
};
load_argv
(
0
,
const_cast
<
char
**>
(
argv
));
load_argv
_levels
(
0
,
const_cast
<
char
**>
(
argv
));
REQUIRE
(
spdlog
::
default_logger
()
->
level
()
==
spdlog
::
level
::
err
);
REQUIRE
(
spdlog
::
default_logger
()
->
level
()
==
spdlog
::
level
::
err
);
spdlog
::
set_level
(
spdlog
::
level
::
info
);
spdlog
::
set_level
(
spdlog
::
level
::
info
);
}
}
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