mirror of
https://github.com/gabime/spdlog.git
synced 2024-11-21 03:12:41 +08:00
Update readme with custom flags example
This commit is contained in:
parent
0a5ada6411
commit
332eaaf916
35
README.md
35
README.md
@ -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++
|
||||
|
Loading…
Reference in New Issue
Block a user