This commit is contained in:
Tutur33
2023-11-24 22:35:41 +01:00
parent 3c0b507a93
commit 7644b2a0f7
45165 changed files with 4803356 additions and 3 deletions
+47
View File
@@ -0,0 +1,47 @@
# abstract-logging
This module provides an interface for modules to include so that they can
support logging via an external logger that conforms to the standard Log4j
interface. One such logger is [Pino](https://npm.im/pino). This module
is intended for modules that are meant to be used by other modules.
Example:
```js
'use strict'
function AwesomeLibrary (options) {
this.log = (options.logger) ? options.logger : require('abstract-logging')
}
AwesomeLibrary.prototype.coolMethod = function () {
this.log.trace('AwesomeLibrary.coolMethod was invoked')
return {}
}
module.exports = AwesomeLibrary
```
## Interface
Available methods:
+ `fatal`
+ `error`
+ `warn`
+ `info`
+ `debug`
+ `trace`
All methods are no operation functions.
Some loggers, like [Pino](https://getpino.io/), implement a `child()` method. This method can be easily added to an `abstract-logging` instance when stubbing out such loggers:
```js
const logger = require('abstract-logging')
logger.child = () => logger
```
## License
[MIT License](http://jsumners.mit-license.org/)
+18
View File
@@ -0,0 +1,18 @@
'use strict'
function noop () { }
const proto = {
fatal: noop,
error: noop,
warn: noop,
info: noop,
debug: noop,
trace: noop
}
Object.defineProperty(module, 'exports', {
get () {
return Object.create(proto)
}
})
+25
View File
@@ -0,0 +1,25 @@
{
"name": "abstract-logging",
"version": "2.0.1",
"description": "A noop logger that conforms to the Log4j interface for modules to stub out internal logging",
"main": "index.js",
"scripts": {
"test": "node test.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/jsumners/abstract-logging.git"
},
"keywords": [
"log",
"logging",
"logger",
"pino"
],
"author": "James Sumners <james.sumners@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/jsumners/abstract-logging/issues"
},
"homepage": "https://github.com/jsumners/abstract-logging#readme"
}
+17
View File
@@ -0,0 +1,17 @@
'use strict'
const assert = require('assert')
const one = require('./')
const two = require('./')
assert.notEqual(one, two)
assert.ok(one.info)
assert.equal(Function.prototype.isPrototypeOf(one.info), true)
two.info = () => 'info'
const result1 = one.info()
assert.equal(result1, undefined)
const result2 = two.info()
assert.equal(result2, 'info')