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
51c851ce
Unverified
Commit
51c851ce
authored
Jul 17, 2018
by
Gabi Melman
Committed by
GitHub
Jul 17, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update README.md
parent
c2a49080
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
15 deletions
+31
-15
README.md
README.md
+31
-15
No files found.
README.md
View file @
51c851ce
...
...
@@ -76,9 +76,8 @@ async... Elapsed: 0.427072 2,341,527/sec
async... Elapsed: 0.449768 2,223,369/sec
```
## Usage
Example
## Usage
```
c++
#include "spdlog/spdlog.h"
#include "spdlog/sinks/stdout_color_sinks.h"
void
stdout_example
()
...
...
@@ -115,7 +114,9 @@ void stdout_example()
SPDLOG_TRACE
(
console
,
"Enabled only #ifdef SPDLOG_TRACE_ON..{} ,{}"
,
1
,
3.23
);
SPDLOG_DEBUG
(
console
,
"Enabled only #ifdef SPDLOG_DEBUG_ON.. {} ,{}"
,
1
,
3.23
);
}
```
#### Basic file logger
```
c++
#include "spdlog/sinks/basic_file_sink.h"
void
basic_logfile_example
()
{
...
...
@@ -130,13 +131,18 @@ void basic_logfile_example()
return
1
;
}
}
```
#### Rotating example
```
c++
#include "spdlog/sinks/rotating_file_sink.h"
void
rotating_example
()
{
// Create a file rotating logger with 5mb size max and 3 rotated files
auto
rotating_logger
=
spdlog
::
rotating_logger_mt
(
"some_logger_name"
,
"logs/rotating.txt"
,
1048576
*
5
,
3
);
}
```
#### Daily file example
```
c++
#include "spdlog/sinks/daily_file_sink.h"
void
daily_example
()
...
...
@@ -145,6 +151,10 @@ void daily_example()
auto
daily_logger
=
spdlog
::
daily_logger_mt
(
"daily_logger"
,
"logs/daily.txt"
,
2
,
30
);
}
```
#### Asynchronous example
```
c++
#include "spdlog/async.h"
void
async_example
()
{
...
...
@@ -160,6 +170,10 @@ void async_example()
}
}
```
#### Multi sink
```
c++
// create logger with 2 targets with different log levels and formats.
// the console will show only warnings or errors, while the file will log all.
void
multi_sink_example
()
...
...
@@ -176,6 +190,9 @@ void multi_sink_example()
logger
.
warn
(
"this should appear in both console and file"
);
logger
.
info
(
"this message should not appear in the console, only in the file"
);
}
```
#### User defined types logging
```
c++
// user defined types logging by implementing operator<<
#include "spdlog/fmt/ostr.h" // must be included
struct
my_type
...
...
@@ -193,9 +210,9 @@ void user_defined_example()
spdlog
::
get
(
"console"
)
->
info
(
"user defined type: {}"
,
my_type
{
14
});
}
//
// c
ustom error handler
//
```
#### C
ustom error handler
```
c++
void
err_handler_example
()
{
// can be set globally or per logger(logger->set_error_handler(..))
...
...
@@ -203,8 +220,9 @@ void err_handler_example()
spdlog
::
get
(
"console"
)
->
info
(
"some invalid message to trigger an error {}{}{}{}"
,
3
);
}
// syslog example (linux/osx/freebsd)
#ifndef _WIN32
```
#### syslog example
```
c++
#include "spdlog/sinks/syslog_sink.h"
void
syslog_example
()
{
...
...
@@ -212,10 +230,11 @@ void syslog_example()
auto
syslog_logger
=
spdlog
::
syslog_logger
(
"syslog"
,
ident
,
LOG_PID
);
syslog_logger
->
warn
(
"This is warning that will end up in syslog."
);
}
#endif
// Android example
#if defined(__ANDROID__)
```
#### Android example
```
c++
#incude "spdlog/sinks/android_sink.h"
void
android_example
()
{
...
...
@@ -223,9 +242,6 @@ void android_example()
auto
android_logger
=
spdlog
::
android_logger
(
"android"
,
tag
);
android_logger
->
critical
(
"Use
\"
adb shell logcat
\"
to view this message."
);
}
#endif
```
## Documentation
...
...
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