winston

How to get Winston daily file rotate to log to corresponding level file

风流意气都作罢 提交于 2019-12-02 06:53:11
问题 I have defined custom levels for my application .They are as follows. protected levels: Level = { "error": 0, "warn": 1, "info": 2, "debug": 3, "trace": 4 }; I am using daily file rotate transport to get daily log in separate files. const options: Object = { name: this.level, filename: logFilePath, dirname: WinstonLogAgent.DIR_LOG, datePattern: "yyyyMMdd.", prepend: true, level: this.level, levels: this.levels, maxsize: this.maxFileSize, maxFiles: this.maxFileCount, handleExceptions: true,

stream.write is not a function when using morgan with logger

a 夏天 提交于 2019-12-02 06:17:54
问题 Basically i am trying to implement logger for the nodejs , using morgan and winston. When i am trying to use morgan , throwing an error of stream.write is not a function. Since i want get the file name , i am passing the module, from module object there is a property called filename. Below is my code. // Winston.js const appRoot = require('app-root-path'); const { createLogger, format, transports } = require('winston'); const { combine, timestamp, label, printf } = format; const path =

How to get Winston daily file rotate to log to corresponding level file

断了今生、忘了曾经 提交于 2019-12-02 04:04:56
I have defined custom levels for my application .They are as follows. protected levels: Level = { "error": 0, "warn": 1, "info": 2, "debug": 3, "trace": 4 }; I am using daily file rotate transport to get daily log in separate files. const options: Object = { name: this.level, filename: logFilePath, dirname: WinstonLogAgent.DIR_LOG, datePattern: "yyyyMMdd.", prepend: true, level: this.level, levels: this.levels, maxsize: this.maxFileSize, maxFiles: this.maxFileCount, handleExceptions: true, humanReadableUnhandledException: true }; this.transportInstance.push(new (winston.transports

stream.write is not a function when using morgan with logger

荒凉一梦 提交于 2019-12-02 03:53:47
Basically i am trying to implement logger for the nodejs , using morgan and winston. When i am trying to use morgan , throwing an error of stream.write is not a function. Since i want get the file name , i am passing the module, from module object there is a property called filename. Below is my code. // Winston.js const appRoot = require('app-root-path'); const { createLogger, format, transports } = require('winston'); const { combine, timestamp, label, printf } = format; const path = require('path'); // Custom Format const customFormat = printf(info => { return `${new Date(info.timestamp)} |

Winston Logging - separate levels to separate Transports

断了今生、忘了曾经 提交于 2019-12-01 22:20:50
问题 I am using Winston for logging with 2 different transports - File and MongoDB. I have set the level for File as "INFO" and for MongoDB as "ERROR". If I now log, log.info('some info...'); log.warn('some Warning...'); log.error('some error...'); All of these would go to the LogFile, and only Error would go to DB. I want only Info messages to go to File, and none other. I understand the system log levels in Winston, and that only Error goes to MongoDB because its the highest level. Since, INFO

How do I get Winston to work with Webpack?

我是研究僧i 提交于 2019-11-30 19:18:34
I have an electron application which is using node.js. I would like to use Winston for logging in the application. I've added winston to my package.json file, but when I run the build command for webpack I'm getting some warnings from the colors.js dependency in winston. '...the request of a dependency is an expression...' It then references winston and colors.js. Ignoring the warnings doesn't work, as the electron application gets an exception trying to load some files from winston. I did some digging on SO and the github site and they say that colors.js has some dynamic require statements

How to append a unique_id to my express node logs with winston without refactoring everything?

无人久伴 提交于 2019-11-30 14:45:19
I've an Express app. I'd like to trace all the loggings that were made by a single request. Apache has a module called mod_unique_id which injects in the request headers a special one containing a unique hash. I'd like to use such hash when logging (anything). For example if an user is assigned by apache the unique_id valued "abcdefg" and somewhere in my code (controller, model, or anything) i generate a debug log i'd like to have "abcdefg" attached to every log entry. The only idea that pops in my mind is to create a logger instance using app.use() and pass that logger instance to ALL the

How to append a unique_id to my express node logs with winston without refactoring everything?

馋奶兔 提交于 2019-11-29 21:08:51
问题 I've an Express app. I'd like to trace all the loggings that were made by a single request. Apache has a module called mod_unique_id which injects in the request headers a special one containing a unique hash. I'd like to use such hash when logging (anything). For example if an user is assigned by apache the unique_id valued "abcdefg" and somewhere in my code (controller, model, or anything) i generate a debug log i'd like to have "abcdefg" attached to every log entry. The only idea that pops

using winston in several modules

我是研究僧i 提交于 2019-11-29 19:48:46
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! Nick The default logger concept handles this nicely. Winston defines a default logger that any straight require (and subsequent require) to winston will retrieve. Thus you simply configure this default

Multiple log files with Winston?

浪子不回头ぞ 提交于 2019-11-28 20:39:20
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? pesho I just sent a pull request that allows using multiple File transports in one logger. https://github.com/flatiron/winston/pull/149 It is already merged into flatiron/winston. You can also use my forked repo: https://github.com