Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

winston-axios

Package Overview
Dependencies
Maintainers
0
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

winston-axios

An axios transport for winston which allows for sending REST requests to an external API

  • 1.7.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
38
increased by65.22%
Maintainers
0
Weekly downloads
 
Created
Source

Winston-Axios

Build npm version Known Vulnerabilities

An axios transport for winston which allows for sending REST requests to an external API.

Usage

Setup

const { AxiosTransport } = require('winston-axios');

or

import { AxiosTransport } from 'winston-axios';

Create a logger with an Axios Transport

const winston = require('winston');
const { AxiosTransport } = require('winston-axios');

const logger = winston.createLogger({
  level: 'info',
  format: winston.format.json(),
  transports: [
    new AxiosTransport({
      url: 'http://localhost:9999',
      path: '/log',
      auth: 'abc123',
    }),
  ],
});

Add an Axios Transport to an existing logger

const { AxiosTransport } = require('winston-axios');

logger.add(
  new AxiosTransport({
    host: 'http://localhost:9999/log'
  })
);

Receiving the log message

You can simply use logger.info(request.body); to log the request in the external API as Winston can resolve the body.

More information on body formatting is to come.

Example

A production example of using this transport is available here: photoprism-helper logger.ts

Here is the relevant code, omitting anything not relevant to the transport:

import { createLogger, transports } from 'winston';
import { AxiosTransport } from 'winston-axios';

const config = {
  levelConsole: 'info',
  url: 'http://apiurl.com'
  key: 'abc123'
}
//.code here.//

// Create a logger instance with custom settings
export const logger = createLogger({
  transports: [
    new transports.Console({ level: config.levelConsole }),
    //.code here.//
  ],
    //.code here.//
});

//.code here.//

// Add an Axios transport to the logger instance
logger.add(
  new AxiosTransport({
    url: config.url,
    path: '/log',
    auth: config.key,
  })
);

Documentation

AxiosTransportOptions

Options for Axios Transport.

AxiosTransport

Transport for Winston that sends log messages to a remote server using Axios.

AxiosTransportOptions

Options for Axios Transport.

ParamTypeDescription
urlstringThe url to send the logs to.
pathstringThe path to send the logs to. The destination url will resolve to url + path.
authstringThe authentication token to send with the logs. Will override any auth headers provided in headers.
authTypeTransportAuthTypeThe type of authentication to use.
methodTransportMethodThe method to use when sending the logs.
headersAxiosRequestHeadersThe headers to send with the logs.

AxiosTransport

Transport for Winston that sends log messages to a remote server using Axios.

See: AxiosTransportOptions

new AxiosTransport(options)

ParamTypeDescription
optionsAxiosTransportOptionsThe options for the transport.

Example

const logger = createLogger({
  transports: [
    new AxiosTransport({
      url: 'http://localhost:3000',
      path: '/logs',
    }),
  ],
});
logger.log({ level: 'info', message: 'Hello World' });

Keywords

FAQs

Package last updated on 11 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc