{"id":15287999,"url":"https://github.com/simonmcconnell/logger_file_backend_win","last_synced_at":"2025-10-21T14:44:38.435Z","repository":{"id":57517849,"uuid":"430543381","full_name":"simonmcconnell/logger_file_backend_win","owner":"simonmcconnell","description":"Elixir Logger file backend for Windows","archived":false,"fork":true,"pushed_at":"2022-08-22T05:08:08.000Z","size":83,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-23T03:42:46.615Z","etag":null,"topics":["elixir","logger","windows"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"onkel-dirtus/logger_file_backend","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simonmcconnell.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}},"created_at":"2021-11-22T02:58:02.000Z","updated_at":"2022-08-24T01:26:55.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/simonmcconnell/logger_file_backend_win","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonmcconnell%2Flogger_file_backend_win","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonmcconnell%2Flogger_file_backend_win/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonmcconnell%2Flogger_file_backend_win/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonmcconnell%2Flogger_file_backend_win/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simonmcconnell","download_url":"https://codeload.github.com/simonmcconnell/logger_file_backend_win/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235581533,"owners_count":19013089,"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","logger","windows"],"created_at":"2024-09-30T15:43:43.402Z","updated_at":"2025-10-07T02:31:58.376Z","avatar_url":"https://github.com/simonmcconnell.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LoggerFileBackendWin\n\nA simple Elixir `Logger` backend for Windows, which writes logs to a file. It can rotate files at the start of each new day (local time) and when a maximum size is reached, if you wish it to be so.\n\n**Note** If you are running this with the Phoenix framework, please review the Phoenix specific instructions later on in this file.\n\n## Configuration\n\n`LoggerFileBackendWin` is a custom backend for the elixir `:logger` application. As\nsuch, it relies on the `:logger` application to start the relevant processes.\nHowever, unlike the default `:console` backend, we may want to configure\nmultiple log files, each with different log levels, formats, etc. Also, we want\n`:logger` to be responsible for starting and stopping each of our logging\nprocesses for us. Because of these considerations, there must be one `:logger`\nbackend configured for each log file we need. Each backend has a name like\n`{LoggerFileBackendWin, name}`, where `name` is any elixir term (usually an atom).\n\nFor example, let's say we want to log error messages to\n`\"\u003cAPPDIR\u003e/logs/error_log_\u003cDATE\u003e.\u003cFILE#\u003e.log\"`. To do that, we will need to configure a backend.\n\nOur `config.exs` would have an entry similar to this:\n\n```elixir\n# tell logger to load a LoggerFileBackend processes\nconfig :logger,\n  backends: [{LoggerFileBackendWin, :error_log}]\n```\n\nWith this configuration, the `:logger` application will start one `LoggerFileBackendWin`\nnamed `{LoggerFileBackendWin, :error_log}`. We still need to set the correct file\npath and log levels for the backend, though. To do that, we add another config\nstanza. Together with the stanza above, we'll have something like this:\n\n```elixir\n# tell logger to load a LoggerFileBackend processes\nconfig :logger,\n  backends: [{LoggerFileBackendWin, :error_log}]\n\n# configuration for the {LoggerFileBackend, :error_log} backend\nconfig :logger, :error_log,\n  dir: \"logs\",\n  level: :error\n```\n\nThis will use the `name` defined in the backend configuration for the filename.  You can\nset a custom name using the `filename` option.  The complete filename looks like:\n`\"#{dir}/#{filename}_#{Date.to_string(date).#{file_number}.log\"`.  The file number starts\nat `0` and newer ones are incremented by one.  We do not rename them, the highest number \nis always the most recent.\n\n`LoggerFileBackendWin` supports the following configuration values:\n\n* `dir` - the directory where log files are saved\n* `filename` - the file name to write to\n* `level` - the logging level for the backend\n* `format` - the logging format for the backend\n* `metadata` - the metadata to include\n* `metadata_filter` - metadata terms which must be present in order to log\n* `rotate` - file rotation configuration\n\n### Directory\n\n`dir` accepts a string or a tuple `{:user_data|:user_log, app, opts}`, where opts can include `author` and/or `version`.\nThis will output logs to `C:/Users/\u003cuser\u003e/AppData/Local/[author/]\u003capp\u003e/[version/]` for `:user_data` or \n`C:/Users/\u003cuser\u003e/AppData/Local/[author/]\u003capp\u003e/[version/]Logs` for `:user_log`.\n\n### File Rotation\n\n```elixir\nconfig :logger, :error_log,\n  dir: \"logs\",\n  level: :error,\n  rotate: %{\n    daily: true,\n    days: 30,\n    keep: 3,\n    max_bytes: 1_000_000\n  }\n```\n\nThe above configuration will:\n\n* rotate files daily\n* keep 30 days worth of logs\n* create a new log file once the current one exceeds `max_bytes`\n* keeping up to `3` x `1,000,000` byte files for each day\n\nSo you'll end up with something like this:\n\n```\nerror_log_2021-06-18.1.log\nerror_log_2021-06-18.0.log\n\nerror_log_2021-06-17.0.log\n\nerror_log_2021-06-16.2.log\nerror_log_2021-06-16.1.log\nerror_log_2021-06-16.0.log\n```\n\n### Examples\n\n#### Runtime configuration\n\n```elixir\nLogger.add_backend {LoggerFileBackend, :debug}\nLogger.configure_backend {LoggerFileBackend, :debug},\n  dir: \"/path/to\",\n  filename: \"debug\"\n  format: ...,\n  metadata: ...,\n  metadata_filter: ...\n```\n\n#### Application config for multiple log files\n\n```elixir\nconfig :logger,\n  backends: [{LoggerFileBackendWin, :info},\n             {LoggerFileBackendWin, :error}]\n\nconfig :logger, :info,\n  level: :info\n\nconfig :logger, :error,\n  level: :error\n```\n\n#### Filtering specific metadata terms\n\nThis example only logs `:info` statements originating from the `:ui` OTP app; the `:application` metadata key is auto-populated by `Logger`.\n\n```elixir\nconfig :logger,\n  backends: [{LoggerFileBackendWin, :ui}]\n\nconfig :logger, :ui,\n  level: :info,\n  metadata_filter: [application: :ui]\n```\n\nThis example only writes log statements with a custom metadata key to the file.\n\n```elixir\n# in a config file:\nconfig :logger,\n  backends: [{LoggerFileBackendWin, :device_1}]\n\nconfig :logger, :device_1,\n  level: :debug,\n  metadata_filter: [device: 1]\n\n# Usage:\n# anywhere in the code:\nLogger.info(\"statement\", device: 1)\n\n# or, for a single process, e.g., a GenServer:\n# in init/1:\nLogger.metadata(device: 1)\n# ^ sets device: 1 for all subsequent log statements from this process.\n\n# Later, in other code (handle_cast/2, etc.)\nLogger.info(\"statement\") # \u003c= already tagged with the device_1 metadata\n```\n\n## Additional Phoenix Configurations\n\nPhoenix makes use of its own `mix.exs` file to track dependencies and additional applications. Add the following to your `mix.exs`:\n\n```elixir\ndef application do\n    [applications: [\n      ...,\n      :logger_file_backend_win,\n      ...\n      ]\n    ]\nend\n  \ndefp deps do\n  [ \n    ...\n    {:logger_file_backend_win, \"~\u003e 0.0.2\"},\n    ...\n  ]\nend\n```\n\n###  Attribution\n\nThis project is little more than [logger_file_backend](https://github.com/onkel-dirtus/logger_file_backend) modified to rotate files on Windows.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonmcconnell%2Flogger_file_backend_win","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimonmcconnell%2Flogger_file_backend_win","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonmcconnell%2Flogger_file_backend_win/lists"}