{"id":17088627,"url":"https://github.com/jship/monad-logger-aeson","last_synced_at":"2026-05-25T09:30:21.172Z","repository":{"id":37055063,"uuid":"487688876","full_name":"jship/monad-logger-aeson","owner":"jship","description":"JSON logging using monad-logger interface","archived":false,"fork":false,"pushed_at":"2023-12-10T15:10:44.000Z","size":195,"stargazers_count":14,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-03-06T18:24:28.885Z","etag":null,"topics":["aeson","json","logging","structured-logging"],"latest_commit_sha":null,"homepage":"","language":"Haskell","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/jship.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2022-05-02T01:56:27.000Z","updated_at":"2023-11-28T11:37:47.000Z","dependencies_parsed_at":"2023-12-10T15:48:51.898Z","dependency_job_id":null,"html_url":"https://github.com/jship/monad-logger-aeson","commit_stats":{"total_commits":94,"total_committers":2,"mean_commits":47.0,"dds":0.05319148936170215,"last_synced_commit":"139ea041f96439387c978850e917b5bd974c2510"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jship%2Fmonad-logger-aeson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jship%2Fmonad-logger-aeson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jship%2Fmonad-logger-aeson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jship%2Fmonad-logger-aeson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jship","download_url":"https://codeload.github.com/jship/monad-logger-aeson/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219847295,"owners_count":16556405,"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":["aeson","json","logging","structured-logging"],"created_at":"2024-10-14T13:38:12.937Z","updated_at":"2026-05-25T09:30:19.111Z","avatar_url":"https://github.com/jship.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [monad-logger-aeson][]\n\n[![Build badge][]][build]\n[![Version badge][]][version]\n\n## Synopsis\n\n`monad-logger-aeson` provides structured JSON logging using `monad-logger`'s\ninterface. Specifically, it is intended to be a (largely) drop-in replacement\nfor `monad-logger`'s `Control.Monad.Logger.CallStack` module.\n\nFor additional detail on the library, please see the [Haddocks][], the\n[announcement blog post][], and the remainder of this README.\n\n## Crash course\n\nAssuming we have the following `monad-logger`-based code:\n\n```haskell\n{-# LANGUAGE BlockArguments #-}\n{-# LANGUAGE OverloadedStrings #-}\nmodule Main\n  ( main\n  ) where\n\nimport Control.Monad.Logger.CallStack\nimport Data.Text (pack)\n\ndoStuff :: (MonadLogger m) =\u003e Int -\u003e m ()\ndoStuff x = do\n  logDebug $ \"Doing stuff: x=\" \u003c\u003e pack (show x)\n\nmain :: IO ()\nmain = do\n  runStdoutLoggingT do\n    doStuff 42\n    logInfo \"Done\"\n```\n\nWe would get something like this log output:\n\n```text\n[Debug] Doing stuff: x=42 @(main:Main app/readme-example.hs:12:3)\n[Info] Done @(main:Main app/readme-example.hs:18:5)\n```\n\nWe can change our import from this:\n\n```haskell\nimport Control.Monad.Logger.CallStack\n```\n\nTo this:\n\n```haskell\nimport Control.Monad.Logger.Aeson\n```\n\nIn changing the import, we'll have one compiler error to address:\n\n```text\nmonad-logger-aeson/app/readme-example.hs:12:35: error:\n    • Couldn't match expected type ‘Message’\n                  with actual type ‘Data.Text.Internal.Text’\n    • In the second argument of ‘(\u003c\u003e)’, namely ‘pack (show x)’\n      In the second argument of ‘($)’, namely\n        ‘\"Doing stuff: x=\" \u003c\u003e pack (show x)’\n      In a stmt of a 'do' block:\n        logDebug $ \"Doing stuff: x=\" \u003c\u003e pack (show x)\n   |\n12 |   logDebug $ \"Doing stuff: x=\" \u003c\u003e pack (show x)\n   |\n```\n\nThis indicates that we need to provide the `logDebug` call a `Message` rather\nthan a `Text` value. This compiler error gives us a choice depending upon our\ncurrent time constraints: we can either go ahead and convert this `Text` value\nto a \"proper\" `Message` by moving the metadata it encodes into structured data\n(i.e.  a `[Series]` value, where `Series` is an `aeson` key and encoded value),\nor we can defer doing that for now by tacking on an empty `[Series]` value.\nWe'll opt for the former here:\n\n```haskell\nlogDebug $ \"Doing stuff\" :# [\"x\" .= x]\n```\n\nNote that the `logInfo` call did not give us a compiler error, as `Message` has\nan `IsString` instance.\n\nOur log output now looks like this (formatted for readability here with `jq`):\n\n```jsonl\n{\n  \"time\": \"2022-05-15T20:52:15.5559417Z\",\n  \"level\": \"debug\",\n  \"location\": {\n    \"package\": \"main\",\n    \"module\": \"Main\",\n    \"file\": \"app/readme-example.hs\",\n    \"line\": 11,\n    \"char\": 3\n  },\n  \"message\": {\n    \"text\": \"Doing stuff\",\n    \"meta\": {\n      \"x\": 42\n    }\n  }\n}\n{\n  \"time\": \"2022-05-15T20:52:15.5560448Z\",\n  \"level\": \"info\",\n  \"location\": {\n    \"package\": \"main\",\n    \"module\": \"Main\",\n    \"file\": \"app/readme-example.hs\",\n    \"line\": 17,\n    \"char\": 5\n  },\n  \"message\": {\n    \"text\": \"Done\"\n  }\n}\n```\n\nVoilà! Now our Haskell code is using structured logging. Our logs are fit for\nparsing, ingestion into our log aggregation/analysis service of choice, etc.\n\n## Goals\n\nThe following goals have underpinned the development of `monad-logger-aeson`:\n\n1. Structured logging _must_ be easy to add to existing Haskell codebases\n1. Structured logging _should_ be performant\n\nWe believe we have achieved goal 1 by targeting `monad-logger`'s\n`MonadLogger`/`LoggingT` interface. There are many interesting logging libraries\nto choose from in Haskell: `monad-logger`, `di`, `logging-effect`, `katip`, and\nso on. Both by comparing the [reverse dependency list][] for `monad-logger` with\nthe other logging libraries' reverse dependency lists, and also consulting our\npersonal experiences working on Haskell codebases, `monad-logger` would seem to\nbe the most prevalent logging library in the wild. In developing our library as\na (largely) drop-in replacement for `monad-logger`, we hope to empower\nHaskellers using this popular logging interface to add structured logging to\ntheir programs with minimal fuss.\n\nWe believe we have achieved goal 2 by directly representing in-flight `Message`\nvalues using a fixed `aeson` object `Encoding`, by never (internally) converting\nanything to intermediate `Value`s, and by never parsing these in-flight log\nmessages when assembling the final logged message. Regarding the latter point,\nwe need to know the origin of an input `LogStr` (i.e. is it from\n`monad-logger-aeson` or not?). If we know an input `LogStr` came from\n`monad-logger-aeson`, then we know the `LogStr` is an `aeson` object `Encoding`\nof a `Message`, and so we can pass this encoding along untouched as a piece of\nthe final log message's encoding. If we know an input `LogStr` did not come from\n`monad-logger-aeson`, then we can scoop this `LogStr` up into a text-only\n`Message`, encode that, and pass the encoding along as a piece of the final log\nmessage's encoding. A straightforward and relatively expensive implementation of\ndetermining a `LogStr`'s origin would involve parsing of in-flight log messages\nback into `Message` values. Rather than resort to parsing _every_ in-flight\nmessage, we simply check the first 9 characters of the `LogStr` for a match with\n`{\"text\":\"`. Yes, there is the possibility that a `monad-logger` user logs out a\n`LogStr` with this same prefix and that `LogStr` makes its way into a\n`monad-logger-aeson` user's `LoggingT` runner function.  This would cause\n`monad-logger-aeson` to erroneously assume the message's origin is\n`monad-logger-aeson`. We feel this possibility is overall unlikely, and have\naccepted this as a tradeoff in the design space of the library. While we believe\nthe principles described previously should provide good performance, please note\nthat benchmarks do not yet exist for this library.  Caveat emptor!\n\n[monad-logger-aeson]: https://github.com/jship/monad-logger-aeson\n[Build badge]: https://github.com/jship/monad-logger-aeson/workflows/CI/badge.svg\n[build]: https://github.com/jship/monad-logger-aeson/actions\n[Version badge]: https://img.shields.io/hackage/v/monad-logger-aeson?color=brightgreen\u0026label=version\u0026logo=haskell\n[version]: https://hackage.haskell.org/package/monad-logger-aeson\n[Haddocks]: https://hackage.haskell.org/package/monad-logger-aeson\n[announcement blog post]: https://jship.github.io/posts/2022-05-17-announcing-monad-logger-aeson/\n[reverse dependency list]: https://packdeps.haskellers.com/reverse/monad-logger\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjship%2Fmonad-logger-aeson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjship%2Fmonad-logger-aeson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjship%2Fmonad-logger-aeson/lists"}