@enfo/logger
v3.0.1
Published
A small wrapper made to assist with logging following our internal standard.
Downloads
149
Readme
enfo-logger
A small wrapper made to assist with logging following our internal standard.
Install
yarn add winston @enfo/logger
or
npm i winston @enfo/logger
Usage
Using the defaultSchema
which logs JSON.
import logger from '@enfo/logger'
logger.info('my first log')
// {"message":"my first log","level":"info"}
Using the textSchema
which logs text.
import { createLogger, textSchema } from '@enfo/logger'
const logger = createLogger({ schema: textSchema })
logger.info('my text log')
// [info]: my text log
Making your own schema.
import { createLogger } from '@enfo/logger'
import R from 'ramda'
import winston from 'winston'
const schema = {
format: winston.format.printf(({ level, message }) => `LEVEL ${level}: ${message}`),
parse: (x: string) =>
Promise.resolve(x)
.then(R.match(/^LEVEL (.+?): (.*)/s))
.then(R.when(
R.isNil,
() => Promise.reject(new SyntaxError(`Could not parse log: ${x}`))))
.then(([ , level, message ]) => ({ level, message }))
}
const logger = createLogger({ schema })
logger.info('my custom log')
// LEVEL info: my custom log
schema.parse('LEVEL info: my logged data')
// resolves to { level: 'info', message: 'my logged data' }
Developing
- Clone the repo
- Run
yarn install
- Run
yarn test-watch
to run the tests while deving - Run
git add . && yarn cm
to commit changes using commitizen - Run
yarn release
to create a new version using standard-version
Lint checks and tests are run automatically on commit and built by the pipeline on push.
License
enfo-logger is licensed under the terms of the MIT license.