當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript winston.createLogger函數代碼示例

本文整理匯總了TypeScript中winston.createLogger函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript createLogger函數的具體用法?TypeScript createLogger怎麽用?TypeScript createLogger使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了createLogger函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: constructor

	constructor() {
		const alignedWithColorsAndTime = winston.format.combine(
			winston.format.colorize(),
			winston.format.timestamp(),
			//winston.format.align(),
			winston.format.printf(info => `${info.timestamp} ${info.level}: ${info.message}`),
		);

		this.textLogger = winston.createLogger({
			format: alignedWithColorsAndTime,
			transports: [],
			level: config.vpdb.logging.level,
		});

		if (config.vpdb.logging.console.enabled) {
			this.textLogger.add(new winston.transports.Console());
		}
		/* istanbul ignore next */
		if (config.vpdb.logging.file.text) {
			const logPath = resolve(config.vpdb.logging.file.text);
			const transport = new DailyRotateFile({
				filename: basename(logPath),
				dirname: dirname(logPath),
				zippedArchive: true,
				datePattern: 'YYYY-MM',
			});
			transport.on('rotate', (oldFilename, newFilename) => {
				this.info(null, '[app] Rotating text logs from %s to %s.', oldFilename, newFilename);
			});
			transport.on('new', newFilename => {
				this.info(null, '[app] Creating new text log at %s.', newFilename);
			});
			this.textLogger.add(transport);
			this.info(null, '[app] Text logger enabled at %s.', logPath);
		}
		/* istanbul ignore next */
		if (config.vpdb.logging.file.json) {
			const logPath = resolve(config.vpdb.logging.file.json);
			const transport = new DailyRotateFile({
				filename: basename(logPath),
				dirname: dirname(logPath),
				zippedArchive: true,
				datePattern: 'YYYY-MM',
			});
			transport.on('rotate', (oldFilename, newFilename) => {
				this.info(null, '[app] Rotating JSON logs from %s to %s.', oldFilename, newFilename);
			});
			transport.on('new', newFilename => {
				this.info(null, '[app] Creating new JSON log at %s.', newFilename);
			});
			this.jsonLogger = winston.createLogger({
				format: winston.format.json(),
				transports: [transport],
				level: config.vpdb.logging.level,
			});
			this.info(null, '[app] JSON logger enabled at %s.', logPath);
		}
	}
開發者ID:freezy,項目名稱:node-vpdb,代碼行數:58,代碼來源:logger.ts

示例2: createLogger

  public static createLogger(
    gatsbyEnv: GatsbyEnv = GatsbyEnv.Development,
  ): Logger {
    const logger = winston.createLogger({
      format: winston.format.json(),
      level: 'info',
      transports: [
        // ==================================================================
        // - Write to all logs with level `info` and below to `combined.log`
        // - Write all logs error (and below) to `error.log`.
        // =================================================================
        new winston.transports.File({ filename: 'error.log', level: 'error' }),
        new winston.transports.File({ filename: 'combined.log' }),
      ],
    })

    // =====================================================================
    // If we're not in production then log to the `console` with the format:
    // `${info.level}: ${info.message} JSON.stringify({ ...rest }) `
    // =====================================================================
    if (gatsbyEnv !== GatsbyEnv.Production) {
      logger.add(
        new winston.transports.Console({
          format: winston.format.simple(),
        }),
      )
    }
    return logger
  }
開發者ID:jessestuart,項目名稱:jessestuart.com,代碼行數:29,代碼來源:log.ts

示例3: constructor

 constructor () {
     this.logger = winston.createLogger({
         level: 'error',
         transports: [new winston.transports.Console()],
         format: winston.format.combine(
             winston.format.colorize({ all: true }),
             logFmt
         )
     })
 }
開發者ID:0mkara,項目名稱:remix,代碼行數:10,代碼來源:logger.ts

示例4: default

export default ({ config }: { config: LoggerConfig }): Logger => {
  const myFormat = printf(info => {
    return `${info.timestamp} ${info.level}: ${info.message}`;
  });

  const logger = createLogger({
    level: config.level,
    format: combine(timestamp(), myFormat),
    transports: [new transports.Console({ format: format.simple() })],
  });

  return logger;
};
開發者ID:sebelga,項目名稱:blog-app-googlecloud,代碼行數:13,代碼來源:logger.ts

示例5: function

/**
 * Configure logger
 * @param  {string} logfile Path to logfile
 * @param  {object} config Configuration for transports
 * @return {winston.Logger}
 */
export default function(app: Application, options: ILoggingOptions) {
  const cwd = process.cwd();
  const logFile = path.resolve(cwd, `${options.dir}/${options.file}`);
  const addRequestId = require("express-request-id")({ setHeader: false });

  app.use(addRequestId);
  morgan.token("id", (req: IRequestWithId) => req.id.split("-")[0]);

  app.use(morgan("[:date[iso] #:id] Started :method :url for :remote-addr", {immediate: true}));

  app.use(morgan("[: date[iso] #: id] Completed : status : res[content - length] in : response - time ms"));

  // If logs directory does not exist, create one
  if (!fs.existsSync(path.resolve(cwd, options.dir))) {
    mkdirp.sync(path.resolve(cwd, options.dir));
  }

  // If log file does not exist, create one with empty content.
  if (!fs.existsSync(logFile)) {
    fs.writeFileSync(logFile, "");
  }

  const logger = winston.createLogger({
    exitOnError: false,
    format: winston.format.json(),
    level: "info",
    transports: [
      new winston.transports.File({
        filename: logFile,
        handleExceptions: true,
        level: "info",
        maxFiles: 5,
        maxsize: 5242880, // 5MB
      }),
      new winston.transports.Console({
        handleExceptions: true,
        level: "debug",
      }),
    ],

  });

  return logger;
}
開發者ID:charlesponti,項目名稱:cthulhu,代碼行數:50,代碼來源:logger.ts

示例6: function

module.exports = async function (arg : any) {
	let format;
	if (arg && arg.quiet) {
		transport = {
			info : function () { return false },
			warn : function () { return false },
			error : function () { return false }
		}
	} else {
		if (arg && arg.label) {
			format = combine(
				label({ label : arg.label }),
				//timestamp(),
				colorize(),
				simple()
			);
		} else {
			format = combine(
				//timestamp(),
				colorize(),
				simple()
			);
		}
		transport = createLogger({
			transports: [
				new (transports.Console)({
					format
				}),
				new (transports.File)({ 
					filename: await logFile(),
					format : combine(
						label({ label : arg.label }),
						//timestamp(),
						json()
					)
				})
			]
		})
	}
	return transport
}
開發者ID:sixteenmillimeter,項目名稱:mcopy,代碼行數:41,代碼來源:index.ts

示例7: constructor

  /**
   * Constructs a new instance of PolymerLogger. This creates a new internal
   * `winston` logger, which is what we use to handle most of our logging logic.
   *
   * Should generally called with getLogger() instead of calling directly.
   */
  constructor(options: Options) {
    options = Object.assign({colorize: true}, options);

    const formats = [];
    if (options.colorize) {
      formats.push(winston.format.colorize());
    }
    formats.push(winston.format.align());
    formats.push(plylogPrettify({ colorize: options.colorize }));
    this._transport = defaultConfig.transportFactory({
      level: options.level || 'info',
      format: winston.format.combine(...formats),
    });

    this._logger = winston.createLogger({transports: [this._transport]});

    this.error = this._log.bind(this, 'error');
    this.warn = this._log.bind(this, 'warn');
    this.info = this._log.bind(this, 'info');
    this.debug = this._log.bind(this, 'debug');
  }
開發者ID:Polymer,項目名稱:plylog,代碼行數:27,代碼來源:index.ts

示例8:

import * as winston from 'winston';

const logger = winston.createLogger({
  level: 'info',
  transports: [new winston.transports.Console()],
});

export default logger;
開發者ID:ericmasiello,項目名稱:synbydesign,代碼行數:8,代碼來源:logger.ts

示例9: new

import winston from "winston";

const logger = winston.createLogger({
    transports: [
        new (winston.transports.Console)({level: process.env.NODE_ENV === "production" ? "error" : "debug"}),
        new (winston.transports.File)({filename: "debug.log", level: "debug"})
    ]
});

if (process.env.NODE_ENV !== "production") {
    logger.debug("Logging initialized at debug level");
}

export default logger;

開發者ID:paul-phan,項目名稱:TypeScript-Node-Starter,代碼行數:14,代碼來源:logger.ts

示例10: constructor

 constructor (config: LoggerConfigInterface) {
   this.adapter = winston.createLogger(config);
 }
開發者ID:RWOverdijk,項目名稱:stix,代碼行數:3,代碼來源:LoggerService.ts


注:本文中的winston.createLogger函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。