{"id":16715474,"url":"https://github.com/fable-hub/Fable.Logging","last_synced_at":"2026-05-28T10:04:18.480Z","repository":{"id":59535736,"uuid":"536711379","full_name":"dbrattli/Fable.Logging","owner":"dbrattli","description":"Logging framework for Fable","archived":false,"fork":false,"pushed_at":"2022-10-08T07:50:22.000Z","size":45,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-21T23:41:26.713Z","etag":null,"topics":["fable","fsharp","logging","python"],"latest_commit_sha":null,"homepage":"","language":"F#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dbrattli.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-09-14T18:29:47.000Z","updated_at":"2022-09-24T22:07:13.000Z","dependencies_parsed_at":"2023-01-19T15:01:33.418Z","dependency_job_id":null,"html_url":"https://github.com/dbrattli/Fable.Logging","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dbrattli%2FFable.Logging","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dbrattli%2FFable.Logging/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dbrattli%2FFable.Logging/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dbrattli%2FFable.Logging/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dbrattli","download_url":"https://codeload.github.com/dbrattli/Fable.Logging/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243707308,"owners_count":20334615,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fable","fsharp","logging","python"],"created_at":"2024-10-12T21:09:31.141Z","updated_at":"2026-05-28T10:04:18.475Z","avatar_url":"https://github.com/dbrattli.png","language":"F#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fable.Logging\n\nA cross-platform logging framework for [Fable](https://fable.io). It mirrors the\n.NET [Microsoft.Extensions.Logging](https://learn.microsoft.com/en-us/dotnet/core/extensions/logging)\npattern with `ILogger`, `ILoggerFactory`, and `ILoggerProvider` interfaces, letting you\nwrite idiomatic logging code in F# that works across JavaScript, Python, and Erlang/BEAM.\n\n## Packages\n\n| Package | NuGet | Description |\n|---------|-------|-------------|\n| `Fable.Logging` | [![NuGet](https://img.shields.io/nuget/v/Fable.Logging.svg)](https://www.nuget.org/packages/Fable.Logging) | Core interfaces, LoggerFactory, ConsoleLogger, JS console logger |\n| `Fable.Logging.Structlog` | [![NuGet](https://img.shields.io/nuget/v/Fable.Logging.Structlog.svg)](https://www.nuget.org/packages/Fable.Logging.Structlog) | Python [structlog](https://www.structlog.org/) provider |\n| `Fable.Logging.Beam` | [![NuGet](https://img.shields.io/nuget/v/Fable.Logging.Beam.svg)](https://www.nuget.org/packages/Fable.Logging.Beam) | Erlang/OTP logger provider |\n\n## Quick Start\n\nCreate a logger factory, configure it with providers, and start logging:\n\n```fsharp\nopen Fable.Logging\n\nlet factory =\n    LoggerFactory.Create(fun builder -\u003e\n        builder.AddProvider(ConsoleLoggerProvider())\n        builder.SetMinimumLevel(LogLevel.Debug))\n\nlet logger = factory.CreateLogger(\"MyApp.Service\")\n\nlogger.LogInformation(\"Application started\")\nlogger.LogDebug(\"Processing request for {UserId}\", box 42)\nlogger.LogError(\"Something went wrong\")\n```\n\n## Platform-Specific Providers\n\n### JavaScript (console)\n\nThe built-in JS logger maps log levels to the appropriate `console.*` methods\n(`console.debug`, `console.info`, `console.warn`, `console.error`).\n\n```fsharp\nopen Fable.Logging\nopen Fable.Logging.JS\n\nlet factory =\n    LoggerFactory.Create(fun builder -\u003e\n        builder.AddProvider(LoggerProvider()))\n\nlet logger = factory.CreateLogger(\"MyApp\")\nlogger.LogInformation(\"Hello from {Platform}!\", box \"JavaScript\")\n```\n\n### Python (structlog)\n\nUses [structlog](https://www.structlog.org/) for structured logging with support for\nboth console and JSON output.\n\n```fsharp\nopen Fable.Logging\nopen Fable.Logging.Structlog\n\n// Console output (human-readable)\nlet factory =\n    LoggerFactory.Create(fun builder -\u003e\n        builder.AddProvider(ConsoleLoggerProvider()))\n\n// JSON output (machine-readable)\nlet jsonFactory =\n    LoggerFactory.Create(fun builder -\u003e\n        builder.AddProvider(JsonLoggerProvider()))\n\nlet logger = factory.CreateLogger(\"MyApp\")\nlogger.LogInformation(\"User {Name} logged in\", box \"Alice\")\n```\n\n### Erlang/BEAM (OTP logger)\n\nBridges to the OTP `logger` module for applications targeting the BEAM runtime.\n\n```fsharp\nopen Fable.Logging\nopen Fable.Logging.Beam\n\nlet factory =\n    LoggerFactory.Create(fun builder -\u003e\n        builder.AddProvider(LoggerProvider()))\n\nlet logger = factory.CreateLogger(\"MyApp\")\nlogger.LogWarning(\"Connection pool running low: {Available} remaining\", box 3)\n```\n\n## Log Levels\n\nLog levels match the .NET `LogLevel` enum:\n\n| Level | Value | Method | Description |\n|-------|-------|--------|-------------|\n| Trace | 0 | `LogTrace` | Most detailed messages, may contain sensitive data |\n| Debug | 1 | `LogDebug` | Debugging and development |\n| Information | 2 | `LogInformation` | General flow of the application |\n| Warning | 3 | `LogWarning` | Abnormal or unexpected events |\n| Error | 4 | `LogError` | Errors and exceptions |\n| Critical | 5 | `LogCritical` | Failures requiring immediate attention |\n| None | 6 | | Suppresses all logging |\n\n## Filtering\n\nSet a minimum log level to filter out less severe messages:\n\n```fsharp\nlet factory =\n    LoggerFactory.Create(fun builder -\u003e\n        builder.AddProvider(ConsoleLoggerProvider())\n        builder.SetMinimumLevel(LogLevel.Warning))\n\nlet logger = factory.CreateLogger(\"MyApp\")\nlogger.LogDebug(\"This is filtered out\")\nlogger.LogWarning(\"This is logged\")\n```\n\n## Message Templates\n\nUse named placeholders in log messages for structured logging. The placeholder names\nbecome keys in the structured log output, while values are substituted positionally:\n\n```fsharp\nlogger.LogInformation(\"Order {OrderId} placed by {Customer}\", box 1234, box \"Alice\")\n// Output: MyApp - Order 1234 placed by Alice\n```\n\n## Logging Exceptions\n\n```fsharp\ntry\n    failwith \"Something broke\"\nwith ex -\u003e\n    logger.LogError(\"Operation failed\", ex)\n```\n\n## Multiple Providers\n\nThe factory dispatches log messages to all registered providers:\n\n```fsharp\nlet factory =\n    LoggerFactory.Create(fun builder -\u003e\n        builder.AddProvider(consoleProvider)\n        builder.AddProvider(jsonProvider))\n\n// Messages are sent to both providers\nlet logger = factory.CreateLogger(\"MyApp\")\nlogger.LogInformation(\"This goes to all providers\")\n```\n\n## Writing a Custom Provider\n\nImplement `ILoggerProvider` and `ILogger` to create your own logging backend:\n\n```fsharp\nopen Fable.Logging\n\ntype MyLogger(name: string) =\n    interface ILogger with\n        member _.Log(state: LogState) =\n            printfn \"[%A] %s: %s\" state.Level name state.Format\n\n        member _.IsEnabled(logLevel: LogLevel) = true\n        member _.BeginScope(_) = failwith \"Not implemented\"\n\ntype MyLoggerProvider() =\n    interface ILoggerProvider with\n        member _.CreateLogger(name) = MyLogger(name)\n        member _.Dispose() = ()\n```\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffable-hub%2FFable.Logging","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffable-hub%2FFable.Logging","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffable-hub%2FFable.Logging/lists"}