winston

How to force nodejs winston log to file before process exit

对着背影说爱祢 提交于 2021-02-07 18:25:38
问题 I am using winston 3 to log my data. But sometimes it didn't log the error before process exit. The following process will exit, without log to the logfile.log : const winston = require('winston'); winston.add(new winston.transports.File({ filename: 'logfile.log' })); winston.info('please log me in'); process.exit(1); One of attempted solution is used callback: const winston = require('winston'); const logger = new winston.createLogger({ new winston.transports.File({ filename: 'logfile.log' }

winston + PM2 logging uncaughtException twice

无人久伴 提交于 2021-02-06 13:57:11
问题 I am using winston for my NodeJS apps, to have a structured logging format (JSON) that later I will process and send to Logstash via Filebeat. As suggested by PM2 and 12factor.net I'm logging using winston.transports.Console transport and letting PM2 to handle the stdout and stderr in my ecosystem.json . In my logger.js module I have the following: "use strict"; const winston = require("winston"); // Remove logging on console winston.remove(winston.transports.Console); // env const env =

Log js file name and function name

孤街浪徒 提交于 2021-02-04 20:59:25
问题 I would like my node.js project to generate log files that are a bit similar to log4j format in that I would like each log line to commence with the file name and the js function name that the log request originated from. e.g: If my js file is called aNiceFile.js and my js function is called doImportantStuff() and I invoke a log statement with something like: log.info('About to start on the important stuff') I would like my log file to look a bit like: 2018-03-14 06:33:26:619 INFO aNiceFile

Log js file name and function name

不问归期 提交于 2021-02-04 20:59:21
问题 I would like my node.js project to generate log files that are a bit similar to log4j format in that I would like each log line to commence with the file name and the js function name that the log request originated from. e.g: If my js file is called aNiceFile.js and my js function is called doImportantStuff() and I invoke a log statement with something like: log.info('About to start on the important stuff') I would like my log file to look a bit like: 2018-03-14 06:33:26:619 INFO aNiceFile

How to make `winston` logging library work like `console.log`?

北城以北 提交于 2021-01-02 06:59:26
问题 The winston library is great for transports and flexibility. I'd like to use it to allow configuring levels and redirecting to files, but would like to reproduce console.log behavior for formatting, and having trouble. Here's what I have so far: const log = winston.createLogger({ level: 'debug', format: format.combine( format.timestamp({format: 'YYYY-MM-DD HH:mm:ss.SSS'}), format.splat(), format.colorize(), format.printf(({level, message, label, timestamp}) => `${timestamp} ${label || '-'} $

how to store logs into mysql db using winston in Node.js

大城市里の小女人 提交于 2020-12-31 06:19:29
问题 I am doing logging for my application using winston. I have done the file transport using this: class LoggerHelper extends BaseHelper { constructor(_cApp) { super(_cApp); this._props = {}; } initialize() { this._prepareConfigs(); this._createTransportObj(); this._createLoggerObj(); } _prepareConfigs() { this._props.dirname = this._configs.logsFolder; this._props.filename = this._configs.filenameConvention; this._props.datePattern = this._configs.datePattern; this._props.maxSize = this.

how to store logs into mysql db using winston in Node.js

耗尽温柔 提交于 2020-12-31 06:16:25
问题 I am doing logging for my application using winston. I have done the file transport using this: class LoggerHelper extends BaseHelper { constructor(_cApp) { super(_cApp); this._props = {}; } initialize() { this._prepareConfigs(); this._createTransportObj(); this._createLoggerObj(); } _prepareConfigs() { this._props.dirname = this._configs.logsFolder; this._props.filename = this._configs.filenameConvention; this._props.datePattern = this._configs.datePattern; this._props.maxSize = this.