winston

NodeJS Logger: winston.transports.DailyRotateFile is not a function

无人久伴 提交于 2019-12-11 00:45:44
问题 I'm writing a rest api with NodeJS and express and I'm using express-winston to log accesses and erros. But I want to separate de log daily. Like in this post I'm trying to do so with winston.transports.DailyRotateFile. A piece of code below. api.use(expressWinston.logger({ transports: [ new winston.transports.DailyRotateFile({ name: 'file', datePattern: '.yyyy-MM-ddTHH', filename: path.join(__dirname, "log-access", "log_file.log") }) ] })); Then I receive the error: winston.transports

How can I limit the winston log files to a specific number

╄→гoц情女王★ 提交于 2019-12-10 17:53:55
问题 I am thinking of using the log rotation feature of Winston. Is there any way to limit the number of log files. For example if I am rotating files daily, is there a way to specify I want to keep only logs for last three days ? 回答1: From the comments - @Aleksandr M maxFiles is that property. It could read like this: dailyRotateFile: { colorize: false, timestamp: true, datePattern: '.yyyy-MM-ddTHH-mm', filename: filename, maxFiles: 5, maxsize: 100000000, json: false } 来源: https://stackoverflow

Firebase functions: logging with winston in stackdriver console

穿精又带淫゛_ 提交于 2019-12-10 16:34:47
问题 I cannot make winston logger to write logs to stackdriver console. I deploy my functions as google firebase functions (using firebase deploy). console logging works fine, but we don't use such tool in the project. What I tried: output to stderr using https://github.com/greglearns/winston-stderr using https://www.npmjs.com/package/@google-cloud/logging-winston (both winston.add(require('@google-cloud/logging-winston')); winston.log('error', 'Winston error!'); and also adding with parameters

Logging with winston-mongodb and express-winston

本秂侑毒 提交于 2019-12-10 14:52:42
问题 I'm trying to log request/response into MongoDB within NodeJS project using express-winston and winston-mongodb. Here is an example code that I worked so far; const expressWinston = require('express-winston'); const winston = require('winston'); require('winston-mongodb').MongoDB; const logger = expressWinston.logger({ transports: [ winston.add(winston.transports.MongoDB, { db : 'something', collection : 'something', level : 'info', capped : true }) ] }); I'm exporting this logger and using

How are you supposed to create Winston logger stream for Morgan in TypeScript

一世执手 提交于 2019-12-10 13:28:01
问题 What is the correct way to create a winston logger in TypeScript that will log the express Morgan middleware logging? I found a number of JavaScript samples but have had trouble converting them over to TypeScript, because I get an error Type '{ write: (message: string, encoding: any) => {}; logger: any; }' is not assignable to type '(options?: any) => ReadableStream'. Object literal may only specify known properties, and 'write' does not exist in type '(options?: any) => ReadableStream'. Here

How to daily rotate logs using Winston except the first day

佐手、 提交于 2019-12-10 12:32:18
问题 I need to rotate the logs daily except the file for current day. I'm using winston and winston-daily-rotate-file libraries. In the following example, a file "info.log.2016-08-09" is generated just the first time I execute node. But, I really need to generate the file "info.log", and after this day, should be renamed to "info.log.2016-08-09", and create a new "info.log" for the current day. I understant that this is the normal behaviour in other applications. var logger = new (winston.Logger)(

TypeError: winston.Logger is not a constructor with winston and morgan

夙愿已清 提交于 2019-12-10 12:27:57
问题 I tried with Winston for logger . I used in one project their It's working well when I copy paste the code from their to the current existing project than I face an issue like TypeError: winston.Logger is not a constructor let logger = new (winston.Logger)({ ^ TypeError: winston.Logger is not a constructor Please guide me, Why this error and what should I have to do for solving this issue. "morgan": "^1.9.0", "winston": "^3.0.0" Following is my code in logger.js file. var appRoot = require(

Best practice to let users inject a logger into nodejs modules

不打扰是莪最后的温柔 提交于 2019-12-08 20:23:49
问题 I wrote this module for nodejs that can be used to dispatch events from anywhere via sockjs to the clients. Now I'd like to include some configurable logging mechanisms. At the moment, I'm adding winston as a dependency, require it as a logger in each class and use logger.error, logger.warn, ... #logger.js var logger = require('winston'); module.exports=logger; and #myClass var logger = require("./logger"); logger.error("Something went wrong") Now, how can I make the logger be replaceable by

Set default winston logger for all modules

巧了我就是萌 提交于 2019-12-08 07:54:58
问题 I am trying to setup winston to work in all my modules in the same fashion as in here: using winston in several modules But I am running in problems. I have setup a logger.js file to configure the console logger: var winston = require('winston'); var logger = new (winston.Logger)({ transports: [ new (winston.transports.Console)({ timestamp: true, level: 'verbose', colorize: true }) ] }); module.exports = logger; I then require that logger in my main app.js file: var logger = require('./logger

Error logs are not passed to the error log file when debug logs does. Why does that happen?

烈酒焚心 提交于 2019-12-08 05:34:20
问题 I am trying to create a simple logger class with Winston. I created two loggers named Logger and Error which extends from Logger . The Logger class by default creates all the logs in al-logs.log and Error class when extending from Logger adds an additional transport to create all error logs inside error-logs.log . But no logs are created inside error-logs.log . What am I missing? Here is what I did: First, I created the Logger class: class Logger { constructor(serviceName, label = "") { this