npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

winston-axios

v1.7.7

Published

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

Downloads

34

Readme

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.

| Param | Type | Description | | -------- | -------------------------------- | --------------------------------------------------------------------------------------------------- | | url | string | The url to send the logs to. | | path | string | The path to send the logs to. The destination url will resolve to url + path. | | auth | string | The authentication token to send with the logs. Will override any auth headers provided in headers. | | authType | TransportAuthType | The type of authentication to use. | | method | TransportMethod | The method to use when sending the logs. | | headers | AxiosRequestHeaders | The 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)

| Param | Type | Description | | ------- | ------------------------------------------------------------ | ------------------------------ | | options | AxiosTransportOptions | The options for the transport. |

Example

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