Skip to content

alma-oss/flogging

Repository files navigation

F-Logging

NuGet NuGet Downloads Tests

Library for Logging to the terminal. It logs to the stdout or stderr based on used function. I has colorful output.

Install

Add following into paket.references

Alma.Logging

Usage

open Alma.Logging

use factory = LoggerFactory.create [
    UseLevel LogLevel.Trace

    LogToConsole

    LogToSerilog [
        SerilogOption.LogToConsole
        SerilogOption.LogToConsoleAsJson

        AddMeta ("domain", "domain")
        AddMeta ("context", "context")
        AddMeta ("purpose", "purpose")
        AddMeta ("version", "version")
    ]
]

let logger = factory.CreateLogger("Example")

logger.LogTrace("{Level} message", "Trace")

Configure from environment variables

Log output from environment variables

You can add dynamic option LogToFromEnvironment with name of a environment variable, which will be used to determine the output of the logs. You can add multiple values, separated by ; (you can add spaces for readability).

# log to console (multiple options to set up)
LOG_TO="console"
LOG_TO="stdout"

# log to console as json (multiple options to set up)
LOG_TO="console-json"
LOG_TO="json"

# log to both console AND to console as json
LOG_TO="console; json"
LoggerFactory.create [
    LogToFromEnvironment "LOG_TO"
]

Log level from environment variables

LOG_LEVEL="debug"
LoggerFactory.create [
    UseLevelFromEnvironment "LOG_LEVEL"
]

Log level is parsed based on following table:

Final level Options Description
LogLevel.Trace "trace", "vvv" Logs that contain the most detailed messages. These messages may contain sensitive application data. These messages are disabled by default and should never be enabled in a production environment.
LogLevel.Debug "debug", "vv" Logs that are used for interactive investigation during development. These logs should primarily contain information useful for debugging and have no long-term value.
LogLevel.Information "information", "v", "normal" Logs that track the general flow of the application. These logs should have long-term value.
LogLevel.Warning "warning" Logs that highlight an abnormal or unexpected event in the application flow, but do not otherwise cause the application execution to stop.
LogLevel.Error "error" Logs that highlight when the current flow of execution is stopped due to a failure. These should indicate a failure in the current activity, not an application-wide failure.
LogLevel.Critical "critical" Logs that describe an unrecoverable application or system crash, or a catastrophic failure that requires immediate attention.
LogLevel.None "quiet", "q", _anything else_ Not used for writing log messages. Specifies that a logging category should not write any messages.

Add metadata to Serilog by environment variables

This is useful if you have library which uses a logger factory inside

LOG_META="domain:tearoom; context:menu"
LoggerFactory.create [
    LogToSerilog [
        AddMetaFromEnvironment "LOG_META"
    ]
]

Useful links

Release

  1. Increment version in Logging.fsproj
  2. Update CHANGELOG.md
  3. Commit new version and tag it

Development

Requirements

Build

./build.sh build

Tests

./build.sh -t tests

About

Library for Logging to the terminal. It logs to the stdout or stderr based on used function.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors