{"id":21672657,"url":"https://github.com/pier-digital/pier-logging-rails","last_synced_at":"2025-04-12T03:54:09.781Z","repository":{"id":40057177,"uuid":"276778196","full_name":"pier-digital/pier-logging-rails","owner":"pier-digital","description":null,"archived":false,"fork":false,"pushed_at":"2023-08-23T21:41:41.000Z","size":74,"stargazers_count":6,"open_issues_count":9,"forks_count":0,"subscribers_count":20,"default_branch":"main","last_synced_at":"2025-04-12T03:54:04.795Z","etag":null,"topics":["library"],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/pier-digital.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null}},"created_at":"2020-07-03T01:20:34.000Z","updated_at":"2023-04-20T12:49:01.000Z","dependencies_parsed_at":"2023-02-11T22:02:08.203Z","dependency_job_id":null,"html_url":"https://github.com/pier-digital/pier-logging-rails","commit_stats":null,"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pier-digital%2Fpier-logging-rails","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pier-digital%2Fpier-logging-rails/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pier-digital%2Fpier-logging-rails/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pier-digital%2Fpier-logging-rails/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pier-digital","download_url":"https://codeload.github.com/pier-digital/pier-logging-rails/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248514205,"owners_count":21116899,"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":["library"],"created_at":"2024-11-25T13:31:23.878Z","updated_at":"2025-04-12T03:54:09.758Z","avatar_url":"https://github.com/pier-digital.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PierLogging\n\nA gem developed by [PIER](https://www.pier.digital/) to standardize our logs (request and general-purpose)\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'pier_logging'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install pier_logging\n\n## Usage\n\n- Create an initializer at `config/initializers/pier_logging.rb` to configure the gem.\n- Configure General-purpose logging, Request logging and register the request logger rails middleware.\n- Configure your logger on `config/application.rb` to use `PierLogging::Logger`\n\n### General-purpose logging\n\nUse `PierLogging.configure_logger` block to configure general-purpose logs. Accepted configs are:\n\n| config    | Required | Type                      | Default                            |\n| --------- | --------:| -------------------------:| ----------------------------------:|\n| app_name  | true     | string                    | nil                                |\n| env       | true     | string                    | nil                                |\n| formatter | false    | `Ougai::Formatters::Base` | `PierLogging::Formatter::Json.new` |\n\n### Request logging\n\nUse `PierLogging.configure_request_logger` block to configure request logs. Accepted configs are:\n\n| config           | Required | Type            | Default    |\n| ---------------- | --------:| ---------------:| ----------:|\n| enabled          | false    | boolean         | false      |\n| user_info_getter | true     | block (headers) | nil        |\n| sensitive_keywords | false | array of symbols, strings or regexps | `REDACT_REPLACE_KEYS` in request_logger.rb\n\nThe block passed to `user_info_getter` receives the headers of the request so you can use your headers to define the username or role. \n\nYou have at your disposal the following helper methods:\n\n- has_basic_credentials(headers): checks if there are basic auth credentials in the header\n- get_basic_credentials_user(headers): get the user from the basic auth credential\n\n### Example\n\n```ruby\n# config/initializers/pier_logging.rb\n\nPierLogging.configure_logger do |config|\n  config.app_name = Rails.application.class.module_parent_name.underscore.dasherize\n  config.env = Rails.env\n  config.formatter = Rails.env.production? ? PierLogging::Formatter::Json.new : \n    PierLogging::Formatter::Readable.new\nend \n\nPierLogging.configure_request_logger do |config|\n  config.user_info_getter do |headers|\n    if headers['MY-USER-HEADER'].present?\n      { username: headers['MY-USER-HEADER']  }\n    elsif has_basic_credentials?(headers)\n      { username: get_basic_credentials_user(headers) }\n    else\n      { username: 'anonymous' }\n    end\n  end\n  config.enabled = ENV.fetch('REQUEST_LOG_ENABLED', 'true') == 'true'\nend\n\nRails.application.config.middleware.use PierLogging::RequestLogger, PierLogging::Logger.new(STDOUT)\n```\n\n```ruby\n# config/application.rb\n\n# ...\nconfig.logger = PierLogging::Logger.new(STDOUT)\n# ...\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/pier-digital/pier_logging.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpier-digital%2Fpier-logging-rails","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpier-digital%2Fpier-logging-rails","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpier-digital%2Fpier-logging-rails/lists"}