Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bonniernews/exp-logger
https://github.com/bonniernews/exp-logger
Last synced: about 8 hours ago
JSON representation
- Host: GitHub
- URL: https://github.com/bonniernews/exp-logger
- Owner: BonnierNews
- Created: 2022-12-20T10:00:35.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-11-04T09:42:47.000Z (14 days ago)
- Last Synced: 2024-11-04T09:52:42.765Z (14 days ago)
- Language: JavaScript
- Size: 71.3 KB
- Stars: 1
- Watchers: 15
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# exp-logger
Simple logger package to unify how logging is done with (configurable) remapping
[NPM](https://www.npmjs.com/package/@bonniernews/exp-logger)
___
## defaults
* trace -> DEBUG
* debug -> DEBUG
* info -> INFO
* warn -> WARNING
* error -> ERROR
* fatal -> CRITICAL
___
## options
```js
logLevel // defaults to info
mixin // pino mixins, passed down to pino as is
formatLog // pino formatter.log function, passed down to pino as is
```
## example
```jsconst logger = require('@bonniernews/exp-logger')()
logger.info("Hello world")
/*
-- expected output
[15:19:13.240] INFO: Hello world
*/
```## Format the log object
To change the shape of the log object to match gcp error-reporting structure or similiar, use formatLog```js
const expLogger = require('@bonniernews/exp-logger');const logger = expLogger({
formatLog: (obj) => {
if (!obj.err) {
return obj;
}
const stackTrace = obj.err?.stack;
return {
...obj,
...(stackTrace && { stack_trace: stackTrace }),
};
}
);logger.error(new Error('Something wrong'));
```