{"id":15063681,"url":"https://github.com/viodotcom/meta_logger","last_synced_at":"2025-12-12T00:11:18.977Z","repository":{"id":46224317,"uuid":"208064506","full_name":"viodotcom/meta_logger","owner":"viodotcom","description":"A wrapper for Elixir Logger that keeps and returns the logger metadata from the caller processes.","archived":false,"fork":false,"pushed_at":"2025-03-27T11:28:42.000Z","size":255,"stargazers_count":21,"open_issues_count":4,"forks_count":3,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-03-27T12:30:03.044Z","etag":null,"topics":["bofh","elixir","elixir-library","elixir-logger"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/viodotcom.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","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":"2019-09-12T14:00:41.000Z","updated_at":"2025-03-20T21:34:10.000Z","dependencies_parsed_at":"2022-08-31T02:41:39.342Z","dependency_job_id":"a1007bbc-80d2-4703-917f-63f0b5f7f561","html_url":"https://github.com/viodotcom/meta_logger","commit_stats":null,"previous_names":["findhotel/meta_logger"],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viodotcom%2Fmeta_logger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viodotcom%2Fmeta_logger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viodotcom%2Fmeta_logger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viodotcom%2Fmeta_logger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/viodotcom","download_url":"https://codeload.github.com/viodotcom/meta_logger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248208621,"owners_count":21065203,"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":["bofh","elixir","elixir-library","elixir-logger"],"created_at":"2024-09-25T00:05:58.015Z","updated_at":"2025-12-12T00:11:18.920Z","avatar_url":"https://github.com/viodotcom.png","language":"Elixir","readme":"# MetaLogger\n\n[![Hex.pm](https://img.shields.io/hexpm/v/meta_logger.svg)](https://hex.pm/packages/meta_logger)\n[![Docs](https://img.shields.io/badge/hex-docs-542581.svg)](https://hexdocs.pm/meta_logger)\n[![Build Status](https://github.com/FindHotel/meta_logger/workflows/build/badge.svg?branch=master)](https://github.com/FindHotel/meta_logger/actions?query=branch%3Amaster)\n[![License](https://img.shields.io/hexpm/l/meta_logger.svg)](https://github.com/FindHotel/meta_logger/blob/master/LICENSE)\n\nMetaLogger is a wrapper for Elixir `Logger` that keeps and returns the logger metadata from the\ncaller processes.\n\n## Installation\n\nThe package can be installed by adding `meta_logger` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:meta_logger, \"~\u003e 1.9.0\"}\n  ]\nend\n```\n\nMetaLogger requires Elixir 1.10 or greater. For previous Elixir versions use MetaLogger `0.1.0`.\n\n## Usage\n\nJust replace `Logger` with `MetaLogger`, there is no need to require it before using:\n\n```elixir\nMetaLogger.[debug|error|info|log|warning](...)\n```\n\nFor processes that can continue running after the parent process ends, the `MetaLogger` will not\nbe able to get the caller processes metadata if the parent process is finished. In this case, the\n`MetaLogger.metadata/0` function can be used to store the metadata before the process starts:\n\n```elixir\nmetadata = MetaLogger.metadata()\n\nTask.async(fn -\u003e\n  Logger.metadata(metadata)\nend)\n```\n\n## Tesla Middleware\n\nA middleware to log requests and responses using [Tesla](https://hexdocs.pm/tesla).\n\n## Installation\n\nIf you want to use the MetaLogger Tesla middleware, optional dependencies are required. Add the\nfollowing to your `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:tesla, \"~\u003e 1.4\"},\n    {:miss, \"~\u003e 0.1\"}\n  ]\nend\n```\n\n### Usage example\n\n```elixir\ndefmodule MyClient do\n  use Tesla\n\n  plug Tesla.Middleware.MetaLogger,\n    filter_body: {~r/email=.*\u0026/, \"email=[FILTERED]\u0026\"}\n    filter_headers: [\"authorization\"],\n    filter_query_params: [:api_key],\n    log_level: :debug,\n    log_tag: MyApp,\n    max_entry_length: 22_000\nend\n```\n\n### Options\n\nSee the [`Tesla.Middleware.MetaLogger`](https://hexdocs.pm/meta_logger/Tesla.Middleware.MetaLogger.html)\ndocumentation for the options definition.\n\n## MetaLogger.Formatter protocol\n\nIt is possible to define an implementation for a custom struct, so MetaLogger will know how to\nformat log messages. It also includes the possibility to filter some data using regexp patterns.\n\nIt could be useful, when there is a defined struct with sensitive information, for example after\nan HTTP request. If you own the struct, you can derive the implementation specifying a formatter\nfunction and patterns which will be filtered.\n\nThe struct for which implementation will be used must have the `payload` field, which is used as\ninput for the defined format function.\n\n`MetaLogger.log/3` accepts the structs which derives `MetaLogger.Formatter` implementation.\n\n### Usage\n\n```elixir\ndefmodule ClientFormatterImpl do\n  @derive {\n    MetaLogger.Formatter,\n    formatter_fn: \u0026__MODULE__.format/1,\n    filter_patterns: [\n      {~s/\"name\":\".*\"/, ~s/\"name\":\"[FILTERED]\"/},\n      \"very_secret_word\"\n    ]\n  }\n\n  def build(payload) do\n    struct!(__MODULE__, payload: payload)\n  end\n\n  def format(%{foo: foo}) do\n    \"Very useful but filtered information: #{inspect(foo)}\"\n  end\nend\n\n# Inside the build function a logic can be defined to extract an useful payload\n# which needs to belogged, e.g. a request and response information.\nhttp_request\n|\u003e ClientFormatterImpl.build()\n|\u003e then(fn log_struct -\u003e MetaLogger.log(:debug, log_struct) end)\n```\n\n### Options\n\n- `:formatter_fn` (required) - The function which is used to format a given payload. The function\n  must return a string or a list of strings.\n- `:filter_patterns` (optional) - Regex patterns which will be used to replace sensitive\n  information in a payload. It is a list of strings or tuples (can be mixed). If tuples are given,\n  the first element is used as a regex pattern to match, and the second is as a replacement which\n  will be used to replace it. E.g. `{~s/\"name\": \".+\"/, ~s/\"name\": \"[FILTERED]\"/}`.\n\n## Full documentation\n\nThe full documentation is available at [https://hexdocs.pm/meta_logger](https://hexdocs.pm/meta_logger).\n\n## Contributing\n\nSee the [contributing guide](https://github.com/FindHotel/meta_logger/blob/master/CONTRIBUTING.md).\n\n## License\n\nMetaLogger is released under the Apache 2.0 License. See the\n[LICENSE](https://github.com/FindHotel/meta_logger/blob/master/LICENSE) file.\n\nCopyright © 2019-2021 FindHotel\n\n## Author\n\n[FindHotel](https://github.com/FindHotel)\n\n\u003ca href=\"https://careers.findhotel.net\" title=\"FindHotel Careers\" target=\"_blank\"\u003e\u003cimg height=\"150\" src=\"https://raw.githubusercontent.com/FindHotel/meta_logger/master/assets/fh-loves-elixir-holo.png\" alt=\"FindHotel loves Elxir!\"\u003e\u003c/a\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fviodotcom%2Fmeta_logger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fviodotcom%2Fmeta_logger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fviodotcom%2Fmeta_logger/lists"}