Skip to content

Quickstart ​

Getting started with @nhtio/logger is quick and easy. Just follow the steps below and you'll be up and running in no time.

Installation ​

You can install @nhtio/logger directly from your preferred package manager

sh
npm i @nhtio/logger
sh
pnpm add @nhtio/logger
sh
yarn add @nhtio/logger

Initialization ​

@nhtio/logger exports 2 kinds of Loggers:

  • A generic logger which provides syslog log level methods
  • A pino-compatible logger which provides pino log level methods

Generic Logger ​

Import the Logger

typescript
import { Logger } from '@nhtio/logger'

Then initialize it

typescript
const logger = new Logger('INFO', {foo: 'bar'})

Pino Compatible Logger ​

Import the PinoCompatibleLogger

typescript
import { Logger } from '@nhtio/logger'

Then initialize it

typescript
const logger = new PinoCompatibleLogger('INFO')

Using as a Pino Transport ​

@nhtio/logger also exports a pino-compatible transport which can be used with an existing Pino logger.

typescript
const transport = pino.transport({
    target: '@nhtio/logger/transports/pino',
    options: {
        level: 'INFO'
    }
})

Integration with Loki ​

You can pass an object with contains the configuration options to log with Loki to the Logger and PinoCompatibleLogger as the last argument in order to faciliate automatic logging to a Loki server.

Additionally, you can pass this configuration object to the transport options for use with the Pino Transport under the key loki.