Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

winston custom transport with typescript

I'm having a hard time trying to get a winstom custom logger compiled using typescript.

I'm taking this js code as starting point and taking into account this comment from github:

import * as Transport from 'winston-transport'

//
// Inherit from `winston-transport` so you can take advantage
// of the base functionality and `.exceptions.handle()`.
//
module.exports = class YourCustomTransport extends Transport {
  constructor(opts) {
    super(opts);
    //
    // Consume any custom options here. e.g.:
    // - Connection information for databases
    // - Authentication information for APIs (e.g. loggly, papertrail, 
    //   logentries, etc.).
    //
  }

  log(info, callback) {
    setImmediate(() => {
      this.emit('logged', info);
    });

    // Perform the writing to the remote service
    callback();
  }
};

But I get the error:

Type 'typeof TransportStream' is not a constructor function type.ts(2507)

I tried with several alternatives but always end up blocked by typescript compiler.

like image 535
opensas Avatar asked Dec 23 '22 22:12

opensas


1 Answers

When I replace your import statement with

 import Transport = require('winston-transport');

then tsc has no complaints. This is similar to how the built-in file transport imports winston-transport.

like image 66
davewy Avatar answered Jan 12 '23 00:01

davewy