Library for Logging to the terminal. It logs to the stdout or stderr based on used function. I has colorful output.
Add following into paket.references
Alma.Logging
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")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="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. |
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"
]
]- https://www.tutorialsteacher.com/core/fundamentals-of-logging-in-dotnet-core
- https://benfoster.io/blog/serilog-best-practices/
- Increment version in
Logging.fsproj - Update
CHANGELOG.md - Commit new version and tag it
./build.sh build./build.sh -t tests