@enfo/logger
TypeScript icon, indicating that this package has built-in type declarations

3.0.1 • Public • Published

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

  1. Clone the repo
  2. Run yarn install
  3. Run yarn test-watch to run the tests while deving
  4. Run git add . && yarn cm to commit changes using commitizen
  5. 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.

Readme

Keywords

none

Package Sidebar

Install

npm i @enfo/logger

Weekly Downloads

18

Version

3.0.1

License

MIT

Unpacked Size

16.5 kB

Total Files

8

Last publish

Collaborators

  • castodius
  • enfogroup