{"id":15641760,"url":"https://github.com/trygve-lie/abslog","last_synced_at":"2025-04-30T09:14:27.445Z","repository":{"id":27003914,"uuid":"111962983","full_name":"trygve-lie/abslog","owner":"trygve-lie","description":"An abstract logger - Enables adding logging to modules without adding a dependency to a full log library.","archived":false,"fork":false,"pushed_at":"2024-10-21T03:41:47.000Z","size":173,"stargazers_count":6,"open_issues_count":3,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-29T15:12:52.617Z","etag":null,"topics":["javascript","log","log4j","logdna","logger","loggerinterface","nodejs","pino","roarr","synclog","winston"],"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/trygve-lie.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-11-24T23:37:51.000Z","updated_at":"2024-10-21T03:41:37.000Z","dependencies_parsed_at":"2024-03-12T20:30:24.291Z","dependency_job_id":"dfcd6ebf-56de-49f3-a4e4-698c881da814","html_url":"https://github.com/trygve-lie/abslog","commit_stats":{"total_commits":314,"total_committers":10,"mean_commits":31.4,"dds":0.6114649681528662,"last_synced_commit":"f6fc1f0ed41c56d03bb16d9d17f53b4bddc03ae0"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trygve-lie%2Fabslog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trygve-lie%2Fabslog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trygve-lie%2Fabslog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trygve-lie%2Fabslog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/trygve-lie","download_url":"https://codeload.github.com/trygve-lie/abslog/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233546487,"owners_count":18692228,"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","log","log4j","logdna","logger","loggerinterface","nodejs","pino","roarr","synclog","winston"],"created_at":"2024-10-03T11:45:00.140Z","updated_at":"2025-01-11T22:55:31.550Z","avatar_url":"https://github.com/trygve-lie.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# abslog\n\n[![Dependencies](https://img.shields.io/david/trygve-lie/abslog.svg?style=flat-square)](https://david-dm.org/trygve-lie/abslog)\n[![GitHub Actions status](https://github.com/trygve-lie/abslog/workflows/Run%20Lint%20and%20Tests/badge.svg)](https://github.com/trygve-lie/abslog/actions?query=workflow%3A%22Run+Lint+and+Tests%22)\n[![Known Vulnerabilities](https://snyk.io/test/github/trygve-lie/abslog/badge.svg?targetFile=package.json\u0026style=flat-square)](https://snyk.io/test/github/trygve-lie/abslog?targetFile=package.json)\n\nAn abstract logger - Enables adding logging to modules without adding a dependency to a full log library. This way, the consumer of your modules can plug in their own log library of choice.\n\nThe API of this abstract logger conforms to the standard [Log4j interface](https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Level.html) levels.\n\n\n## Installation\n\n```bash\n$ npm install abslog\n```\n\n\n## Usage\n\nIn your module(s):\n\n```js\nconst abslog = require('abslog');\n\nclass AwesomeModule {\n    constructor(logger) {\n        this.log = abslog(logger);\n    }\n\n    doStuff() {\n        this.log.info('Did stuff');\n    }\n}\n```\n\nThe consumer of your module, using pino as logger:\n\n```js\nconst AwesomeModule = require('AwesomeModule');\nconst pino = require('pino')();\n\nconst awesome = new AwesomeModule(pino);\nawesome.doStuff()  // will now log on info\n```\n\n\n## Interface\n\n`abslog` takes one argument. It takes an logger expected to be log4j interface\ncompatible.\n\nIf no logger is provided an object with log methods will be returned. Each of\nthese method are just `noop` methods adding minimal footprint and performance impact\non your module.\n\nIf a logger is provided, the logger will be returned. This leaves `abslog` adding\nzero runtime footprint and performance impact on your module.\n\nIf an logger is provided but the logger is not compatible with the log4j interface,\nan exception will be thrown.\n\n\n## Methods\n\nThe log4j compatilbe methods are:\n\n * fatal\n * error\n * warn\n * info\n * debug\n * trace\n\nExample:\n\n```js\nconst abslog = require('abslog');\n\nconst log = abslog();\nlog.fatal('critital message');\nlog.error(new Error(), 'error message');\nlog.warn('warn message');\nlog.info('info message');\nlog.debug('debug message');\nlog.trace('trace message');\n```\n\n\n## console.log\n\n`Console` is not log4j compatible, but `abslog` does support `Console` for logging.\nIts worth noticing that its not recommended to use `Console` for logging in production\ncode, but it can be handy to just plug in `Console` to get log output in development.\n\nExample:\n\n```js\nconst abslog = require('abslog');\n\nconst log = abslog(console);\nlog.info('some message');\nlog.fatal('critical message');\n```\n\n\n## Known compatible loggers:\n\nThese loggers are known to be compatible and tested:\n\n### pino\n\n[pino](https://www.npmjs.com/package/pino) is found to be compatible.\n\n```js\nconst abslog = require('abslog');\nconst pino = require('pino')();\n\nconst log = abslog(pino);\nlog.info('hello');\n```\n\n### bunyan\n\n[bunyan](https://www.npmjs.com/package/bunyan) is found to be compatible.\n\n```js\nconst abslog = require('abslog');\nconst bunyan = require('bunyan');\n\nconst logger = bunyan.createLogger({\n    name: 'test',\n    stream: process.stdout,\n    level: 'trace'\n});\n\nconst log = abslog(logger);\nlog.info('hello');\n```\n\n### log4js\n\n[log4js](https://www.npmjs.com/package/log4js) is found to be compatible.\n\n```js\nconst abslog = require('abslog');\nconst log4js = require('log4js');\n\nconst logger = log4js.getLogger();\n\nconst log = abslog(logger);\nlog.info('hello');\n```\n\n### winston\n\n[winston](https://www.npmjs.com/package/winston) is found to NOT be compatible\nout of the box. Though, winston can be customised with alternative log levels\nand through such a configuration be compatible.\n\n```js\nconst abslog = require('abslog');\nconst winston = require('winston');\n\nconst winstonCustomLevels = {\n    levels: {\n        fatal: 0,\n        error: 1,\n        warn: 2,\n        info: 3,\n        debug: 4,\n        trace: 5,\n    },\n    colors: {\n        fatal: 'red',\n        error: 'red',\n        warn: 'yellow',\n        info: 'green',\n        debug: 'blue',\n        trace: 'cyan',\n    }\n};\n\nconst logger = winston.createLogger({\n    levels: winstonCustomLevels.levels,\n});\n\nconst log = abslog(logger);\nlog.info('hello');\n```\n\n### roarr\n\n[roarr](https://github.com/gajus/roarr) is found to be compatible.\n\n```js\nconst abslog = require('abslog');\nconst roarr = require('roarr').default;\n\nconst log = abslog(roarr);\nlog.info('hello');\n```\n\n### synclog\n\n[synclog](https://github.com/trygve-lie/synclog) is found to be compatible.\n\n```js\nconst abslog = require('abslog');\nconst SyncLog = require('synclog')\n\nconst log = abslog(new SyncLog('debug'));\nlog.info('hello');\n```\n\n### LogDna\n\n[LogDna](https://www.npmjs.com/package/logdna) is found to be compatible.\n\n```js\nconst abslog = require('abslog');\nconst LogDna = require('logDna')\n\nconst log = abslog(Logdna.createLogger('some_api_key_goes_here', {}));\nlog.info('hello');\n```\n\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2018 - Trygve Lie - post@trygve-lie.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrygve-lie%2Fabslog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrygve-lie%2Fabslog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrygve-lie%2Fabslog/lists"}