{"id":21452327,"url":"https://github.com/vtfk/node-shared-logger","last_synced_at":"2025-07-26T21:34:35.748Z","repository":{"id":40680427,"uuid":"187477578","full_name":"vtfk/node-shared-logger","owner":"vtfk","description":"A logger to use in node applications","archived":false,"fork":false,"pushed_at":"2024-10-27T21:56:03.000Z","size":796,"stargazers_count":1,"open_issues_count":12,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-28T01:52:05.839Z","etag":null,"topics":["javascript","library","logging","node","nodejs","typescript"],"latest_commit_sha":null,"homepage":null,"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/vtfk.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":"2019-05-19T13:03:43.000Z","updated_at":"2024-08-14T06:36:21.000Z","dependencies_parsed_at":"2023-01-21T09:48:03.600Z","dependency_job_id":"d0cf690e-2b4e-43e4-9210-75ea44274550","html_url":"https://github.com/vtfk/node-shared-logger","commit_stats":null,"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vtfk%2Fnode-shared-logger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vtfk%2Fnode-shared-logger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vtfk%2Fnode-shared-logger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vtfk%2Fnode-shared-logger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vtfk","download_url":"https://codeload.github.com/vtfk/node-shared-logger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226001637,"owners_count":17558014,"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":["javascript","library","logging","node","nodejs","typescript"],"created_at":"2024-11-23T04:28:51.177Z","updated_at":"2025-07-14T22:31:02.494Z","avatar_url":"https://github.com/vtfk.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=center \u003eVTFK Logger\u003c/h1\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"https://img.shields.io/github/workflow/status/vtfk/node-shared-logger/Tests?label=Tests\u0026style=for-the-badge\"/\u003e\u003cimg src=\"https://img.shields.io/github/workflow/status/vtfk/node-shared-logger/Publish?label=Publish\u0026style=for-the-badge\"/\u003e\u003cimg src=\"https://img.shields.io/npm/v/@vtfk/logger?style=for-the-badge\u0026color=success\"/\u003e\u003cimg alt=\"Coveralls github branch\" src=\"https://img.shields.io/coveralls/github/vtfk/node-shared-logger/master?style=for-the-badge\"\u003e\n\u003c/div\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://github.com/vtfk/node-shared-logger\"\u003e\u003cimg src=\"https://img.shields.io/static/v1?logo=github\u0026label=\u0026message=GITHUB\u0026color=black\u0026style=for-the-badge\"/\u003e\u003c/a\u003e\u003ca href=\"https://www.npmjs.com/package/@vtfk/logger\"\u003e\u003cimg src=\"https://img.shields.io/static/v1?logo=npm\u0026label=\u0026message=NPM\u0026color=red\u0026style=for-the-badge\"/\u003e\u003c/a\u003e\n\u003c/div\u003e\n\n\u003cbr\u003e\n\u003cp align=center \u003eA simple logger for node applications. Logs to console, papertrail (via token) and Azure Function.\u003c/p\u003e\n\u003cbr\u003e\n\n## Installation\n\n`npm install --save @vtfk/logger`\n\n## Usage\n\n\u003e [!IMPORTANT]  \n\u003e Version 5.x.x and above requires Nodejs 16 or higher\n\n## Config\nAll options are optional.\n\nLogging to papertrail can be configured in `logConfig()` or as env variables.\n\nLogging to BetterStack can be configured in `logConfig()` or as env variables.\n\nLogging to Microsoft Teams can be configured in `logConfig()` or as env variable **TEAMS_WEBHOOK_URL**.\n\nAzure Function logging can be configured in `logConfig()`.\n\n\u003e Note: `logConfig()` can be called multiple times to update the config throughout the program.\n  And it will keep the previous config parameter if not specified in the next call.\n\n```js\nconst options = {\n  remote: {                     // Options for remote logging.\n    disabled: false,            // If true; disables logging to remote, even if remote config is set\n    onlyInProd: true,           // If true; only log to remote aggregator when NODE_ENV === 'production' (default is true)\n    host: '',                   // Host for the remote aggregator\n    token: '',                  // Token for the remote aggregator\n    level: ''                   // Lowest level for log to remote. If not set, all levels will log to remote\n  },\n  betterstack: {                // Options for betterstack logging.\n    disabled: false,            // If true; disables logging to betterstack, even if betterstack config is set\n    onlyInProd: true,           // If true; only log to betterstack aggregator when NODE_ENV === 'production' (default is true)\n    url: '',                    // Url for the betterstack aggregator\n    token: '',                  // Token for the betterstack aggregator\n    level: ''                   // Lowest level for log to betterstack. If not set, all levels will log to betterstack\n  },\n  teams: {                      // Options for Microsoft Teams logging with webhook.\n    disabled: false,            // If true; disables logging to Microsoft Teams, even if teams config is set\n    onlyInProd: true,           // If true; only log to Microsoft Teams when NODE_ENV === 'production' (default is true)\n    url: '',                    // Microsoft Teams channel webhook url\n    level: ''                   // Lowest level for log to Microsoft Teams. If not set, all levels will log to Microsoft Teams\n  },\n  azure: {                      // Options for Azure\n    context: context,           // The context object received from an Azure Function (see example further down)\n    excludeInvocationId: false  // If true; do not append the invocationId from the context object\n  },\n  prefix: '',                   // A string that will be added in front of each log message (ex. UID for each run)\n  suffix: '',                   // A string that will be added at the end of each log message\n  error: {                      // Options for logging out Error object. If undefined; stack from Error object will be returned\n    useMessage: true            // If true; use message from Error object instead of stack\n  },\n  localLogger: console.log      // Replace the local logger with a custom function (Default: console.log)\n}\n\nlogConfig(options)\n```\n\n\n### ENV Variables\n```bash\nNODE_ENV=production\nPAPERTRAIL_HOST = papertrail.example.com/v1/log\nPAPERTRAIL_TOKEN = jvkuvuyoufyofo8ygo8f609fo7ouyvcio7=\nBETTERSTACK_URL = https://hiufjdsiofjods.betterstackdata.com\nBETTERSTACK_TOKEN = jvkuvuyoufyofo8ygo8f609fdsiufids\nTEAMS_WEBHOOK_URL = https://\u003ctenant\u003e.webhook.office.com/blablabla\n```\n`logConfig()` options take priority.\n\n[How to get Microsoft Teams Webhook URL (Workflows)](https://support.microsoft.com/en-us/office/create-incoming-webhooks-with-workflows-for-microsoft-teams-8ae491c7-0394-4861-ba59-055e33f75498)\n\n\n### Examples\n#### Ex. Basic\nThe least amount of code to log to console or a remote aggregator (if options are set in enviroment variables)\n```js\nconst { logger } = require('@vtfk/logger')\n\nlogger('info', ['test', 'message'])\n```\n\n#### Ex. Basic (async)\nThe least amount of code to log to console or a remote aggregator asynchronous (if options are set in enviroment variables)\n```js\nconst { logger } = require('@vtfk/logger')\n\nawait logger('info', ['test', 'message'])\n```\n\n#### Ex. Basic with specifying Error property\nUse logConfig to instruct that message property is used from Error objects\n```js\nconst { logConfig, logger } = require('@vtfk/logger')\n\nlogConfig({\n  error: {\n    useMessage: true\n  }\n})\n\nlogger('info', ['test', 'message'])\n\nlogger('warn', ['another', 'action', new Error('Ups. Something happend')])\n\n// OUTPUT \n// NAME-OF-APP and VER-OF-APP is the value of \"name\" and \"version\" in your package.json\n[ 2019.05.19 15:41:17 ] \u003c INFO \u003e  {NAME-OF-APP} - {VER-OF-APP}: test - message\n[ 2019.05.19 15:41:17 ] \u003c WARN \u003e  {NAME-OF-APP} - {VER-OF-APP}: another - action - Ups. Something happend\n```\n\n#### Ex. Basic without specifying Error property\n```js\nconst { logger } = require('@vtfk/logger')\n\nlogger('info', ['test', 'message'])\n\nlogger('warn', ['another', 'action', new Error('Ups. Something happend')])\n\n// OUTPUT \n// NAME-OF-APP and VER-OF-APP is the value of \"name\" and \"version\" in your package.json\n[ 2019.05.19 15:41:17 ] \u003c INFO \u003e  {NAME-OF-APP} - {VER-OF-APP}: test - message\n[ 2019.05.19 15:41:17 ] \u003c WARN \u003e  {NAME-OF-APP} - {VER-OF-APP}: another - action - Error: Ups. Something happend\\n\n```\n\n#### Ex. Basic with prefix\nUse logConfig to display a UID infront of each message\n```js\nconst { logConfig, logger } = require('@vtfk/logger')\nconst nanoid = require('nanoid')\n\nlogConfig({\n  prefix: nanoid()\n})\n\nlogger('info', ['test', 'message'])\n\nlogger('warn', ['another', 'action'])\n\n// OUTPUT \n// NAME-OF-APP and VER-OF-APP is the value of \"name\" and \"version\" in your package.json\n[ 2019.05.19 15:41:17 ] \u003c INFO \u003e  {NAME-OF-APP} - {VER-OF-APP}: V01k3pDpHCBkAHPyCvOOl - test - message\n[ 2019.05.19 15:41:17 ] \u003c WARN \u003e  {NAME-OF-APP} - {VER-OF-APP}: V01k3pDpHCBkAHPyCvOOl - another - action\n```\n\n#### Ex. Logging in Azure Function with context object\n```js\nmodule.exports = async function (context, req) {\n  logger('info', ['New Request. Validating token'], context) // This will log to context instead of using console.log (it will still display)\n}\n```\n\n\n#### Ex. Logging to remote or Microsoft Teams\nConfiguration of remote options in the `logConfig()` function\n```js\nconst { logConfig, logger } = require('@vtfk/logger')\n\n// logConfig() is optional\nlogConfig({\n  remote: {\n    onlyInProd: true,\n    host: 'papertrail.example.com/v1/log',\n    token: 'jvkuvuyoufyofo8ygo8f609fo7ouyvcio7='\n  },\n  betterstack: {\n    onlyInProd: true,\n    url: 'https://logloglog.betterstackdata.com',\n    token: 'tpokeneinieni'\n  },\n  teams: {\n    url: 'https://\u003ctenant\u003e.webhook.office.com/blablabla'\n  }\n  prefix: 'prefixedValue',\n  suffix: 'suffixedValue'\n})\n\nlogger('info', ['test', 'message'])\n\nconst error = Error('Error in process')\nlogger('error', ['Error in app', error])\n\n// OUTPUT\n// NAME-OF-APP and VER-OF-APP is the value of \"name\" and \"version\" in your package.json\n[ 2019.05.19 15:13:35 ] \u003c INFO \u003e  {NAME-OF-APP} - {VER-OF-APP}: prefixedValue - test - message - suffixedValue\n[ 2019.05.19 15:13:35 ] \u003c ERROR \u003e  {NAME-OF-APP} - {VER-OF-APP}: prefixedValue - Error in app - Error: Error in process - suffixedValue\n```\n\n#### Ex. Logging to remote with a lowest level for remote or Microsoft Teams\nConfiguration of remote options in the `logConfig()` function\n```js\nconst { logConfig, logger } = require('@vtfk/logger')\n\n// logConfig() is optional\nlogConfig({\n  remote: {\n    onlyInProd: true,\n    host: 'papertrail.example.com/v1/log',\n    token: 'jvkuvuyoufyofo8ygo8f609fo7ouyvcio7=',\n    level: 'warn'\n  },\n  teams: {\n    url: 'https://\u003ctenant\u003e.webhook.office.com/blablabla',\n    level: 'error'\n  }\n  prefix: 'prefixedValue',\n  suffix: 'suffixedValue'\n})\n\n// this will NOT log to remote since this level is \"info\" and lowest remote level is set to \"warn\"\nlogger('info', ['test', 'message'])\n\n// this will log to remote since this level is \"error\" and lowest remote level is set to \"warn\"\nconst error = Error('Error in process')\nlogger('error', ['Error in app', error])\n\n// OUTPUT\n// NAME-OF-APP and VER-OF-APP is the value of \"name\" and \"version\" in your package.json\n[ 2019.05.19 15:13:35 ] \u003c INFO \u003e  {NAME-OF-APP} - {VER-OF-APP}: prefixedValue - test - message - suffixedValue\n[ 2019.05.19 15:13:35 ] \u003c ERROR \u003e  {NAME-OF-APP} - {VER-OF-APP}: prefixedValue - Error in app - Error: Error in process - suffixedValue\n```\n\n#### Ex. Disable logging to remote or Microsoft Teams\nConfiguration of remote options in the `logConfig()` function\n```js\nconst { logConfig, logger } = require('@vtfk/logger')\n\n// logConfig() is optional\nlogConfig({\n  remote: {\n    disabled: true,\n    onlyInProd: true,\n    host: 'papertrail.example.com/v1/log',\n    token: 'jvkuvuyoufyofo8ygo8f609fo7ouyvcio7='\n  },\n  teams: {\n    disabled: true,\n    url: 'https://\u003ctenant\u003e.webhook.office.com/blablabla'\n  }\n  prefix: 'prefixedValue',\n  suffix: 'suffixedValue'\n})\n\nlogger('info', ['test', 'message'])\n\nconst error = Error('Error in process')\nlogger('error', ['Error in app', error])\n\n// OUTPUT\n// NAME-OF-APP and VER-OF-APP is the value of \"name\" and \"version\" in your package.json\n[ 2019.05.19 15:13:35 ] \u003c INFO \u003e  {NAME-OF-APP} - {VER-OF-APP}: prefixedValue - test - message - suffixedValue\n[ 2019.05.19 15:13:35 ] \u003c ERROR \u003e  {NAME-OF-APP} - {VER-OF-APP}: prefixedValue - Error in app - Error: Error in process - suffixedValue\n```\n\n#### Ex. Azure Function\nPass the `context` object from Azure Function to add a invocationId and use `context.log[level](message)`.\n\u003e Note: If the `context` object contains all log functions (`context.log[levels]`) then it will log using these instead of `options.localLogger`\n```js\nconst { logConfig, logger } = require('@vtfk/logger')\n\nmodule.exports = async function (context, req) {\n  logConfig({\n      azure: { context }, // Pass in the context. (Shorthand for 'azure: { context: context }' )\n      prefix: 'kittens'\n  })\n  logger('error', ['are too cute!'])\n  logger('warn', ['can scratch'])\n  logConfig({ azure: { excludeInvocationId: true } }) // Exclude the invocationId from now on\n  logger('info', ['are cats'])\n\n  context.res.body = '200 OK'\n}\n\n// OUTPUT \n// NAME-OF-APP and VER-OF-APP is the value of \"name\" and \"version\" in your package.json\n[2020-11-19T11:47:43.735Z] {NAME-OF-APP} - {VER-OF-APP}: 786df5ec-e19b-4f94-a65f-b86eed8df405 - kittens - are too cute!\n[2020-11-19T11:47:43.737Z] {NAME-OF-APP} - {VER-OF-APP}: 786df5ec-e19b-4f94-a65f-b86eed8df405 - kittens - can scratch\n[2020-11-19T11:47:43.737Z] {NAME-OF-APP} - {VER-OF-APP}: kittens - are cats // invocationId is now excluded\n```\n\n## Logging\nRemote logging is only enabled in a production enviroment (`NODE_ENV === 'production'`), unless `options.remote.onlyInProd === false`.\n\n# License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvtfk%2Fnode-shared-logger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvtfk%2Fnode-shared-logger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvtfk%2Fnode-shared-logger/lists"}