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.
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 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: 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, logger will dump messages in file every 5 seconds
by defaults. flush allows to choose how long to wait before dumping
messages in the file. Be careful, setting a too small interval could lead to
performance issues, because BEAM will spend too much time in file writing.
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.