{"id":27947892,"url":"https://github.com/luckyframework/dexter","last_synced_at":"2025-08-03T23:40:03.316Z","repository":{"id":39643815,"uuid":"172527723","full_name":"luckyframework/dexter","owner":"luckyframework","description":"A logger with maximum customizability and surgical precision","archived":false,"fork":false,"pushed_at":"2022-05-29T22:20:34.000Z","size":103,"stargazers_count":21,"open_issues_count":4,"forks_count":4,"subscribers_count":5,"default_branch":"main","last_synced_at":"2024-05-06T00:04:53.678Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Crystal","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/luckyframework.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2019-02-25T15:04:52.000Z","updated_at":"2024-04-12T17:13:23.000Z","dependencies_parsed_at":"2022-08-23T13:50:16.322Z","dependency_job_id":null,"html_url":"https://github.com/luckyframework/dexter","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luckyframework%2Fdexter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luckyframework%2Fdexter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luckyframework%2Fdexter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luckyframework%2Fdexter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/luckyframework","download_url":"https://codeload.github.com/luckyframework/dexter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252896922,"owners_count":21821358,"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":[],"created_at":"2025-05-07T14:38:44.830Z","updated_at":"2025-05-07T14:38:47.075Z","avatar_url":"https://github.com/luckyframework.png","language":"Crystal","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dexter\n\n[![API Documentation Website](https://img.shields.io/website?down_color=red\u0026down_message=Offline\u0026label=API%20Documentation\u0026up_message=Online\u0026url=https%3A%2F%2Fluckyframework.github.io%2Fdexter%2F)](https://luckyframework.github.io/dexter)\n\nExtensions to Crystal's `Log` class.\n\n* 100% compatible with built-in Crystal's [`Log`](https://crystal-lang.org/api/latest/Log.html)\n* Adds methods for easily logging key/value data\n* Built-in `Dexter::JSONLogFormatter` for formatting Logs as JSON\n* Helper class for making log formatting simpler and more flexible\n* Simpler configuration with helpful compile-time guarantees\n* Helper methods for testing log output more easily\n\nAnd everything is optional so if you only want the JSON formatter you can just use that.\nDexter does not break the existing `Log` and is a *very* small library.\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n   ```yaml\n   dependencies:\n     dexter:\n       github: luckyframework/dexter\n       version: ~\u003e 0.3\n   ```\n\n2. Run `shards install`\n\n## Getting started example\n\n```crystal\nrequire \"dexter\"\n\nbackend = Log::IOBackend.new\nbackend.formatter = Dexter::JSONLogFormatter.proc\n# Equivalent to: Log.builder.bind \"*\", :info, backend\nLog.dexter.configure(:info, backend)\n\n# These examples use 'info' but you can use 'debug', 'warn', and 'error' as well.\n#\n# Logs timestamp, severity and {foo: \"bar\"} as JSON\nLog.dexter.info { {foo: \"bar\"} }\n\n# You can pass an exception *and* key/value data\nLog.dexter.error(exception: my_exception) { {foo: \"bar\"} }\n\n# Fully compatible with built-in Crystal Log\n#\n# Logs timestamp, severity and {message: \"My message\"} as JSON\nLog.info { \"My message\" }\n```\n\n## Type-safe Log configuration\n\nUse `{LogClass}.dexter.configure to configure `{LogClass}` and its child logs\n\nRather than pass a string `source` to `Log.builder.bind` you can configure a\nlog using its class. This is a type-safe and simpler alternative to using\n`Log.builder.bind`.\n\n## Examples:\n\n\u003e Note: the backend can be left off and it will use the `{LogClass}`'s\n\u003e existing backend or a new `Log::IOBackend`\n\n```crystal\n# Configure all logs.\n# Similar to `Log.builder.bind \"*\"`\nLog.dexter.configure(:info, backend)\n\n# Configure Avram::Log and all child logs\n# Similar to `Log.builder.bind \"avram.*\"\nAvram::Log.dexter.configure(:warn)\n\n# Can further customize child Logs\nAvram::QueryLog.dexter.configure(:none)\nAvram::FailedQueryLog.dexter.configure(:info, SomeOtherBackend.new)\n```\n\n`{LogClass}.dexter.configure` sets all child logs to the given\nlevel/backend . If you want to configure a Log and leave its children alone\nit is best to set the `level` or `backend` directly:\n\n```crystal\nMyShard::Log.level = :error\nMyShard::Log.backend = MyCustomBackend.new\n```\n\n## Test helpers\n\nThis will temporarily configure the given log with a `Log::IOBackend`\nwith an `IO::Memory` that is yielded. The log level is also\ntemporarily set to `:debug` to log all messages\n\n```crystal\nMyShard::Log.dexter.temp_config do |log_io|\n  MyShard::Log.info { \"log me\" }\n  log_io.to_s.should contain(\"log me\")\nend\n```\n\nThere are more options for changing the level, passing your own IO, etc. See\nthe [documentation](https://github.com/luckyframework/dexter/blob/6144739a6d1a2d0f64d95a89086495c17cafe7eb/src/dexter/log.cr#L80) for more details\n\n## Built-in formatters\n\nDexter works with *any* `Log::Formatter`, but has a JSON formatter built-in\nthat works especially well.\n\n* Logs exceptions in an easily parseable format\n```json\n{\n  \"exception\": { \"class\": \"RuntimeError\", \"message\": \"Something broke\", backtrace: [\"line_of_code.cr:123\"] }\n}\n```\n* Puts string message in a `message` key that comes first so you can find it easily\n* JSON works great for searching logs with many SaaS logging services\n\n\n## Create your own formatter\n\nIncluded is a `Dexter::JSONLogFormatter`, but you can create your own formatter to format\nand output log data however you want. For example,\n[Lucky](https://luckyframework.org) has a `PrettyLogFormatter` that formats data\nin a human readable format during development, and uses the `JSONLogFormatter`\nin production.\n\nSee an example formatter in [Dexter::JSONLogFormatter](https://github.com/luckyframework/dexter/blob/master/src/dexter/json_log_formatter.cr)\n\n## Contributing\n\n1. Fork it (\u003chttps://github.com/luckyframework/dexter/fork\u003e)\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## Contributors\n\n- [Paul Smith](https://github.com/paulcsmith) - creator and maintainer\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluckyframework%2Fdexter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluckyframework%2Fdexter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluckyframework%2Fdexter/lists"}