FlatImage
A configurable Linux containerization system
Loading...
Searching...
No Matches
ns_log Namespace Reference

Multi-level logging system with file and stdout sinks. More...

Classes

class  critical
 Critical-level logger (highest priority, always shown) More...
 
class  debug
 Debug-level logger (lowest priority) More...
 
class  error
 Error-level logger (recoverable errors) More...
 
class  info
 Info-level logger (informational messages) More...
 
struct  Location
 Source code location information for log messages. More...
 
class  warn
 Warning-level logger (potential issues) More...
 
class  Writer
 Base class for level-specific log writers (debug, info, warn, error, critical) More...
 

Enumerations

enum class  Level : int {
  CRITICAL , ERROR , WARN , INFO ,
  DEBUG
}
 

Functions

void set_level (Level level)
 Sets the logging verbosity (CRITICAL,ERROR,INFO,DEBUG)
 
Level get_level ()
 Get current verbosity level of the logger.
 
void set_sink_file (fs::path const &path_file_sink)
 Sets the sink file of the logger.
 
void set_as_fork ()
 Marks the logger as being in a forked child process.
 
template<typename... Ts>
std::string vformat (std::string_view fmt, Ts &&... ts)
 Workaround make_format_args only taking references.
 
template<ns_string::static_string str>
constexpr decltype(auto) impl_log (Location loc)
 Implementation function for compile-time log level dispatch.
 

Detailed Description

Multi-level logging system with file and stdout sinks.

Thread-local logging infrastructure supporting DEBUG, INFO, WARNING, ERROR, and CRITICAL levels with automatic source location tracking. Provides dual output to log files and stdout/stderr with level-based prefixes (D::, I::, W::, E::, C::) for convenient filtering and categorization.

Enumeration Type Documentation

◆ Level

enum class ns_log::Level : int
strong

Definition at line 147 of file log.hpp.

Function Documentation

◆ get_level()

Level ns_log::get_level ( )
inline

Get current verbosity level of the logger.

Returns
Level

Definition at line 349 of file log.hpp.

◆ impl_log()

template<ns_string::static_string str>
decltype(auto) ns_log::impl_log ( Location loc)
constexpr

Implementation function for compile-time log level dispatch.

Template Parameters
strStatic string containing the log level prefix (D::, I::, W::, E::, C::, Q::)
Parameters
locSource location of the log call
Returns
Lambda that accepts variadic arguments and dispatches to the appropriate logger

Definition at line 737 of file log.hpp.

◆ set_as_fork()

void ns_log::set_as_fork ( )
inline

Marks the logger as being in a forked child process.

For processes that need to explicitly indicate they are children (e.g., pipe readers forked from the parent), this function sets the logger's tracked PID to an invalid value (0) so that subsequent log messages always display the current process ID instead of file location information.

Usage Example:

pid_t pid = fork();
if (pid == 0) {
// Child process
ns_log::set_as_fork(); // Ensure logs show this process's PID
logger("I::Starting in child process");
}
#define logger(fmt,...)
Compile-time log level dispatch macro with automatic location capture.
Definition log.hpp:682
void set_as_fork()
Marks the logger as being in a forked child process.
Definition log.hpp:390
void set_sink_file(fs::path const &path_file_sink)
Sets the sink file of the logger.
Definition log.hpp:359

Effect on Log Output:

  • Before: I::boot.cpp::50::Message (if m_pid matched current PID)
  • After: I::12345::Message (always shows current PID since m_pid=0)

Note: This is typically automatic after fork() + pthread_atfork handlers, but can be called explicitly for clarity or in special circumstances.

Definition at line 390 of file log.hpp.

Here is the caller graph for this function:

◆ set_level()

void ns_log::set_level ( Level level)
inline

Sets the logging verbosity (CRITICAL,ERROR,INFO,DEBUG)

Parameters
levelEnumeration of the verbosity level

Definition at line 339 of file log.hpp.

Here is the caller graph for this function:

◆ set_sink_file()

void ns_log::set_sink_file ( fs::path const & path_file_sink)
inline

Sets the sink file of the logger.

Parameters
path_file_sinkThe path to the logger sink file

Definition at line 359 of file log.hpp.

Here is the caller graph for this function:

◆ vformat()

template<typename... Ts>
std::string ns_log::vformat ( std::string_view fmt,
Ts &&... ts )

Workaround make_format_args only taking references.

Template Parameters
TsTypes of format arguments (variadic)
Parameters
fmtFormat of the string
tsArguments to the input format
Returns
std::string The formatted string

Definition at line 440 of file log.hpp.

Here is the caller graph for this function: