{"id":19778312,"url":"https://github.com/npkgz/logging-facility","last_synced_at":"2026-05-16T11:03:07.078Z","repository":{"id":66170250,"uuid":"59988689","full_name":"npkgz/logging-facility","owner":"npkgz","description":" :page_with_curl: Logging Abstraction Layer for easy backend switching","archived":false,"fork":false,"pushed_at":"2018-02-10T10:03:10.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-27T08:36:43.458Z","etag":null,"topics":["abstraction","javascript","logger","logging","logging-library","nodejs"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/logging-facility","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/npkgz.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE.md","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":"2016-05-30T07:14:51.000Z","updated_at":"2021-05-24T13:52:18.000Z","dependencies_parsed_at":"2023-07-19T03:31:31.585Z","dependency_job_id":null,"html_url":"https://github.com/npkgz/logging-facility","commit_stats":null,"previous_names":["andidittrich/node.logging-facility"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/npkgz/logging-facility","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npkgz%2Flogging-facility","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npkgz%2Flogging-facility/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npkgz%2Flogging-facility/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npkgz%2Flogging-facility/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/npkgz","download_url":"https://codeload.github.com/npkgz/logging-facility/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npkgz%2Flogging-facility/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33100319,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-16T04:41:52.686Z","status":"ssl_error","status_checked_at":"2026-05-16T04:41:52.009Z","response_time":115,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["abstraction","javascript","logger","logging","logging-library","nodejs"],"created_at":"2024-11-12T05:28:53.042Z","updated_at":"2026-05-16T11:03:07.050Z","avatar_url":"https://github.com/npkgz.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Logging Facility\n================\n\nApplication Logging Abstraction Layer\n\n```bash\n$ yarn add logging-facility\n$ npm install logging-facility --save\n```\n\nFeatures\n--------\n\n* **Abstraction Layer/Wrapper to easily exchange your logging backend without breaking your code**\n* Common used syslog levels are exposed as functions (emergency, alert, critical, error, warning, notice, info, debug)\n* Multiple Loggers identified by name\n* Ability to use multiple Backends\n* All Logging functions are aggregated into **a single** callback\n\nUsage\n---------\n\n#### 1. Application Startup/Configuration ####\n\nThis code sets up the logging-backend and should be executed within the application bootstrap\n\n```js\nconst _loggingFacility = require('logging-facility');\n\n// use fancy colored cli output\n_loggingFacility.addBackend('fancy-cli');\n```\n\n### 2. Logging ###\n\nWithin each of your application files you can access the global named loggers\n\n```js\n// create/get a logger named \"mylogger\"\nconst _logger = require('logging-facility').getLogger('mylogger');\n\n// log something\n_logger.info('Initializing module X1', 'Additional Payload');\n_logger.emergency('fatal error');\n```\n\n### 3. Custom Logging Backend ###\n\n```js\nconst _loggingFacility = require('logging-facility');\n\n// only required for styling \nconst _colors = require('colors/safe');\n\n// set the logging backend/upstream\n// every log message is passed to this function\n_loggingFacility.setBackend(function(facility, level, args){\n    // simple console output\n    \n    // log, info, debug\n    if (level \u003e 5){\n        console.log(_colors.grey(facility.trim() + '~'), args.join(' '));\n\n    // errors\n    }else{\n        console.log(_colors.red(facility.trim() + '~'), args.join(' '));\n    }\n});\n```\n\nMultiple Backends\n-----------------------------\n```js\nconst _loggingFacility = require('logging-facility');\n\n// add logging backend for fatal errors\n_loggingFacility.addBackend(function(facility, level, args){\n   \n   // send a e-mail on fatal errors occured\n   if (level \u003e 3){\n        Mailer.notify(args[0]);\n   }\n});\n\n// add fancy console output\n_loggingFacility.addBackend('fancy-cli');\n```\n\nMethods/Syntax\n------------------------------\n\n### ::getLogger() ###\n\n**Description:** Create a new logger\n\n**Syntax:** `logger:object = getLogger(name)`\n\n**Arguments:**\n\n * name:string - the instance name of the logger, passed as first argument to the backend function\n\n**Returns:**\n\nAn object with the following logging-functions\n\n * emerg(...messages),\n * emergency(...messages),\n * alert(...messages),\n * crit(...messages),\n * critical(...messages),\n * error(...messages),\n * err(...messages),\n * warning(...messages),\n * warn(...messages),\n * notice(...messages),\n * log(...messages),\n * info(...messages),\n * debug(...messages),\n\n**Example:**\n\n```js\n// create/get a logger named \"mylogger\"\nconst _logger = require('logging-facility').getLogger('mylogger');\n\n// log something\n_logger.info('Initializing module X1', 'Additional Payload');\n_logger.emergency('fatal error');\n```\n\n### ::addBackend() ###\n\n**Description:** Adds a new backend logger to the stack\n\n**Syntax:** `setBackend(backend:function|string, [minLogLevel:int=99])`\n\n**Arguments:**\n\n * backend:(function|string) - a callback function which will receive all log messages. all default loggers can be accessed by name (allowed values: `fancy-cli`, `cli`).\n * minLogLevel:int=99 (optional) - the minimum log-level of the backend in case it's initialized by name not function\n\n**Example:**\n```js\nconst _loggingFacility = require('logging-facility');\n\n// add logging backend for fatal errors\n_loggingFacility.addBackend(function(facility, level, args){\n   \n   // send a e-mail on fatal errors occured\n   if (level \u003e 3){\n        Mailer.notify(args[0]);\n   }\n});\n\n// add fancy console output\n_loggingFacility.addBackend('fancy-cli');\n\n// add simple cli output\n_loggingFacility.addBackend('cli');\n```\n\n### ::setBackend() ###\n\n**DEPRECATED**\n\n**Description:** Removes all exsiting backends and add a new one to the stack\n\n**Syntax:** `setBackend(backend:function|string)`\n\n**Arguments:**\n\n * backend:(function|string) - a callback function which will receive all log messages. all default loggers can be accessed by name.\n\n **Example:**\n```js\nconst _loggingFacility = require('logging-facility');\n\n// add fancy console output\n_loggingFacility.addBackend('fancy-cli');\n\n// add logging backend for fatal errors - WILL REMOVE the fancy-cli backend added previously!\n_loggingFacility.setBackend(function(facility, level, args){\n   \n   // send a e-mail on fatal errors occured\n   if (level \u003e 3){\n        Mailer.notify(args[0]);\n   }\n});\n```\n\n### ::LEVEL ###\n\n**Description:** Constants used for different log-levels `@see lib/loglevel.js`\n\n```\nEMERGENCY: 0\nALERT: 1\nCRITICAL: 2\nERROR: 3\nWARNING: 4\nNOTICE: 5\nINFO: 6\nDEBUG: 7\n```\n\n**Example:**\n\n```js\nconst _loggingFacility = require('logging-facility');\n\n// get warning log-level\nconsole.log(_loggingFacility.LEVEL.WARNING);\n```\n\n### ::LOGGER ###\n\n**Description:** Build-In logging backends\n\n```\nCLI - simple cli logging\nFANCY - colorized cli output\nDEFAULT - alias of CLI\n```\n\n**Example:**\n\n```js\nconst _loggingFacility = require('logging-facility');\n\n// add logging function with min-loglevel of 5\n_loggingFacility.addBackend(_loggingFacility.LOGGER.CLI(_loggingFacility.LEVEL.NOTICE));\n```\n\nAny Questions ? Report a Bug ? Enhancements ?\n---------------------------------------------\nPlease open a new issue on [GitHub](https://github.com/AndiDittrich/Node.Logging-Facility/issues)\n\nLicense\n-------\nLogging-Facility is OpenSource and licensed under the Terms of [The MIT License (X11)](http://opensource.org/licenses/MIT). You're welcome to contribute!","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnpkgz%2Flogging-facility","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnpkgz%2Flogging-facility","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnpkgz%2Flogging-facility/lists"}