42 explicit file_sink(
const std::string& file_path,
bool append =
true)
46 auto mode = append ? (std::ios::out | std::ios::app) : std::ios::out;
47 file_.open(file_path, mode);
52 if (
file_.is_open()) {
59 std::lock_guard<std::mutex> lock(
mutex_);
77 std::lock_guard<std::mutex> lock(
mutex_);
79 if (!
file_.is_open()) {
102 std::lock_guard<std::mutex> lock(
mutex_);
104 if (
file_.is_open()) {
107 info +=
", size: " + std::to_string(
size / 1024) +
"KB";
Writes log messages to a file.
std::string get_info() const override
Get sink information.
std::string get_file_path() const
Get the file path.
bool is_healthy() const override
Check if the sink is healthy.
common::VoidResult flush() override
Flush any buffered data.
common::VoidResult write_raw(std::string_view message) override
Write a pre-formatted message to the output destination.
std::string get_name() const override
Get the name of this sink.
file_sink(const std::string &file_path, bool append=true)
Construct a file sink.
Abstract interface for log output destinations (I/O only)
common::VoidResult make_logger_void_result(logger_error_code code, const std::string &message="")
@ size
Rotate based on file size only.
Interface for log output destinations (Single Responsibility Principle) kcenon.