如何导入NodeJS`winston-daily-rotate-file`依赖项?

时间:2019-06-06 07:14:39

标签: javascript node.js logging winston

我可以使用VC2来使用VC1依赖性。

class VC1 : UIViewController {
    var isShowListAsked: Bool = false

    func onTapMapButton(_ sender: UIButton) {
        if let controller = self.storyboard?.instantiateViewController(withIdentifier: "VC2") as? VC2 {
            controller.handler = {[weak self] (value) in
                self?.isShowListAsked = value
                print(self?.isShowListAsked) 
            }
            self.present(controller, animated: true, completion: nil)
        }
    }
}

但是当我尝试像下面这样导入时,它不起作用。如何解决?

winston-daily-rotate-file

custom-logger.js

require

在运行应用程序时,出现以下错误

var DailyRotateFile = require('winston-daily-rotate-file');

3 个答案:

答案 0 :(得分:1)

import * as winston from 'winston';
import 'winston-daily-rotate-file';
import appRoot from 'app-root-path';


const logger = winston.createLogger({
    transports: [
        new winston.transports.DailyRotateFile ({
            filename: 'application-%DATE%.log',
            dirname: `${appRoot}/logs/`,
            level: 'info',
            handleExceptions: true,
            colorize: true,
            json: false,
            zippedArchive: true,
            maxSize: '20m',
            maxFiles: '14d'        
        })
    ],
    exitOnError: false
});

logger.stream = {
    write: function(message, encoding) {
      logger.info(message);
    },
  };

export default logger;

这会将记录器配置为每日轮换。

答案 1 :(得分:0)

尝试

import DailyRotateFile = require("winston-daily-rotate-file");

答案 2 :(得分:0)

尝试一下:

DateTime.Now