https://github.com/alloc/shared-log
Decoupled logging for libraries
https://github.com/alloc/shared-log
logging nodejs
Last synced: 9 months ago
JSON representation
Decoupled logging for libraries
- Host: GitHub
- URL: https://github.com/alloc/shared-log
- Owner: alloc
- License: mit
- Created: 2021-04-13T02:08:07.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2022-04-02T00:20:59.000Z (almost 4 years ago)
- Last Synced: 2025-04-07T09:03:18.690Z (10 months ago)
- Topics: logging, nodejs
- Language: TypeScript
- Homepage:
- Size: 26.4 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# shared-log
[](https://www.npmjs.com/package/shared-log)
[](https://bundlephobia.com/result?p=shared-log)
[](https://github.com/prettier/prettier)
[](https://paypal.me/alecdotbiz)
> Decoupled logging for libraries
### Usage
Libraries should import `shared-log` and treat it as write-only.
"Reading" the log (via event listener) is reserved for the end user.
```ts
import log from 'shared-log'
// The log function is console.log by default
log('all arguments', 'are passed thru')
// Log methods exist for each log level
log.error(new Error('ruh roh'))
log.warn(...)
log.info(...)
log.verbose(...)
log.debug(...)
```
The end user hooks up their logging library of choice.
```ts
import log from 'shared-log'
// Listen to every log level
log.on('all', (level, args, filename) => {...})
// or a specific log level
log.on('error', (args, filename) => {...})
```
If the end user doesn't add a log listener, the `console` is used by default, but the `debug` and `verbose` log levels are ignored by default.