{"id":15450180,"url":"https://github.com/iand/logfmtr","last_synced_at":"2025-04-19T22:50:10.240Z","repository":{"id":43081935,"uuid":"284054406","full_name":"iand/logfmtr","owner":"iand","description":"An implementation of the logr minimal logging API that writes in logfmt style.","archived":false,"fork":false,"pushed_at":"2023-12-11T10:35:33.000Z","size":62,"stargazers_count":10,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-13T19:22:57.159Z","etag":null,"topics":["go","golang","logfmt","logging","structured-logging"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iand.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-31T14:22:53.000Z","updated_at":"2023-03-03T13:27:43.000Z","dependencies_parsed_at":"2023-12-11T11:50:03.270Z","dependency_job_id":null,"html_url":"https://github.com/iand/logfmtr","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/iand%2Flogfmtr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iand%2Flogfmtr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iand%2Flogfmtr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iand%2Flogfmtr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iand","download_url":"https://codeload.github.com/iand/logfmtr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249824094,"owners_count":21330263,"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":["go","golang","logfmt","logging","structured-logging"],"created_at":"2024-10-01T21:03:42.554Z","updated_at":"2025-04-19T22:50:10.215Z","avatar_url":"https://github.com/iand.png","language":"Go","readme":"# logfmtr\n\nAn implementation of the [logr minimal logging API](https://github.com/go-logr/logr) that writes in [logfmt](https://www.brandur.org/logfmt) style.\n\n[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go\u0026logoColor=white)](https://pkg.go.dev/github.com/iand/logfmtr)\n[![Check Status](https://github.com/iand/logfmtr/actions/workflows/check.yml/badge.svg)](https://github.com/iand/logfmtr/actions/workflows/check.yml)\n[![Test Status](https://github.com/iand/logfmtr/actions/workflows/test.yml/badge.svg)](https://github.com/iand/logfmtr/actions/workflows/test.yml)\n\n\n## Getting Started\n\nThis is a no frills logging package that follows the [logr minimal logging API](https://github.com/go-logr/logr) \nand by default writes logs in [logfmt](https://www.brandur.org/logfmt) format, a line of space delimited\nkey/value pairs.\n\n```\nlevel=0 logger=MyName ts=2020-09-20T14:31:10.905267839Z msg=hello user=you val1=1 val2=map[k:1]\nlevel=1 logger=MyName ts=2020-09-20T14:31:10.905279546Z msg=\"you should see this\" user=you\nlevel=0 logger=MyName ts=2020-09-20T14:31:10.905288008Z msg=\"uh oh\" error=\u003cnil\u003e user=you trouble=true reasons=\"[0.1 0.11 3.14]\"\nlevel=0 logger=MyName ts=2020-09-20T14:31:10.905291479Z msg=goodbye error=\"an error occurred\" user=you code=-1\n```\n\nA more human friendly output format is also provided which can be configured using the `humanize` option:\n\n```\n0 info  | 14:31:10.905297 | hello                          logger=MyName user=you val1=1 val2=map[k:1]\n1 info  | 14:31:10.905302 | you should see this            logger=MyName user=you\n0 error | 14:31:10.905307 | uh oh                          logger=MyName error=\u003cnil\u003e user=you trouble=true reasons=\"[0.1 0.11 3.14]\"\n0 error | 14:31:10.905311 | goodbye                        logger=MyName error=\"an error occurred\" user=you code=-1\n```\n\nLoggers defer applying their configuration until they are used. The logger is instantiated when\neither Info, Error or Enabled is called. At that point the logger will read and use any options set\nfrom a prior call to UseOptions. \n\n\n```Go\npackage main\n\nimport (\n    \"github.com/iand/logfmtr\"\n)\n\nfunc main() {\n    // Set options that all loggers will be based on\n    opts := logfmtr.DefaultOptions()\n    opts.Humanize = true\n    opts.AddCaller = true\n    logfmtr.UseOptions(opts)\n}\n\n```\n\nAny new loggers will use the options set in `main` when they first start logging.\n\n```Go\npackage worker\n\nimport (\n    \"github.com/iand/logfmtr\"\n)\n\n// Create the logger\nvar logger = logfmtr.New().WithName(\"worker\")\n\n\nfunc doWork() }\n    // Logger is instantiated with the options set earlier\n    logger.Info(\"the sun is shining\")\n}\n```\n\nLoggers can be created with specific configuration by using `NewWithOptions`:\n\n```Go\nfunc otherWork() }\n    opts := logfmtr.DefaultOptions()\n    opts.Writer = os.Stderr\n\n    logger := logfmtr.NewWithOptions(opts)\n    logger.Info(\"important system information\")\n}\n```\n\nSeveral predefined keys are used when writing logs in logfmt style:\n\n * **msg** - the log message\n * **error** - error message passed to the `Error` method\n * **logger** - the name of the logger writing the log entry\n * **level** - the verbosity level of the logger writing the log entry\n * **caller** - filename and line number of the origin of the log entry\n\n## Author\n\n* [Ian Davis](http://github.com/iand) - \u003chttp://iandavis.com/\u003e\n\n## License\n\nThis is free and unencumbered software released into the public domain. Anyone is free to \ncopy, modify, publish, use, compile, sell, or distribute this software, either in source \ncode form or as a compiled binary, for any purpose, commercial or non-commercial, and by \nany means. For more information, see \u003chttp://unlicense.org/\u003e or the \naccompanying [`UNLICENSE`](UNLICENSE) file.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiand%2Flogfmtr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiand%2Flogfmtr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiand%2Flogfmtr/lists"}