-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add file event handlers #2165
add file event handlers #2165
Conversation
@@ -14,7 +14,8 @@ namespace spdlog { | |||
namespace sinks { | |||
|
|||
template<typename Mutex> | |||
SPDLOG_INLINE basic_file_sink<Mutex>::basic_file_sink(const filename_t &filename, bool truncate) | |||
SPDLOG_INLINE basic_file_sink<Mutex>::basic_file_sink(const filename_t &filename, bool truncate, const file_event_handlers_t& event_handlers) | |||
: file_helper_{std::move(event_handlers)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const reference cannot be really moved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -68,10 +68,11 @@ class daily_file_sink final : public base_sink<Mutex> | |||
{ | |||
public: | |||
// create daily file sink which rotates on given time | |||
daily_file_sink(filename_t base_filename, int rotation_hour, int rotation_minute, bool truncate = false, uint16_t max_files = 0) | |||
daily_file_sink(filename_t base_filename, int rotation_hour, int rotation_minute, bool truncate = false, uint16_t max_files = 0, const file_event_handlers_t& event_handlers = {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cannot really move const ref.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
example/example.cpp
Outdated
@@ -26,9 +26,32 @@ void custom_flags_example(); | |||
#include "spdlog/spdlog.h" | |||
#include "spdlog/cfg/env.h" // support for loading levels from the environment variable | |||
#include "spdlog/fmt/ostr.h" // support for user defined types | |||
#include "spdlog/common.h" | |||
|
|||
spdlog::file_event_handlers_t file_event_handlers; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to make it global
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
file_event_handlers is referenced by other example functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer not to change the original example functions and keep it simple. Lets just have single function in the end that shows how to use it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok.
I have fixed that. Just pass file_event_handlers to the rotating_logger
example/example.cpp
Outdated
|
||
spdlog::file_event_handlers_t file_event_handlers; | ||
|
||
void init_file_event_handler() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please move this towards the end of example.cpp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
Merged. Thanks @seker |
add file event handlers