palabres/options
Options to configure Palabres at start.
import palabres
import palabres/level
import palabres/options
pub fn configure_logger() {
options.defaults()
// Enables or disable colored output.
|> options.color(True)
// Enables or disable JSON output. JSON output will never be colored.
|> options.json(False)
// Set the minimum log level.
|> options.level(level.Info)
// Output to a file instead of stdout.
|> options.output(to: {
options.file(test_utils.log_file)
|> options.flush(every: 5000)
})
// Applies or not palabres styling to default logger (on stdout).
|> options.style_default_logger(True)
// Configure the logger.
|> palabres.configure
}
Types
Options to configure the logger. To create with defaults.
Below are the configurable options, usable with the corresponding functions.
colorDefaults toTrue.
Allow to choose if the output is colored or not.
Can be deactivated globally with theNO_COLOR(orNO_COLOUR) environment variable.
Once set,colordefaults toFalse.jsonDefaults toFalse.
Activate the JSON mode, forcing the logger to output JSON instead of strings.
JSON output will automatically disable colored logging.levelDefaults tolevel.Info.
Set the minimum required log level.
Every level below will be ignored.outputDefaults tostdout.
Allow to choose writing tostdoutor a file.style_default_loggerDefaults toTrue.
Apply the palabres styling to the default logger.auto_atDefaults toTrue.
Automatically fill theatfield with the module and function creating the log.auto_whenDefaults toTrue.
Automatically fill thewhenfield with the timestamp of the log.
pub opaque type Options
Configurable output for the logger. Can be the standard output, or a
selected file.
Standard output can be simply selected with stdout, while file
logging is selected with file.
A file logger will dump the log contents at regular interval. This interval
is configurable by using flush.
pub fn configure_logger() {
options.defaults()
// Choose to output to stdout.
|> options.output(to: options.stdout())
// Choose to output to a file.
|> options.output(to: {
options.file("/var/log/my_app.log")
// Flush interval can be seldected in milliseconds.
|> options.flush(every: 2500)
})
}
pub opaque type Output
Values
pub fn auto_at(options: Options, enabled: Bool) -> Options
Defaults to True.
Activate or deactivate the automatic at field. When activated, every log
is tagged with the module and the function it has been created in, unless
palabres.at overrides it.
Locating a log requires inspecting the call stack, which is cheap but not
free. Deactivate it on hot paths if every microsecond matters.
pub fn auto_when(options: Options, enabled: Bool) -> Options
Defaults to True.
Activate or deactivate the automatic when field, holding the timestamp of
the log in ISO 8601 format. Deactivate it when your log collector adds its
own timestamp, like journald or most cloud log processors, to avoid
paying twice for the same information.
pub fn color(options: Options, color: Bool) -> Options
Activate or deactivate colored output.
Defaults to True if environment variable NO_COLOR is unset.
Defaults to False otherwise.
If color is called, it takes precedence on environment variable.
pub fn defaults() -> Options
Initialise the options with defaults.
color: Trueif environment variableNO_COLORis unset,Falseotherwise.json: Falselevel: level.Infooutput: stdoutstyle_default_logger: Trueauto_at: Trueauto_when: True
pub fn file(filename: String) -> Output
Creates a file output, to use with output. Flush interval can be configured
with flush.
pub fn flush(file: Output, every interval: Int) -> Output
When outputting to a file on Erlang, logger will sync the file every 5
seconds by default. flush allows to choose how long to wait between two
syncs. Be careful, setting a too small interval could lead to performance
issues, because BEAM will spend too much time in file writing.
Has no effect on JavaScript, where logs are written to the file as they
come, through a single stream kept open by the logger.
pub fn json(options: Options, json: Bool) -> Options
Defaults to False.
Activate or deactive JSON ouput.
If activated, colored output is automatically deactivated.
pub fn level(options: Options, level: level.Level) -> Options
Defaults to level.Info. Set the minimum desired log level.
pub fn output(options: Options, to output: Output) -> Options
Defaults to stdout. Choose the desired output.