1.2.0 • Published 10 months ago

@axiomhq/winston v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

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----
});

:warning: 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.

1.2.0

10 months ago

1.1.1

11 months ago

1.0.0

1 year ago

1.0.0-rc.4

1 year ago

1.0.0-rc.3

1 year ago

1.0.0-rc.2

1 year ago

1.0.0-rc.1

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago