winston

Winston logger not write to file

我怕爱的太早我们不能终老 提交于 2019-12-23 02:31:09
问题 I want to use winston logger in node app for log error to file. But winston not write to file. var logger = new (winston.Logger)({ transports: [ new (winston.transports.Console)(), new (winston.transports.File)({ filename: 'somefile.log' }) ] }); logger.error('test'); file somefile.log is created but empty. 回答1: You need to define a level in the constructor. var tsFormat = () => (new Date()).toLocaleTimeString(); var log = new (winston.Logger)({ transports: [ new (winston.transports.Console)(

Winston : understanding logging levels

梦想的初衷 提交于 2019-12-21 07:14:05
问题 Reading and fiddling with Winston, I'm puzzled as to why the logging levels are ordered as they are and why the transports behave in the way they do (well, at least the Console one). I'd appreciate if someone could, perhaps even thoroughly, with real use case examples, explain why logging with Winston works this way? For example, I setup my logger like this : var logger = new (winston.Logger)({ levels: winston.config.syslog.levels, colors: winston.config.syslog.colors, level: "debug", // I'm

How to Log Full Stack Trace with Winston 3?

放肆的年华 提交于 2019-12-20 11:14:03
问题 My logger is set up like: const myFormat = printf(info => { return `${info.timestamp}: ${info.level}: ${info.message}: ${info.err}`; }); const logger = winston.createLogger({ level: "info", format: combine(timestamp(), myFormat), transports: [ new winston.transports.File({ filename: "./logger/error.log", level: "error" }), new winston.transports.File({ filename: "./logger/info.log", level: "info" }) ] }) Then I am logging out some error like this: logger.error(`GET on /history`, { err }); How

using winston in several modules

回眸只為那壹抹淺笑 提交于 2019-12-18 10:06:15
问题 I have several modules - let's say server.js, module1.js,...,moduleN.js. I would like define the log file in my server.js: winston.add(winston.transports.File, { filename: 'mylogfile.log' }); and then use it in all my modules. What is the best way to do that? I could exports.winston=winston; in each module and then set it in the server.js, but is there any better solution? Thank you in advance! 回答1: The default logger concept handles this nicely. Winston defines a default logger that any

Multiple log files with Winston?

ぐ巨炮叔叔 提交于 2019-12-17 23:11:43
问题 We'd like to use Winston for our logging in Node.js. But, we can't figure out how to have two log files: one for just errors, and one for everything else. Doing this the naive way doesn't work, however: adding multiple winston.transports.File transports gives an error. Others have run into this problem, with vague hints of a solution, but no real answer. Any ideas? 回答1: I just sent a pull request that allows using multiple File transports in one logger. https://github.com/flatiron/winston

Node.js - logging / Use morgan and winston

不羁岁月 提交于 2019-12-17 17:23:58
问题 we use morgan in order to log our express transformation: var morgan = require('morgan'); morgan('combined'); // a format string morgan(':remote-addr :method :url :uuid'); // a custom function morgan(function (req, res) { return req.method + ' ' + req.url + ' ' + req.uuid; }) Also, we use winston in order to log our other logging: var winston = require('winston'); var logger = new (winston.Logger)({ transports: [ new (winston.transports.Console)({ level: 'info' }), new (winston.transports

Create Channel Switch Logger

大憨熊 提交于 2019-12-14 00:07:42
问题 I'm trying to create a channel switch logger which allows me to specify a channel where the messages get posted. So, for example, I create a TextChannel called "Channel Switches". When now a user changes voice channel, it should appear a message in this Channel. (eg. <USER> left channel <CHANNEL> and joined <CHANNEL>. ) MY PROBLEM IS: I get no errors and the Bot is not responding... Here my first try: var Discord = require('discord.js'); var logger = require("winston"); var auth = require(".

How to flush winston logs?

北城以北 提交于 2019-12-13 11:35:40
问题 I want to flush the winston logger before process.exit . process.on('uncaughtException', function(err){ logger.error('Fatal uncaught exception crashed cluster', err); logger.flush(function(){ // <- process.exit(1); }); }); Is there anything like logger.flush available? I couldn't find anything about it, other than people complaining about winston not being very actively maintained. As an alternative, is there any popular (actively maintained) multi-transport logging framework that provides a

No log files are being created using winston node js library

不羁岁月 提交于 2019-12-12 19:23:08
问题 I am working in node js and using Winston library for logging. The following code does not create a log file. var winston = require('winston'); var logger = winston.createLogger({ transports: [ new winston.transports.File({ level: 'info', filename: './logs/all-logs.log', handleExceptions: true, json: true, maxsize: 5242880, //5MB maxFiles: 5, colorize: false }), new winston.transports.Console({ level: 'debug', handleExceptions: true, json: false, colorize: true }) ], exitOnError: false });

Node js logging - winston.Logger is not a constructor

别说谁变了你拦得住时间么 提交于 2019-12-12 10:28:53
问题 I am applying logger in node js application using Winston but getting winston.Logger is not a constructor. I am following the link below http://thisdavej.com/using-winston-a-versatile-logging-library-for-node-js/ 回答1: Try something like below code, it should work (it might have happened since you have been using an older code for the newer version): const winston = require('winston'); require('winston-daily-rotate-file'); function getLogger(module) { const transport = new winston.transports