EzDevInfo.com

winston

a multi-transport async logging library for node.js winstonjs/winston · GitHub winston - a multi-transport async logging library for node.js

How to setup log level in Winston/Node.js?

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.


Source: (StackOverflow)

winston:how to change timestamp format

I am using winston to add log details in node.js, i used the following procedure to add the logs

 var winston = require('winston');         
 winston.remove(winston.transports.Console);
 winston.add(winston.transports.Console, {'timestamp':true,'colorize':true);
 winston.log('info','jjjj');

the output that i got is

2012-12-21T09:32:05.428Z - info: jjjj

I need to specify a format for mytimestamp , is there any provision to do so in winston any help will be much appreciated


Source: (StackOverflow)

Advertisements

It is possible to do hourly log rotation in Winston?

Hi i have a requirement from our production team, I need to create the logs hourly, I know that winston support daily, but this doesn't help me. It is possible to do this?


Source: (StackOverflow)

Logging with Winston in Express.js - how to configure for different environments?

I've started to use Winston for logging errors and events with my node/express.js app.

One thing I have not figured out is how to specify different Winston transports (or other config) for different environments (Dev/Test/Production). E.g. I want to have everything logged to the console in the dev enviroment, but use a different transport in Production.

Anyone know how to do this?


Source: (StackOverflow)

NodeJS/Forever archive logs

I am using forever to run my node application. When I start forever I specify where to write the logs. I also specify to append to the log. Problem here is that my log is going to grow out of control over the course of months.

Is there any way to archive/roll logs on an interval, i.e. every day roll/archive what is in the log file to another file (i.e. server-2013-3-5.log). That way I can delete/move off old log files as needed.

I have just started looking into using Winston for my logger and I have not come across anything there that would help.

Any ideas?


Source: (StackOverflow)

Multiple log files with Winston?

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?


Source: (StackOverflow)

How to flush winston logs?

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 flushing capability?


Source: (StackOverflow)

How can I add timestamp to logs using node.js library Winston? [closed]

I want to add timestamp to logs, what is the best way to achieve it?


Source: (StackOverflow)

using winston in several modules

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!


Source: (StackOverflow)

Much needed: well-highlighted JSON log viewer

Using winston for node.js logging, I get json log files. A log file in this vein is simply a sequence of (newline delimited) json objects. This is great for log querying and treating logs as first-class data!

However, both Sublime and gedit (at least the versions of them I'm using on Ubuntu, sublime 2 and gedit 3.6.2), poorly highlight json - they use the same color for keys and values, making any log drilling quite painful and really impossible to go through in any remotely humane manner.

Existing chrome extensions for json highlighting aren't helpful here either - they can't handle a collection of json objects and thus fail displaying these log files unless I manually turn them into an array within a synthetic parent object first (thus turning them into a json object). This is tedious in the case of viewing a log file that is still being written to and in general......

Is there any tool that can both swallow json log files as is, and at the same time highlight keys in a different color than values, so that json logs are also friendly to man, not only to machine?? this is a real pain.

Thanks!


Source: (StackOverflow)

Winston Logging with Mongoose Docs

I recently just switched over to Winston for logging and noticed an issue when logging mongoose docs after an exec.

Example:

Model.find().exec(function (err, docs) {
    console.log(docs) // Prints the collection fine
    winston.info(docs) // Prints a ton on mongoose stuff, related to the query
});

So basically how do I get winston logging to print the same way as you get from console.log? I'm guessing it must how it is being serialised before being logged by calling toJSON().

Do I have to manually call .toJSON() each time or have people done something else to make this work automatically?


Source: (StackOverflow)

What is the default location of Winston logs?

I am using something like this:

var winston = require('winston'), logger = new (winston.Logger)({
  transports: [
    new (winston.transports.Console) (),
    new (winston.transports.File) ({filename: 'test.log'})
  ]
});

logger.log('Hello world');

I cannot find the log file test.log anywhere on my system and no exception or info in the console either.


Source: (StackOverflow)

Unable to Save Logs to mongodb Database for winston-nodejs

I am using the winston library: https://github.com/flatiron/winston Attempting to store data to the mongodb database with: https://github.com/indexzero/winston-mongodb

to insert the data I use:

var MongoDB = require('winston-mongodb').MongoDB;
var logger = new (winston.Logger)({
transports: [
    new (winston.transports.Console)(),
    new (winston.transports.MongoDB)({ host: ip,  db: 'caribcultivate', collection: 'log', level: 'info'})
], exceptionHandlers: [ new winston.transports.Console() ]
});
logger.log('info', "Running logs "+ d);
logger.info("Drive: "+ (new Date(d)).toDateString());

However when I try to query the data using:

winston.query(options, function (err, results) {
    if (err) {console.log(err);}
    console.log(results);
});

I get:

{}

It works for the Console correctly, and I am using the database in other parts of the application with the Mongoose library.


Source: (StackOverflow)

How do you add multiple levels to a single transport in Winston?

How does one tell Winston to log multiple levels to a single transport? For example, if you want to log both info and error level items to the console, how would you accomplish this? Specifying info does not log all levels that are info level and more critical, it just logs info. Passing an array of levels to the level property does nothing.

winston.add(winston.transports.Console, {
    colorize: true,
    level: 'info'
});

or

winston.add(winstonMongo, {
    safe: false,
    db: 'logs',
    collection: 'api',
    level: 'info'
});

Source: (StackOverflow)

I want to display the file Name in the log statement

For every logger statement with any level, I need to display the file name from where the log statement executed, below is the illustration I given below:

Example : Below is the line executed from JobWork.js

logger.info("getInCompleteJobs in job works");

Actual :

2012-11-05T06:07:19.158Z - info: getInCompleteJobs in job works

Required :

2012-11-05T06:07:19.158Z - info JobWork.js : getInCompleteJobs in job works

Without passing the fileName as a parameter from the log statement it should give the filename.


Source: (StackOverflow)