Git Product home page Git Product logo

winston-azure-storage-transport's Introduction

winston-azure-storage-transport

Azure Storage transports for winston >= 3.

Install

npm install winston@next
npm install winston-azure-storage-transport
npm install azure-storage

Usage

const { AzureBlobTransport } = require('./index');
const { BlobService } = require('azure-storage');
const winston = require('winston');

const blobTransport = new AzureBlobTransport({
  blobs: new BlobService(),
  containerName: 'mylogs',
  blobName: 'myappendblob',
});

const logger = winston.createLogger({
  level: 'info',
  format: winston.format.json(),
  transports: [ blobTransport ],
});

You can write logs 'silently' so that calls to the logger do not block the callback chain. In this case, listen for 'error' events on your AzureBlobTransport to handle IO errors.

const blobTransport = new AzureBlobTransport({
  blobs: new BlobService(),
  containerName: 'mylogs',
  blobName: 'myappendblob.log',
  silent: true,
}).on('error', console.error);

You can customize the blob name using a callback function. The blob will be created if it does not exist.

const blobTransport = new AzureBlobTransport({
  blobs: new BlobService(),
  containerName: 'mylogs',
  blobName: () => {
    const d = new Date();
    return [
      d.getFullYear(),
      d.getMonth() + 1,
      d.getDate(),
      'myappendblob.log',
    ].join('/');
  },
});

winston-azure-storage-transport's People

Contributors

ctstone avatar

Watchers

 avatar

Forkers

chuongtrh sumbad

winston-azure-storage-transport's Issues

Winston-Transport d.ts

Hi,

I'm facing this error when I try to build my app :

 node_modules/winston-azure-storage-transport/dist/blob-transport.d.ts:2:10 - error TS2305: Module '"../../../../../../../../../Users/me/Documents/dev/projets/test/node_modules/winston-transport"' has no exported member 'LogFunction'.

2 import { LogFunction, TransportStreamOptions } from 'winston-transport';           ~~~~~~~~~~~Found 1 error.

As far as I can see,

Winston-transport seems to have the definition types included from now : https://github.com/winstonjs/winston-transport/blob/master/index.d.ts

"LogFunction" has been renamed to "log" :
declare namespace TransportStream { type LogFunction = (message: any, callback: (err?: Error) => void) => void; type LogvFunction = (message: any[], callback: (err?: Error) => void) => void;
to
declare namespace TransportStream { interface TransportStreamOptions { format?: logform.Format; level?: string; silent?: boolean; handleExceptions?: boolean; log?(info: any, next: () => void): any; logv?(info: any, next: () => void): any; close?(): void; } }

Any luck to have an update please ?

Tks !

TypeError: Converting circular structure to JSON

When passing an object with circular references to the logger (such as the error thrown by the axios library when a connection times out), this fatal error is dumped to console and the process crashes. This inability to handle circular references is a known issue with JSON.stringify. In this case, it's line 46 of blob-transport.ts:

const text = tasks.map((x) => JSON.stringify(x)).join('\n') + '\n';

This is an issue that the winston library had in several cases this year, and they resolved it by switching from JSON.stringify to fast-safe-stringify, which is a drop-in replacement to address this exact issue.

Please consider switching.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.