{"id":26930209,"url":"https://github.com/dial-once/node-logtify","last_synced_at":"2025-10-15T00:03:41.723Z","repository":{"id":74212855,"uuid":"90992360","full_name":"dial-once/node-logtify","owner":"dial-once","description":"Flexible logger based on winston package and EventEmitter","archived":false,"fork":false,"pushed_at":"2018-11-30T08:45:18.000Z","size":120,"stargazers_count":5,"open_issues_count":6,"forks_count":0,"subscribers_count":8,"default_branch":"develop","last_synced_at":"2025-03-18T02:01:45.528Z","etag":null,"topics":["logtify","nodejs","presets","pub","stream","winston"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/dial-once.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-05-11T15:03:48.000Z","updated_at":"2023-03-20T23:21:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"ef542de7-9f3c-4c40-b103-8825dca0c7f9","html_url":"https://github.com/dial-once/node-logtify","commit_stats":{"total_commits":46,"total_committers":6,"mean_commits":7.666666666666667,"dds":"0.32608695652173914","last_synced_commit":"49f28e03288ce1aacdc1956b293ea2537b4e2beb"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dial-once%2Fnode-logtify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dial-once%2Fnode-logtify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dial-once%2Fnode-logtify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dial-once%2Fnode-logtify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dial-once","download_url":"https://codeload.github.com/dial-once/node-logtify/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246651544,"owners_count":20811993,"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":["logtify","nodejs","presets","pub","stream","winston"],"created_at":"2025-04-02T06:17:30.845Z","updated_at":"2025-10-15T00:03:36.682Z","avatar_url":"https://github.com/dial-once.png","language":"JavaScript","readme":"# Logtify\n\n[![CircleCI](https://circleci.com/gh/dial-once/node-logtify/tree/develop.svg?style=svg)](https://circleci.com/gh/dial-once/node-logtify/tree/develop)\n[![Sonar](http://proxy.dialonce.net/sonar/api/badges/gate?key=node-logtify)](http://sonar.dialonce.net/dashboard?id=node-logtify)\n[![Sonar](http://proxy.dialonce.net/sonar/api/badges/measure?key=node-logtify\u0026metric=ncloc)](http://sonar.dialonce.net/dashboard?id=node-logtify)\n[![Sonar](http://proxy.dialonce.net/sonar/api/badges/measure?key=node-logtify\u0026metric=coverage)](http://sonar.dialonce.net/dashboard?id=node-logtify)\n[![Sonar](http://proxy.dialonce.net/sonar/api/badges/measure?key=node-logtify\u0026metric=code_smells)](http://proxy.dialonce.net/sonar/api/badges/measure?key=node-logtify\u0026metric=coverage)\n[![Sonar](http://proxy.dialonce.net/sonar/api/badges/measure?key=node-logtify\u0026metric=bugs)](http://sonar.dialonce.net/dashboard?id=node-logtify)\n[![Sonar](http://proxy.dialonce.net/sonar/api/badges/measure?key=node-logtify\u0026metric=sqale_debt_ratio)](http://sonar.dialonce.net/dashboard?id=node-logtify)\n\n### [Dev Tips](https://github.com/dial-once/node-logtify/wiki)\n\n## Installing the module\n```bash\nnpm i -S logtify\n```\n\n## Configuration\nFull list of env variables. Can be used in config object with the same name. Each of them is optional\n```\nLOG_TIMESTAMP = 'true'\nLOG_ENVIRONMENT = 'true'\nLOG_LEVEL = 'true'\nLOG_REQID = 'true' // only included when provided with metadata\nLOG_CALLER_PREFIX = 'true' // additional prefix with info about caller module/project/function\nJSONIFY = 'true' // converts metadata to json\nCONSOLE_LOGGING = 'true'\nLOGENTRIES_LOGGING = 'true'\nLOGSTASH_LOGGING = 'true'\nBUGSNAG_LOGGING = 'true'\n```\n\nEnvironment variables have a higher priority over the settings object\n\n### Minimal\n```js\nconst { logger } = require('logtify')();\n```\n### Configuration via object\n\n```js\n// Note, that such settings will be passed to each subscriber:\nconst { logger } = require('logtify')({\n    CONSOLE_LOGGING: false, // switches off the console subscriber\n    MIN_LOG_LEVEL: 'info' // minimal message level to be logged\n});\n```\n\n### Add new subscriber\nA subscriber is a small independent logger unit, whose job is to send logs to (ideally) one service/node.\n\nBy default, logtify contains only 1 subscriber - `Console`.\n\nHowever, you can add [any of the following available subscribers](https://github.com/dial-once/node-logtify/tree/feature/metadata-handling#existing-subscribers)\n\n### Add adapter\nAn adapter is a small plugin, meant to ease the usage of some subscriber.\n\nIf a subscriber provides an adapter, it will be exposed in the logtify instance\n```js\nrequire('logtify-bugsnag')();\nconst { logger, notifier } = require('logtify')();\n```\n\nIf you import he subscriber with adapter __after__ you initialize the stream, you need to update the logtify reference, because __adapter property will be undefined__.\n\n### Logger usage:\n```js\nconst { logger } = require('logtify')();\n\nlogger.silly('Hello world');\nlogger.verbose('Hello world');\nlogger.debug('Hello world');\nlogger.info('Hello world');\nlogger.warn('Hello world', { your: 'metadata' }, { at: 'the end' });\nlogger.error(new Error('Hello world'));\nlogger.log('info', 'Hello world');\n\nlogger.profile('label');\n```\n\n### Stream Usage:\n```js\nconst { stream } = require('logtify')();\n\nstream.log('warn', 'Hello world', { metadata: 'Something' });\n\n// properties\nstream.settings;         // Object\nstream.adapters;         // Map\nstream.subscribersCount; // Number\n\n// classes\nstream.Message;          // Object\nstream.Subscriber;       // Object\n```\n\n### Message format\n\nThen provided data is converted into a message package object of the following structure:\n\n```js\n// if text message\n{\n  level: {'silly'|'verbose'|'debug'|'info'|'warn'|'error'},\n  text: {string},\n  meta: {\n    instanceId: {string},\n    ... (other metadata provided in runtime)\n  }\n}\n```\n\nMetadata object can be stringified to JSON with ``process.env.JSONIFY = 'true'``. Alternatively, you can do the same via configs object.\n\n### Default logLevel priority:\n- silly -\u003e 0\n- verbose -\u003e 1\n- debug -\u003e 2\n- info -\u003e 3\n- warn -\u003e 4\n- error -\u003e 5\n\n## Adding your own subscriber\n\nPlease refer to [Dev Tips](https://github.com/dial-once/node-logtify/wiki) for more information on the topic\n\n## Prefixing\nSubscribers may include prefixes into a message. For example\n```js\nlogger.info('Hello world');\n```\nwill result in:\n\n``info: [2017-05-10T15:16:31.468Z:local:INFO:] Hello world instanceId={youtInstanceId}``\n\nYou can enable/disable them with the following environment variables / parameters for the stream settings:\n```\nprocess.env.LOG_TIMESTAMP = 'true';\nprocess.env.LOG_ENVIRONMENT = 'true';\nprocess.env.LOG_LEVEL = 'true';\nprocess.env.LOG_REQID = 'true';\nprocess.env.LOG_CALLER_PREFIX = 'true';\n```\n\n`LOG_CALLER_PREFIX` - enables/disables printing of additional prefix: `[project:module:function]` with information about the caller project\n\n**Note!** that if the ``LOG_REQID`` is set to ``'true'``, it will still not log it (as seen from example above), unless it is provided in the ``message.meta``.\nSo, to include it, you should do the following:\n```js\nlogger.info('Hello world', { reqId: 'something' });\n```\nAnd it will result in:\n\n``info: [2017-05-10T15:16:31.468Z:local:INFO:something] Hello world instanceId={yourInstanceId}``\n\n## Presets\nTo make it easier to config the logger, some presets are available:\n* ``dial-once`` - enables Console subscriber when ``NODE_ENV`` is neither ``staging`` or ``production`` and disables it otherwise. Also includes ``jsonify`` option.\n\n```js\nconst { stream, logger } = require('logtify')({ presets: ['dial-once'] });\n```\n* ``no-prefix`` - disables the prefix from the message\n* ``prefix`` - enables the prefix in the message\n* ``jsonify`` - convert message metadata to JSON. By defaunt, object is flattened\n\nApply a preset by passing it to the stream configs:\n```js\nconst { stream, logger } = require('logtify')({\n    presets: ['dial-once', 'no-prefix']\n});\n```\n  \n## Existing subscribers:\n- Console subscriber (part of this project)\n- [Logentries Subscriber](https://github.com/dial-once/node-logtify-logentries)\n- [Logstash Subscriber](https://github.com/dial-once/node-logtify-logstash)\n- [Bugsnag Subscriber](https://github.com/dial-once/node-logtify-bugsnag)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdial-once%2Fnode-logtify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdial-once%2Fnode-logtify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdial-once%2Fnode-logtify/lists"}