winston

How to properly use Winston

隐身守侯 提交于 2020-08-03 02:15:55
问题 I have read the docs for logging in node.js using the winston package. My question: Do I need to add my logging module to every single page that requires logging.. or does winston somehow intercept console.log and console.error . thanks for your time. 回答1: Normally, you'd need to require your logger in the modules that use it. However, you can follow the suggestion made by @spmason in the gist logging.js or what @fega suggests in his comment to redefine the properties of the console Object:

How to properly use Winston

泪湿孤枕 提交于 2020-08-03 02:14:51
问题 I have read the docs for logging in node.js using the winston package. My question: Do I need to add my logging module to every single page that requires logging.. or does winston somehow intercept console.log and console.error . thanks for your time. 回答1: Normally, you'd need to require your logger in the modules that use it. However, you can follow the suggestion made by @spmason in the gist logging.js or what @fega suggests in his comment to redefine the properties of the console Object:

How to properly use Winston

独自空忆成欢 提交于 2020-08-03 02:14:21
问题 I have read the docs for logging in node.js using the winston package. My question: Do I need to add my logging module to every single page that requires logging.. or does winston somehow intercept console.log and console.error . thanks for your time. 回答1: Normally, you'd need to require your logger in the modules that use it. However, you can follow the suggestion made by @spmason in the gist logging.js or what @fega suggests in his comment to redefine the properties of the console Object:

How to log Unhandled TimeoutError in Winstonjs logger?

限于喜欢 提交于 2020-07-22 22:11:03
问题 I've got a node application in which I use Winstonjs as a logger. In my logger I've got a specific part for logging exceptions like this: const myFormat = winston.format.printf(info => { return `${info.timestamp} ${info.level}: ${info.message}`; }); const logger = winston.createLogger({ level: "debug", format: winston.format.combine(winston.format.timestamp(), myFormat), // winston.format.json(), transports: [ new winston.transports.File({filename: "logs/error.log", level: 'error'}), new

How to log Unhandled TimeoutError in Winstonjs logger?

喜欢而已 提交于 2020-07-22 22:10:56
问题 I've got a node application in which I use Winstonjs as a logger. In my logger I've got a specific part for logging exceptions like this: const myFormat = winston.format.printf(info => { return `${info.timestamp} ${info.level}: ${info.message}`; }); const logger = winston.createLogger({ level: "debug", format: winston.format.combine(winston.format.timestamp(), myFormat), // winston.format.json(), transports: [ new winston.transports.File({filename: "logs/error.log", level: 'error'}), new

How to set log level in Winston/Node.js

萝らか妹 提交于 2020-05-25 05:44:45
问题 I am using Winston logging with my Node.js app and have defined a file transport. Throughout my code, I log using either logger.error , logger.warn , or logger.info . My question is, how do I specify the log level? Is there a config file and value that I can set so that only the appropriate log messages are logged? For example, I'd like the log level to be "info" in my development environment but "error" in production. 回答1: Looks like there is a level option in the options passed covered here

How to set log level in Winston/Node.js

丶灬走出姿态 提交于 2020-05-25 05:44:22
问题 I am using Winston logging with my Node.js app and have defined a file transport. Throughout my code, I log using either logger.error , logger.warn , or logger.info . My question is, how do I specify the log level? Is there a config file and value that I can set so that only the appropriate log messages are logged? For example, I'd like the log level to be "info" in my development environment but "error" in production. 回答1: Looks like there is a level option in the options passed covered here

Disable winston logging when running unit tests?

半世苍凉 提交于 2020-05-25 03:31:30
问题 Can Winston logging be selectively disabled when executing unit tests of a node module? Ideally, I'd like to have logging for informational and debug purposes when the application is running, but be suppressed as to not clutter the presentation unit test results when I run my tests. My use of winston is internal to my module, something like this: // MyModule.js var logger = require('winston'); module.exports = function() { // does some stuff // and logs some stuff like so: logger.log('an

Explain use of levels in winston logger

拜拜、爱过 提交于 2020-04-30 08:10:10
问题 Hey i am using this winston logger, kindly explain use of level inside the transports, what will happen if i use logger with info while logging, do i have to use debug while i log my data. var logger = new (winston.Logger)({ transports: [ new (winston.transports.Console)({ level: 'debug', json: true }), new (winston.transports.File)({ name: 'order_check', filename: './logs/order_check.log', level: 'debug' }) ] }); logger.log("info","request body"); 回答1: The level inside your transport

How to use Jest to mock winston logger instance encapsulated in service class

时光总嘲笑我的痴心妄想 提交于 2020-03-05 04:06:13
问题 I am trying to mock a winston.Logger instance that is encapsulated within a service class created with NestJS. I have included my code below. I cannot get the mocked logger instance to be triggered from within the service class. Can anyone explain where I am going wrong? import * as winston from 'winston'; import { loggerOptions } from '../logger/logger.config'; import { LoggingService } from '../logger/logger.service'; const logger: winston.Logger = winston.createLogger(loggerOptions); //