{"id":16368570,"url":"https://github.com/ianstormtaylor/heroku-logger","last_synced_at":"2025-03-16T15:32:58.374Z","repository":{"id":19848356,"uuid":"88082738","full_name":"ianstormtaylor/heroku-logger","owner":"ianstormtaylor","description":"A dead simple logger, designed to be perfect for Heroku apps.","archived":false,"fork":false,"pushed_at":"2022-04-07T02:44:25.000Z","size":1619,"stargazers_count":58,"open_issues_count":4,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-04-14T04:55:40.676Z","etag":null,"topics":["heroku","logger","logging","nodejs"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ianstormtaylor.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"License.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-12T18:16:21.000Z","updated_at":"2023-06-10T06:00:04.000Z","dependencies_parsed_at":"2022-08-24T21:01:53.734Z","dependency_job_id":null,"html_url":"https://github.com/ianstormtaylor/heroku-logger","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ianstormtaylor%2Fheroku-logger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ianstormtaylor%2Fheroku-logger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ianstormtaylor%2Fheroku-logger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ianstormtaylor%2Fheroku-logger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ianstormtaylor","download_url":"https://codeload.github.com/ianstormtaylor/heroku-logger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221665575,"owners_count":16860282,"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":["heroku","logger","logging","nodejs"],"created_at":"2024-10-11T02:53:09.350Z","updated_at":"2024-10-27T10:51:29.128Z","avatar_url":"https://github.com/ianstormtaylor.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# heroku-logger\n\nA dead simple logger, designed to be perfect for Heroku apps.\n\n---\n\n### Features\n\n- No configuration necessary—with sane defaults based on your `NODE_ENV` and `LOG_LEVEL` environment variables.\n- Matches Heroku's own [logfmt](https://brandur.org/logfmt) formatting syntax in production.\n- Makes your logging nice and easy to read in development.\n\n---\n\n### Example\n\nGiven an API which is what you'd expect...\n\n```js\nconst logger = require('heroku-logger')\n\nlogger.info('Starting server', { port: 4000 })\nlogger.error('Invalid `type` argument', { argument: 'type', value: 'nuber' })\n```\n\nIn development, it outputs an easy to read version...\n\n![](./docs/screenshot-dev.png)\n\nBut in production, it omits the junk, since Heroku handles that for you, and simply outputs the data in [`logfmt`]()...\n\n![](./docs/screenshot-prod.png)\n\nIn any add-ons attached to your Heroku log drain, the metadata will be picked up automatically...\n\n![](./docs/screenshot-addon-collapsed.png)\n![](./docs/screenshot-addon-expanded.png)\n\nThat's it!\n\n---\n\n### Why?\n\nThere are lots of Node.js logging packages—simple ones that basically just print strings to the console, and complex ones like [Winston](https://github.com/winstonjs/winston) or [Bunyan](https://github.com/trentm/node-bunyan) which give you fine-grained control.\n\nBut none that were a one-liner for Heroku apps, with sane defaults.\n\nHeroku already handles all of the logging issues that complex libraries solve—timestamping, process-stamping, log draining, performance, etc. So the complex libraries are just extra configuration for no gains.\n\nBut the one thing that no logger handled nicely was matching Heroku's [logfmt](https://brandur.org/logfmt) formatting out of the box. By using logfmt for your application logs, you get a consistent output for everything, so any consumers of the Heroku log drains can automatically parse them, because they're in the same format.\n\n---\n\n### API\n\n```js\nconst logger = require('heroku-logger')\n\nlogger.info('message', { key: 'value' })\n```\n```\n[info] message key=value level=info message=message\n```\n\nThe package exports the one-liner `logger` singleton as the default, which is already instanciated with sane defaults using the `LOG_LEVEL` and `NODE_ENV` environment variables.\n\n#### new Logger(options)\n\n```js\nconst Logger = require('heroku-logger').Logger\n\nconst logger = new Logger({\n  color: Boolean,    // Defaults to `true` only if `NODE=ENV != 'production'`.\n  delimiter: String, // Defaults to  `'#'`.\n  level: String,     // Defaults to `LOG_LEVEL` if set, or `'info'`.\n  prefix: String,    // Defaults to `''`.\n  readable: Boolean, // Defaults to `true` only if `NODE=ENV != 'production'`.\n})\n```\n\nBut if you need to create multiple instances, which can be useful for subclassing loggers based on the parts of your system, the `Logger` constructor is also exported, which takes the following options:\n\n- `color` sets whether to log in colors, for easier scanning.\n- `level` sets the current log threshold, silencing logs that don't meet it.\n- `delimiter` sets the delimiter to use for nested data keys.\n- `prefix` sets a string that will be prepend to every message.\n- `readable` sets whether to log the `message` separate from the `data`.\n\n#### logger\\[level\\](message, data)\n\n```js\nlogger.info('message', { key: 'value' })\nlogger.error('error!', { code: 400 })\n```\n```\n[info] message key=value level=info message=message\n[error] error! code=400 level=error message=error!\n```\n\nLog a `message` with `data` to the console at `level`, where level is one of:\n\n- `debug`\n- `info`\n- `warn`\n- `error`\n\nYou can also pass an `Error` object as a `message`, in which case the logger will automatically convert it into useful `message` and `data` with a full stack trace.\n\n#### logger.log(level, message, data)\n\n```js\nlogger.log('info', 'message', { key: 'value' })\n```\n```\n[info] message key=value level=info message=message\n```\n\nLog a `message` with `data` to the console at `level`.\n\n#### logger.clone(options)\n\n```js\nconst other = logger.clone({ prefix: '[package] ' })\n\nother.info('message', { key: 'value' })\n```\n```\n[info] [package] message key=value level=info message=message\n```\n\nCreate a new `Logger` instance, copying the existing loggers config, but extending it with optional `options`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fianstormtaylor%2Fheroku-logger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fianstormtaylor%2Fheroku-logger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fianstormtaylor%2Fheroku-logger/lists"}