std::log
This library provides basic logging functionality. Logging levels, in increasing order of severity, are:
pub enum Level { Debug, Info, Warn, Error, Fatal, }
Convenience functions are provided for unconditional logging to the standard output stream.
Use a Logger instance to customize the logging-level and destination file.
Functions
-
debug(arg: any)
debug(format_string: str, *args: any) -
A convenience function for writing a
DEBUGmessage to the standard output stream.-
Calling this function with a single argument is equivalent to calling
$str()on that argument first and logging the resulting string. -
Calling this function with more than one argument is equivalent to calling
$fmt()on those arguments first and logging the resulting string.
-
Calling this function with a single argument is equivalent to calling
-
error(arg: any)
error(format_string: str, *args: any) -
A convenience function for writing an
ERRORmessage to the standard output stream.-
Calling this function with a single argument is equivalent to calling
$str()on that argument first and logging the resulting string. -
Calling this function with more than one argument is equivalent to calling
$fmt()on those arguments first and logging the resulting string.
-
Calling this function with a single argument is equivalent to calling
-
fatal(arg: any)
fatal(format_string: str, *args: any) -
A convenience function for writing a
FATALmessage to the standard output stream.Calling this function will write the log message, then cause the program to exit with a non-zero status code.
-
Calling this function with a single argument is equivalent to calling
$str()on that argument first and logging the resulting string. -
Calling this function with more than one argument is equivalent to calling
$fmt()on those arguments first and logging the resulting string.
-
Calling this function with a single argument is equivalent to calling
-
info(arg: any)
info(format_string: str, *args: any) -
A convenience function for writing an
INFOmessage to the standard output stream.-
Calling this function with a single argument is equivalent to calling
$str()on that argument first and logging the resulting string. -
Calling this function with more than one argument is equivalent to calling
$fmt()on those arguments first and logging the resulting string.
-
Calling this function with a single argument is equivalent to calling
-
warn(arg: any)
warn(format_string: str, *args: any) -
A convenience function for writing a
WARNmessage to the standard output stream.-
Calling this function with a single argument is equivalent to calling
$str()on that argument first and logging the resulting string. -
Calling this function with more than one argument is equivalent to calling
$fmt()on those arguments first and logging the resulting string.
-
Calling this function with a single argument is equivalent to calling
Classes
-
Logger() -> Logger -
Returns a new
Loggerinstance.- Messages will only be logged if their logging-level is greater than or equal to the logger's logging-level.
-
The logger's default logging-level is
Level::Info.
Logger instances have the following public fields:
class Logger { # The logger's logging-level. pub var logging_level: Level = Level::Info; # The logger's output file. pub var output_file: file = $stdout; # Set to true to show milliseconds in timestamps. pub var show_milliseconds: bool = false; # Set to true to show microseconds in timestamps. pub var show_microseconds: bool = false; # Set to true to use UTC instead of local time. pub var show_utc: bool = false; # Set to true to show the timezone offset. pub var show_tz_offset: bool = false; }
Logger instances have the following methods:
-
:debug(arg: any)
:debug(format_string: str, *args: any) -
Writes a
DEBUGmessage to the logger's output file.-
Calling this method with a single argument is equivalent to calling
$str()on that argument first and logging the resulting string. -
Calling this method with more than one argument is equivalent to calling
$fmt()on those arguments first and logging the resulting string.
-
Calling this method with a single argument is equivalent to calling
-
:error(arg: any)
:error(format_string: str, *args: any) -
Writes an
ERRORmessage to the logger's output file.-
Calling this method with a single argument is equivalent to calling
$str()on that argument first and logging the resulting string. -
Calling this method with more than one argument is equivalent to calling
$fmt()on those arguments first and logging the resulting string.
-
Calling this method with a single argument is equivalent to calling
-
:fatal(arg: any)
:fatal(format_string: str, *args: any) -
Writes a
FATALmessage to the logger's output file.Calling this method will write the log message, then cause the program to exit with a non-zero status code.
-
Calling this method with a single argument is equivalent to calling
$str()on that argument first and logging the resulting string. -
Calling this method with more than one argument is equivalent to calling
$fmt()on those arguments first and logging the resulting string.
-
Calling this method with a single argument is equivalent to calling
-
:info(arg: any)
:info(format_string: str, *args: any) -
Writes an
INFOmessage to the logger's output file.-
Calling this method with a single argument is equivalent to calling
$str()on that argument first and logging the resulting string. -
Calling this method with more than one argument is equivalent to calling
$fmt()on those arguments first and logging the resulting string.
-
Calling this method with a single argument is equivalent to calling
-
:warn(arg: any)
:warn(format_string: str, *args: any) -
Writes a
WARNmessage to the logger's output file.-
Calling this method with a single argument is equivalent to calling
$str()on that argument first and logging the resulting string. -
Calling this method with more than one argument is equivalent to calling
$fmt()on those arguments first and logging the resulting string.
-
Calling this method with a single argument is equivalent to calling