迁移到Winston 3并扩展Winston Logger

发布于 2025-02-12 16:53:25 字数 816 浏览 1 评论 0原文

我想将Winston Logger扩展到我的自定义记录仪。 在调用内部方法之前,我在哪里更新日志方法。

对于温斯顿2.4.x版 我这样做了。

var winston = require("winston");

var Logger = function(options){
  Logger.super_.apply(this, arguments);
}
util.inherits(Logger, winston.Logger);

Logger.prototype.log = function () {

  //some logic

  Logger.super_.prototype.log.apply(this, args);

};

Now, I am migrating to the Winston version 3.xx

I migrated the above code as

class Logger extends winston.createLogger {

  constructor(options) {
    super(options);
  }

  log() {

    //some logic

    super.log(args);
  };
}

The above code is able to create an instance of the logger and start logging the logs but it is not calling my log method instead it's only calling the inbuild Winston日志方法。

I want to extend the Winston logger to my custom logger.
Where I updated the log method before calling the internal method.

For Winston version 2.4.x
I did this.

var winston = require("winston");

var Logger = function(options){
  Logger.super_.apply(this, arguments);
}
util.inherits(Logger, winston.Logger);

Logger.prototype.log = function () {

  //some logic

  Logger.super_.prototype.log.apply(this, args);

};

Now, I am migrating to the Winston version 3.x.x

I migrated the above code as

class Logger extends winston.createLogger {

  constructor(options) {
    super(options);
  }

  log() {

    //some logic

    super.log(args);
  };
}

The above code is able to create an instance of the logger and start logging the logs but it is not calling my log method instead it's only calling the inbuild Winston log method.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文