{"id":17362472,"url":"https://github.com/akasprzok/logfmt_ex","last_synced_at":"2025-08-08T06:03:35.021Z","repository":{"id":37103835,"uuid":"494613151","full_name":"akasprzok/logfmt_ex","owner":"akasprzok","description":"A logfmt log formatter for Elixir.","archived":false,"fork":false,"pushed_at":"2024-05-10T01:08:05.000Z","size":90,"stargazers_count":26,"open_issues_count":6,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-12T18:51:01.852Z","etag":null,"topics":["elixir","logging"],"latest_commit_sha":null,"homepage":"","language":"Elixir","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/akasprzok.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2022-05-20T21:38:36.000Z","updated_at":"2025-03-16T07:18:48.000Z","dependencies_parsed_at":"2024-10-31T02:02:33.724Z","dependency_job_id":null,"html_url":"https://github.com/akasprzok/logfmt_ex","commit_stats":{"total_commits":80,"total_committers":3,"mean_commits":"26.666666666666668","dds":"0.13749999999999996","last_synced_commit":"9f3a8983f069a57ad672931f8e01eb116d412949"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/akasprzok/logfmt_ex","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akasprzok%2Flogfmt_ex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akasprzok%2Flogfmt_ex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akasprzok%2Flogfmt_ex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akasprzok%2Flogfmt_ex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akasprzok","download_url":"https://codeload.github.com/akasprzok/logfmt_ex/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akasprzok%2Flogfmt_ex/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269373108,"owners_count":24406320,"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","status":"online","status_checked_at":"2025-08-08T02:00:09.200Z","response_time":72,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["elixir","logging"],"created_at":"2024-10-15T19:38:36.513Z","updated_at":"2025-08-08T06:03:34.970Z","avatar_url":"https://github.com/akasprzok.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"![main](https://github.com/akasprzok/logfmt_ex/actions/workflows/main.yml/badge.svg?branch=main)\n[![Hex](https://img.shields.io/hexpm/v/logfmt_ex.svg)](https://hex.pm/packages/logfmt_ex/)\n[![Hex Docs](https://img.shields.io/badge/hex-docs-informational.svg)](https://hexdocs.pm/logfmt_ex/)\n![License](https://img.shields.io/hexpm/l/logfmt_ex)\n[![Coverage Status](https://coveralls.io/repos/github/akasprzok/logfmt_ex/badge.svg?branch=main)](https://coveralls.io/github/akasprzok/logfmt_ex?branch=main)\n\n# LogfmtEx\n\nA log formatter for the logfmt format popularized by Heroku.\n\n\n```elixir\nLogger.info(\"I am a message\", user_id: 123)\n```\n```\nlevel=info msg=\"I am a message\" ts=\"12:38:38.055 1973-03-12\" user_id=123 pid=#PID\u003c0.223.0\u003e file=test/logfmt_ex_test.exs\n```\n\n## Installation\n\nThe package can be installed\nby adding `logfmt_ex` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:logfmt_ex, \"~\u003e 0.4\"}\n  ]\nend\n```\n\nIn your app's logger configuration, specify the `LogfmtEx` module and its `format` function to be used to format your logs:\n\n```elixir\nconfig :logger, :console,\n  format: {LogfmtEx, :format}\n```\n\nYou can customize the formatting in your config:\n\n```elixir\nconfig :logfmt_ex, :opts,\n  message_key: \"msg\",\n  timestamp_key: \"ts\",\n  timestamp_format: :iso8601\n```\n\n## Configuration\n\n* `:delimiter` - defaults to `=`.\n* `:format` - A list of atoms that defines the order in which key/value pairs will written to the log line. Defaults to `[:timestamp, :level, :message, :metadata]`. Valid parameters are\n  * `:timestamp` - the timestamp of the log message\n  * `:level` - the log level\n  * `:message` - the log message itself\n  * `:metadata` - metadata as key=value paris\n  * `:node` - the node name\n* `timestamp_key` - changes the key used for the timestamp field. Defaults to `timestamp`.\n* `timestamp_format` - How the timestamp is formatted. Defaults to `:elixir`. The options are\n  * `:elixir` - Uses the same formatting functions found in the standard elixir log formatter. Example: `\"12:38:38.055 1973-03-12\"`\n  * `:epoch_seconds` - outputs an integer representing the number of seconds elapsed since January 1, 1970. Only useful for applications that emit logs sporadically.\n  * `:iso8601` - Formats the timestamp according to ISO8601-2019. Example: `2000-02-29T23:00:07`\n* `level_key` - the key used for the log level. Defaults to `level`.\n* `message_key` - the key used for the message field. Defaults to `message`, but `msg` is a popular alternative.\n\n\n## Encoding\n\nStructs can be encoded via the `ValueEncoder` protocol.\n\n```elixir\ndefmodule User do\n  defstruct [:email, :name, :id]\n\n  defimpl LogfmtEx.ValueEncoder do\n    @doc \"\"\"\n    As we don't want to leak PII into our logs, we encode the struct to just the user's ID.\n    \"\"\"\n    def encode(user), do: to_string(user.id)\n  end\n```\n\nTypes for which the protocol is not implemented will fall back to the `to_string/1` function in the `String.Chars` protocol.\nIf the term being encoded does not implement that protocol, the formatter will fall back to the `Inspect` protocol.\n\nNote that the algebra documents produced by `Kernel.inspect/1` don't lend themselves to logfmt - this fallback is provided to minimize the chance that the formatter fails, instead making a \"best effort\" at producing usable output. It is recommended to implement either the `LogfmtEx.ValueEncoder` or `String.Chars` protocol for any data structures that might find their way into your logs.\n\n## Testing and Development\n\nThis library uses [asdf](https://asdf-vm.com) to manage runtime versions of Elixir and Erlang.\nContributions, issues, and all other feedback is more than welcome!\n\n## Benchmarks\n\nthe `/benchmarks` folder includes benchmarks comparing `LogfmtEx` to `Logger.Formatter`.\n\nYou can run them with `mix run benchmarks/throughput.exs`.\n\n## Alternatives\n\nLogfmtEx is a simple logfmt formatter specifically for the Elixir console backend.\nIf you're looking for a library to encode and decode logfmt, take a look at [logfmt-elixir](https://github.com/jclem/logfmt-elixir) instead.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakasprzok%2Flogfmt_ex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakasprzok%2Flogfmt_ex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakasprzok%2Flogfmt_ex/lists"}