@axiomhq/winston
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

Axiom Transport for Winston logger

You can use Winston logger to send logs to Axiom. First, install the winston and @axiomhq/winston packages, then create an instance of the logger with the AxiomTransport.

Quickstart

Install using npm install:

npm install @axiomhq/winston

import the axiom transport for winston:

import { WinstonTransport as AxiomTransport } from '@axiomhq/winston';

create a winston logger instance with axiom transport:

const logger = winston.createLogger({
    level: 'info',
    format: winston.format.json(),
    defaultMeta: { service: 'user-service' },
    transports: [
        // You can pass an option here, if you don't the transport is configured automatically
        // using environment variables like `AXIOM_DATASET` and `AXIOM_TOKEN`
        new AxiomTransport({
            dataset: 'my-dataset',
            token: 'my-token',
        }),
    ],
});

then you can use the logger as usual:

logger.log({
    level: 'info',
    message: 'Logger successfully setup',
});

Error, exception and rejection handling

If you want to log Errors, we recommend using the winston.format.errors formatter, for example like this:

import winston from 'winston';
import { WinstonTransport as AxiomTransport } from '@axiomhq/winston';
const { combine, errors, stack } = winston.format;
const axiomTransport = new AxiomTransport({ ... });
const logger = winston.createLogger({
  // 8<----snip----
  format: combine(errors({ stack: true }), json()),
  // 8<----snip----
});

To automatically log exceptions and rejections, add the Axiom transport to the exceptionHandlers and rejectionHandlers like this:

import winston from 'winston';
import { WinstonTransport as AxiomTransport } from '@axiomhq/winston';
const axiomTransport = new AxiomTransport({ ... });
const logger = winston.createLogger({
  // 8<----snip----
  transports: [axiomTransport],
  exceptionHandlers: [axiomTransport],
  rejectionHandlers: [axiomTransport],
  // 8<----snip----
});

⚠️ Running on Edge runtime is not supported at the moment.

For further examples, head over to the examples directory.

License

Distributed under the MIT License.

Package Sidebar

Install

npm i @axiomhq/winston

Weekly Downloads

9,311

Version

1.2.0

License

MIT

Unpacked Size

18.8 kB

Total Files

13

Last publish

Collaborators

  • gabrielelpidio
  • flbn
  • seiflotfy
  • bahlo
  • mhr3
  • lukasmalkmus
  • kevinehosford