std::log
A simple logging library. Logging levels, in increasing order of severity, are:
-
DEBUG
-
INFO
-
WARN
-
ERROR
-
FATAL
A set of convenience functions are available for logging to the standard error stream.
Use a Logger
instance to customize the timestamp format and destination file.
Constants
-
DEBUG: i64
-
Log-level
DEBUG
. -
ERROR: i64
-
Log-level
ERROR
. -
FATAL: i64
-
Log-level
FATAL
. -
INFO: i64
-
Log-level
INFO
. -
WARN: i64
-
Log-level
WARN
.
Functions
-
debug(arg: any)
debug(format_string: str, *args: any)
-
A convenience function for writing a
DEBUG
log message to the standard error 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
ERROR
log message to the standard error 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
FATAL
log message to the standard error stream.This will 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
INFO
log message to the standard error 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
WARN
log message to the standard error 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
-
Initializes a new
Logger
instance.-
By default, a
Logger
logs to the standard error stream. -
The default logging level is
INFO
. -
The default timestamp format is
"[%Y-%m-%d %H:%M:%S]"
.
-
By default, a
Logger
instances support the following methods:
-
:debug(arg: any)
:debug(format_string: str, *args: any)
-
Writes a
DEBUG
level log message 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
ERROR
level log message 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
FATAL
level log message to the logger's output file.This will 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
-
:file(output_file: file)
-
Sets the logger's output file. The default output file is the standard error stream.
-
:info(arg: any)
:info(format_string: str, *args: any)
-
Writes an
INFO
level log message 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
-
:level(log_level: i64)
-
Sets the logging level. Messages will only be logged if their level is greater than or equal to this logging level.
The default logging level is
INFO
. -
:timestamp(format_string: str)
-
Sets the timestamp format for the logger. The default format string is
"%Y-%m-%d %H:%M:%S"
.The format string can include any format specifiers supported by the C standard library's
strftime()
function. -
:warn(arg: any)
:warn(format_string: str, *args: any)
-
Writes a
WARN
level log message 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