1.34.0 • Published 5 months ago

@digdir/dialogporten-node-logger v1.34.0

Weekly downloads
-
License
ISC
Repository
github
Last release
5 months ago

node-logger

Logger for nodejs that uses pino as the logger tool. Allows for both a prettified log and a more machine readable log depending on environment.

Usage

import { logger } from '@digdir/dialogporten-node-logger'

logger.info('Hello world')
logger.info({such: 'context'}, 'Hello world with additional context')
logger.error(new Error('Some error'), 'Oops')

You can also create a "context logger", this will add a context object to all log calls to that logger.

import { logger, createContextLogger } from '@digdir/dialgporten-node-logger'

logger.info('Hello world')
// logs: { <standard fields>, mgs: 'Hello world' }
logger.info({such: 'context'}, 'Hello world with additional context')
// logs: { <standard fields>, such: 'context', mgs: 'Hello world' }

const ctxLogger = createContextLogger({ foo: 'bar' })

ctxLogger.info('Hello world')
// logs: { <standard fields>, foo: 'bar', mgs: 'Hello world' }
ctxLogger.info({such: 'context'}, 'Hello world with additional context')
// logs: { <standard fields>, foo: 'bar', such: 'context', mgs: 'Hello world' }

You can also import the pino logger instance itself.

import { logger } from '@digdir/dialgporten-node-logger'

logger.pinoLogger.info('Hello world')
// logs: { <standard fields>, mgs: 'Hello world' }

### Configuration

Log level and format are configured through environment variables:

* `LOG_LEVEL` - Determines the log level. Allowed values:
  `trace, debug, info, warn, error, fatal, silent`
* `TEST_LOGGING` - Verifies the log level set by logging
  a message with every available log level. Allowed values: `true`
* `LOGGER_FORMAT` - If set to `json`, the logs will be output in
  json format for easier consumption by log services. otherwise,
  the logs are prettified
1.15.0

9 months ago

1.13.2

9 months ago

1.11.4

10 months ago

1.34.0

5 months ago

1.19.0

8 months ago

1.18.1

8 months ago

1.18.0

8 months ago

1.17.0

8 months ago

1.16.0

8 months ago

1.18.5

8 months ago

1.18.4

8 months ago

1.18.3

8 months ago

1.18.2

8 months ago

1.22.0

7 months ago

1.20.0

8 months ago

1.24.1

7 months ago

1.26.0

6 months ago

1.22.1

7 months ago

1.27.0

6 months ago

1.28.0

6 months ago

1.9.3

11 months ago

1.9.2

11 months ago

1.11.0

10 months ago

1.6.0

1 year ago

1.2.0

1 year ago

1.4.0

1 year ago

1.0.0

1 year ago