{"id":16413076,"url":"https://github.com/rlopzc/logger_exporter","last_synced_at":"2025-12-11T23:33:18.094Z","repository":{"id":43714286,"uuid":"440628959","full_name":"rlopzc/logger_exporter","owner":"rlopzc","description":"Export your logs to the service of your choice.","archived":false,"fork":false,"pushed_at":"2024-03-08T16:32:12.000Z","size":196,"stargazers_count":21,"open_issues_count":8,"forks_count":6,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-03-15T03:55:27.374Z","etag":null,"topics":["elixir","elixir-phoenix","heroku","logger","logger-backend","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/rlopzc.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"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}},"created_at":"2021-12-21T19:28:32.000Z","updated_at":"2024-04-21T17:10:59.438Z","dependencies_parsed_at":"2023-12-09T01:27:58.156Z","dependency_job_id":"d3dbc761-24f8-43f2-996b-c09ff04a8464","html_url":"https://github.com/rlopzc/logger_exporter","commit_stats":null,"previous_names":["romariolopezc/logger_exporter"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rlopzc%2Flogger_exporter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rlopzc%2Flogger_exporter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rlopzc%2Flogger_exporter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rlopzc%2Flogger_exporter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rlopzc","download_url":"https://codeload.github.com/rlopzc/logger_exporter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221811376,"owners_count":16884305,"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":["elixir","elixir-phoenix","heroku","logger","logger-backend","logging"],"created_at":"2024-10-11T06:50:33.128Z","updated_at":"2025-12-11T23:33:13.074Z","avatar_url":"https://github.com/rlopzc.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LoggerExporter\n\nExport your logs to the service of your choice.\n\nI created this library because I wanted to export logs to a different service in\nHeroku. There is no simple way to export your logs.\n\n## Supported exporters:\n- Loki\n- Mezmo (LogDNA)\n\nImplement your own exporter using `LoggerExporter.Exporters.Exporter` behaviour.\n\n## Supported formatters:\n- Basic. By default, it will read your logger `:console` format configuration.\n  Example:\n  ```elixir\n  config :logger, :console, format: \"$time $message\"\n  ```\n  Defaults to `$time $metadata[$level] $message`\n\nImplement your own formatter using `LoggerExporter.Formatters.Formatter` behaviour.\n\n## Plug Logger\n\nA plug for logging request information. It will log the method, path, params,\nstatus and duration.\n\nYou can add it to your MyApp.Endpoint:\n```elixir\n  # Log level defaults to :info\n  plug LoggerExporter.Loggers.Plug\n\n  # Dynamic log\n  plug LoggerExporter.Loggers.Plug, log: {__MODULE__, :log_level, []}\n\n  # Disables logging for routes like /health_check\n  def log_level(%{path_info: [\"health_check\"]}), do: false\n  def log_level(_), do: :info\n```\n\n## Installation\n\nAdd `logger_exporter` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:logger_exporter, \"~\u003e 0.4.0\"}\n  ]\nend\n```\n\n## Configuration\n\nBy default, the timestamp sent for each log to the external service is in UTC: `System.os_time(:nanosecond)`\n\n| option           | description                                                                                                   | default                                    |\n|------------------|---------------------------------------------------------------------------------------------------------------|--------------------------------------------|\n| level            | The logger level to report.                                                                                   | `:info`                                    |\n| formatter        | Allows the selection of a formatter implementation.                                                           | `LoggerExporter.Formatters.BasicFormatter` |\n| metadata         | Metadata to log.                                                                                              | `[]`                                       |\n| exporter         | Allows selection of a exporter implementation.                                                                | `LoggerExporter.Exporters.LokiExporter`    |\n| host             | The host of the service without the path. The path is inferred by the exporter.                               | No default. Required                       |\n| app_name         | The name of the app to use as label.                                                                          | No default. Required                       |\n| environment_name | The name of the app to use as label.                                                                          | No default. Required                       |\n| http_client      | Allows the selection of the HTTP client.                                                                      | `LoggerExporter.HttpClient.ReqClient`     |\n| send_to_http     | If set to false, the library will not make any actual API calls. This is useful for test or dev environments. | `true`                                     |\n| http_auth        | See below for configuration                                                                                   | No default                                 |\n\n\n### HTPP Auth\n\nSupported authentication methods:\n- Basic\n- Bearer\n- Custom\n\n| auth     | examples                                   | result                                           |\n| -------- | ------------------------------------------ | ------------------------------------------------ |\n| basic    | `{:basic, \"user\", \"pxIsldPlwty\"}`          | `\"Authorization: Basic CshL2XlkX57cww==\"`        |\n| bearer   | `{:bearer, \"WmRUuBOnTjDwP6jo3bno\"}`        | `\"Authorization: Bearer WmRUuBOnTjDwP6jo3bno\"`   |\n| custom   | `{:header, \"apiKey\", \"dAWRQQkZCc2A==\"}`    | `\"apiKey: dAWRQQkZCc2A==\"`                       |\n\n## Usage in Phoenix\n\n1.  Add the following to deps section of your mix.exs: `{:logger_exporter, \"~\u003e 0.4.0\"}`\n    and then `mix deps.get`\n\n2.  Add `LoggerExporter.Backend` to your logger's backends configuration\n\n    ```\n    config :logger,\n      backends: [:console, LoggerExporter.Backend]\n    ```\n\n3.  Add config related to the exporter and other fields.\n    ie. for `LokiExporter`\n\n    ```elixir\n    config :logger, LoggerExporter,\n      host: \"http://localhost:3100\",\n      app_name: \"my_app\",\n      environment_name: config_env(),\n      http_auth: {:basic, System.fetch_env!(\"LOKI_USER\"), System.fetch_env!(\"LOKI_PASSWORD\")},\n      metadata: [:request_id]\n    ```\n\n4.  Start the LoggerExporter GenServer in the supervised children list.\n    In `application.ex` add to the children list:\n\n    ```elixir\n    children [\n      ...\n      LoggerExporter\n    ]\n    ```\n5. (Optional) Add custom Plug logger.\n  In `MyApp.Endpoint` add the plug after `Plug.Parsers`.\n  If you see duplicate logs, remove `Plug.Telemetry` from your endpoint.\n\n    ```elixir\n    plug Plug.Parsers,\n      ...\n\n    plug LoggerExporter.Loggers.Plug\n    ```\n\n## JSON Formatter Example\n\nIf you want to log in JSON format, you can use the formatter of another library:\n[logger_json](https://github.com/Nebo15/logger_json)\n\nYou need to implement the following formatter using the `LoggerExporter.Formatters.Formatter` behaviour.\n\n```elixir\ndefmodule MyFormatter do\n  @behaviour LoggerExporter.Formatters.Formatter\n\n  alias LoggerJSON.Formatters.BasicLogger\n\n  @impl true\n  def format_event(level, msg, ts, md, md_keys) do\n    BasicLogger.format_event(level, msg, ts, md, md_keys, [])\n    |\u003e Jason.encode!()\n  end\nend\n```\n\nThen, configure it like this:\n```elixir\nconfig :logger, LoggerExporter,\n  formatter: MyFormatter\n```\n\nTada! You have JSON logs!\n\n## Telemetry\n\nTelemetry integration for logging and error reporting.\n\nThere is a default logger for you to attach. It logs when the `status` is `:error`\n\nIn your `application.ex`\n\n```elixir\n:ok = LoggerExporter.Telemetry.attach_default_logger()\n```\n\n### HTTP Post batch events\n\nLoggerExporter emits the following events for processing each batch (sending it through http)\n\n- `[:logger_exporter, :batch, :start]` -- starting to process the events\n- `[:logger_exporter, :batch, :stop]` -- after the events is processed\n- `[:logger_exporter, :batch, :exception]` -- after the events are processed\n\nThe following chart shows which metadata you can expect for each event:\n\n| event        | measures       | metadata                               |\n| ------------ | -------------- | ---------                              |\n| `:start`     | `:system_time` | `:events`                              |\n| `:stop`      | `:duration`    | `:events, :status, :response`          |\n| `:exception` | `:duration`    | `:events, :kind, :reason, :stacktrace` |\n\nMetadata\n* `:events` - the list of `LoggerExporter.Event` processed.\n* `:status` - either `:ok` or `:error`.\n* `:response` - information of the response.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frlopzc%2Flogger_exporter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frlopzc%2Flogger_exporter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frlopzc%2Flogger_exporter/lists"}