Flow 1.0.2
Flow project: Full implementation reference.
|
An internal-use implementation of Logger that logs messages to a given file-system path, blocking the calling thread while the I/O occurs, and usable safely only if logging occurs non-concurrently. More...
#include <serial_file_logger.hpp>
Public Member Functions | |
Serial_file_logger (Logger *backup_logger_ptr, Config *config, const fs::path &log_path) | |
Constructs logger to subsequently log to the given file-system path. More... | |
~Serial_file_logger () override | |
Flushes out anything buffered, returns resources/closes output file(s); then returns. More... | |
bool | should_log (Sev sev, const Component &component) const override |
See Async_file_logger::should_log(). More... | |
bool | logs_asynchronously () const override |
Implements interface method by returning false , indicating that this Logger will not need the contents of *metadata and msg passed to do_log() after that method returns. More... | |
void | do_log (Msg_metadata *metadata, util::String_view msg) override |
Implements interface method by synchronously logging the message and some subset of the metadata in a fashion controlled by m_config. More... | |
void | log_flush_and_reopen () |
Causes the log at the file-system path to be flushed/closed (if needed) and re-opened; this will occur synchronously meaning it will complete before the method returns. More... | |
Public Member Functions inherited from flow::log::Logger | |
virtual bool | should_log (Sev sev, const Component &component) const =0 |
Given attributes of a hypothetical message that would be logged, return true if that message should be logged and false otherwise (e.g., if the verbosity of the message is above the current configured verbosity threshold for the Component specified). More... | |
virtual bool | logs_asynchronously () const =0 |
Must return true if do_log() at least sometimes logs the given message and metadata (e.g., time stamp) after do_log() returns; false if this never occurs (i.e., it logs synchronously, always). More... | |
virtual void | do_log (Msg_metadata *metadata, util::String_view msg)=0 |
Given a message and its severity, logs that message and possibly severity WITHOUT checking whether it should be logged (i.e., without performing logic that should_log() performs). More... | |
std::ostream * | this_thread_ostream () const |
Returns the stream dedicated to the executing thread and this Logger, so that the caller can apply state-setting formatters to it. More... | |
Public Member Functions inherited from flow::util::Null_interface | |
virtual | ~Null_interface ()=0 |
Boring virtual destructor. More... | |
Public Member Functions inherited from flow::util::Unique_id_holder | |
Unique_id_holder () | |
Thread-safely construct an ID whose value is different from any other object of this class, past or future. More... | |
Unique_id_holder (const Unique_id_holder &) | |
This copy constructor is identical in behavior to Unique_id_holder(), the default ctor. More... | |
id_t | unique_id () const |
Raw unique ID identifying this object as well as any object of a derived type. More... | |
const Unique_id_holder & | operator= (const Unique_id_holder &) const |
This assignment operator is a const no-op. More... | |
Public Attributes | |
Config *const | m_config |
See Async_file_logger::m_config. More... | |
Private Attributes | |
const fs::path | m_log_path |
File-system path to which to write subsequently. More... | |
fs::ofstream | m_ofs |
The file to which to write. Because only the worker thread ever accesses it, no mutex is needed. More... | |
Ostream_log_msg_writer | m_ofs_writer |
Stream writer via which to log messages to m_ofs. More... | |
bool | m_reopening |
Starts at false , becomes true at entry to log_flush_and_reopen(), then becomes false again. More... | |
Additional Inherited Members | |
Public Types inherited from flow::util::Unique_id_holder | |
using | id_t = uint64_t |
Raw integer type to uniquely identify a thing. 64-bit width should make overflow extremely hard to reach. More... | |
Static Public Member Functions inherited from flow::log::Logger | |
static void | this_thread_set_logged_nickname (util::String_view thread_nickname=util::String_view(), Logger *logger_ptr=0, bool also_set_os_name=true) |
Sets or unsets the current thread's logging-worthy string name; optionally sets the OS thread name (such as visible in top output). More... | |
static std::ostream & | this_thread_logged_name_os_manip (std::ostream &os) |
ostream manipulator function that, if output via operator<< to an ostream , will cause the current thread's logging-worthy string name to be output to that stream. More... | |
static void | set_thread_info_in_msg_metadata (Msg_metadata *msg_metadata) |
Loads msg_metadata->m_call_thread_nickname (if set) or else msg_metadata->m_call_thread_id , based on whether/how this_thread_set_logged_nickname() was last called in the current thread. More... | |
static void | set_thread_info (std::string *call_thread_nickname, flow::util::Thread_id *call_thread_id) |
Same as set_thread_info_in_msg_metadata() but targets the given two variables as opposed to a Msg_metadata. More... | |
Static Public Member Functions inherited from flow::util::Unique_id_holder | |
static id_t | create_unique_id () |
Short-hand for Unique_id_holder().unique_id() ; useful when all you want is the unique integer itself. More... | |
Protected Member Functions inherited from flow::log::Log_context | |
Log_context (Logger *logger=0) | |
Constructs Log_context by storing the given pointer to a Logger and a null Component. More... | |
template<typename Component_payload > | |
Log_context (Logger *logger, Component_payload component_payload) | |
Constructs Log_context by storing the given pointer to a Logger and a new Component storing the specified generically typed payload (an enum value). More... | |
Log_context (const Log_context &src) | |
Copy constructor that stores equal Logger* and Component values as the source. More... | |
Log_context (Log_context &&src) | |
Move constructor that makes this equal to src , while the latter becomes as-if default-constructed. More... | |
Log_context & | operator= (const Log_context &src) |
Assignment operator that behaves similarly to the copy constructor. More... | |
Log_context & | operator= (Log_context &&src) |
Move assignment operator that behaves similarly to the move constructor. More... | |
void | swap (Log_context &other) |
Swaps Logger pointers and Component objects held by *this and other . More... | |
Logger * | get_logger () const |
Returns the stored Logger pointer, particularly as many FLOW_LOG_*() macros expect. More... | |
const Component & | get_log_component () const |
Returns reference to the stored Component object, particularly as many FLOW_LOG_*() macros expect. More... | |
An internal-use implementation of Logger that logs messages to a given file-system path, blocking the calling thread while the I/O occurs, and usable safely only if logging occurs non-concurrently.
As of this writing it is essentially an internal component needed by Async_file_logger; but it is a full-fledged Logger nevertheless.
The file I/O-using APIs, notably do_log() and log_flush_and_reopen() but not should_log(), are unsafe to call concurrently. The logging user – as of this writing Async_file_logger but it's fully conceivable other uses exist – must therefore provide any anti-concurrency measures (use one thread; a strand; mutex; etc.).
See thread safety notes and to-dos regarding m_config in Simple_ostream_logger doc header. These apply here also.
Definition at line 46 of file serial_file_logger.hpp.
|
explicit |
Constructs logger to subsequently log to the given file-system path.
It will append. This constructor itself does not perform any I/O operations.
config | See Async_file_logger ctor. |
log_path | See Async_file_logger ctor. |
backup_logger_ptr | See Async_file_logger ctor. |
Definition at line 27 of file serial_file_logger.cpp.
References FLOW_LOG_INFO, log_flush_and_reopen(), and m_log_path.
|
override |
Flushes out anything buffered, returns resources/closes output file(s); then returns.
Definition at line 50 of file serial_file_logger.cpp.
References FLOW_LOG_INFO, m_log_path, and m_ofs.
|
overridevirtual |
Implements interface method by synchronously logging the message and some subset of the metadata in a fashion controlled by m_config.
metadata | All information to potentially log in addition to msg . |
msg | The message. |
Implements flow::log::Logger.
Definition at line 63 of file serial_file_logger.cpp.
References FLOW_LOG_WARNING, flow::log::Ostream_log_msg_writer::log(), log_flush_and_reopen(), m_log_path, m_ofs, and m_ofs_writer.
void flow::log::Serial_file_logger::log_flush_and_reopen | ( | ) |
Causes the log at the file-system path to be flushed/closed (if needed) and re-opened; this will occur synchronously meaning it will complete before the method returns.
Definition at line 111 of file serial_file_logger.cpp.
References FLOW_LOG_INFO, FLOW_LOG_SET_LOGGER, FLOW_LOG_TRACE, FLOW_LOG_WARNING, m_log_path, m_ofs, and m_reopening.
Referenced by do_log(), and Serial_file_logger().
|
overridevirtual |
Implements interface method by returning false
, indicating that this Logger will not need the contents of *metadata
and msg
passed to do_log() after that method returns.
Implements flow::log::Logger.
Definition at line 193 of file serial_file_logger.cpp.
|
overridevirtual |
See Async_file_logger::should_log().
sev | See Async_file_logger::should_log(). |
component | See Async_file_logger::should_log(). |
Implements flow::log::Logger.
Definition at line 188 of file serial_file_logger.cpp.
Config* const flow::log::Serial_file_logger::m_config |
See Async_file_logger::m_config.
Definition at line 111 of file serial_file_logger.hpp.
|
private |
File-system path to which to write subsequently.
Definition at line 117 of file serial_file_logger.hpp.
Referenced by do_log(), log_flush_and_reopen(), Serial_file_logger(), and ~Serial_file_logger().
|
private |
The file to which to write. Because only the worker thread ever accesses it, no mutex is needed.
Definition at line 120 of file serial_file_logger.hpp.
Referenced by do_log(), log_flush_and_reopen(), and ~Serial_file_logger().
|
private |
|
private |
Starts at false
, becomes true
at entry to log_flush_and_reopen(), then becomes false
again.
Simple anti-recursion measure.
Definition at line 133 of file serial_file_logger.hpp.
Referenced by log_flush_and_reopen().