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
332eaaf9
Commit
332eaaf9
authored
Mar 21, 2020
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update readme with custom flags example
parent
0a5ada64
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
0 deletions
+35
-0
README.md
README.md
+35
-0
No files found.
README.md
View file @
332eaaf9
...
...
@@ -284,6 +284,39 @@ void user_defined_example()
}
```
---
#### User defined flags in the log pattern
```
c++
// Log patterns can contain custom flags.
// the following example will add new flag '%*' - which will be bound to a <my_formatter_flag> instance.
#include "spdlog/pattern_formatter.h"
class
my_formatter_flag
:
public
spdlog
::
custom_flag_formatter
{
public:
void
format
(
const
spdlog
::
details
::
log_msg
&
,
const
std
::
tm
&
,
spdlog
::
memory_buf_t
&
dest
)
override
{
std
::
string
some_txt
=
"custom-flag"
;
dest
.
append
(
some_txt
.
data
(),
some_txt
.
data
()
+
some_txt
.
size
());
}
std
::
unique_ptr
<
custom_flag_formatter
>
clone
()
const
override
{
return
spdlog
::
details
::
make_unique
<
my_formatter_flag
>
();
}
};
void
custom_flags_example
()
{
using
spdlog
::
details
::
make_unique
;
// for pre c++14
auto
formatter
=
make_unique
<
spdlog
::
pattern_formatter
>
();
formatter
->
add_flag
<
my_formatter_flag
>
(
'*'
).
set_pattern
(
"[%n] [%*] [%^%l%$] %v"
);
spdlog
::
set_formatter
(
std
::
move
(
formatter
));
}
```
---
#### Custom error handler
```
c++
...
...
@@ -295,6 +328,8 @@ void err_handler_example()
}
```
---
#### syslog
```
c++
...
...
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