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
c861e2d9
Commit
c861e2d9
authored
Feb 26, 2020
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated example
parent
e696978d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
23 deletions
+12
-23
example/example.cpp
example/example.cpp
+12
-23
No files found.
example/example.cpp
View file @
c861e2d9
...
...
@@ -10,8 +10,6 @@ void stdout_logger_example();
void
basic_example
();
void
rotating_example
();
void
daily_example
();
void
env_cfg_example
();
void
argv_cfg_example
(
int
,
char
*
[]);
void
async_example
();
void
binary_example
();
void
trace_example
();
...
...
@@ -21,10 +19,21 @@ void err_handler_example();
void
syslog_example
();
#include "spdlog/spdlog.h"
#include "spdlog/cfg/env.h" // for loading levels from the environment variables
int
main
(
int
args
,
char
*
argv
[])
int
main
(
int
,
char
*
[])
{
spdlog
::
info
(
"Welcome to spdlog version {}.{}.{} !"
,
SPDLOG_VER_MAJOR
,
SPDLOG_VER_MINOR
,
SPDLOG_VER_PATCH
);
// 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:
// SPDLOG_LEVEL=info,mylogger=trace && ./example
spdlog
::
cfg
::
load_env
();
// or from command line: "./example SPDLOG_LEVEL=info,mylogger=trace"
// #include "spdlog/cfg/argv.h" // for loading levels from argv
// spdlog::cfg::load_argv(args, argv);
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
::
info
(
"Support for floats {:03.2f}"
,
1.23456
);
...
...
@@ -67,12 +76,6 @@ int main(int args, char *argv[])
err_handler_example
();
trace_example
();
// Init levels from SPDLOG_LEVEL env variable
env_cfg_example
();
// Init levels from args (example.exe "SPDLOG_LEVEL=trace,l2=info,l3=off")
argv_cfg_example
(
args
,
argv
);
// Flush all *registered* loggers using a worker thread every 3 seconds.
// note: registered loggers *must* be thread safe for this to work correctly!
spdlog
::
flush_every
(
std
::
chrono
::
seconds
(
3
));
...
...
@@ -80,7 +83,6 @@ int main(int args, char *argv[])
// Apply some function on all registered loggers
spdlog
::
apply_all
([
&
](
std
::
shared_ptr
<
spdlog
::
logger
>
l
)
{
l
->
info
(
"End of example."
);
});
// Release all spdlog resources, and drop all loggers in the registry.
// This is optional (only mandatory if using windows + async log).
spdlog
::
shutdown
();
...
...
@@ -125,19 +127,6 @@ void daily_example()
auto
daily_logger
=
spdlog
::
daily_logger_mt
(
"daily_logger"
,
"logs/daily.txt"
,
2
,
30
);
}
#include "spdlog/cfg/env.h"
void
env_cfg_example
()
{
// set levels from SPDLOG_LEVEL env variable
spdlog
::
cfg
::
load_env
();
}
#include "spdlog/cfg/argv.h"
void
argv_cfg_example
(
int
args
,
char
*
argv
[])
{
spdlog
::
cfg
::
load_argv
(
args
,
argv
);
}
#include "spdlog/async.h"
void
async_example
()
{
...
...
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