Update README.md

This commit is contained in:
Gabi Melman 2021-11-15 14:45:07 +02:00 committed by GitHub
parent cbaf4880ad
commit a5fa6eb356
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -379,20 +379,14 @@ $ ./example
```c++
// You can get subscribe to get callbacks from spdlog before/after log file has been opened or closed.
// This is useful for cleanup procedures or for adding someting the start/end of the log files.
void file_events_example(){
void file_events_example()
{
// pass the spdlog::file_event_handlers_t to file sinks for open/close log file notifications
spdlog::file_event_handlers_t handlers;
handlers.before_open = [](spdlog::filename_t filename) {
spdlog::info("Before opening {}", filename);
};
handlers.after_open = [](spdlog::filename_t filename, std::FILE *fstream) {
fputs("After opening\n", fstream);
};
handlers.before_close = [](spdlog::filename_t filename, std::FILE *fstream) {
fputs("Before closing\n", fstream);
};
handlers.after_close = [](spdlog::filename_t filename) {
spdlog::info("After closing {}", filename);
};
handlers.before_open = [](spdlog::filename_t filename) { spdlog::info("Before opening {}", filename); };
handlers.after_open = [](spdlog::filename_t filename, std::FILE *fstream) { fputs("After opening\n", fstream); };
handlers.before_close = [](spdlog::filename_t filename, std::FILE *fstream) { fputs("Before closing\n", fstream); };
handlers.after_close = [](spdlog::filename_t filename) { spdlog::info("After closing {}", filename); };
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("logs/events-sample.txt", true, handlers);
spdlog::logger my_logger("some_logger", file_sink);
// or