Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Querying Winston Logs

I am using winston for logging in a node.js application.

I see there are options to query it.

The example shows how to use options from and to.

My question is

  1. What are the other options ?
  2. How do I specify what file should be queried ?
like image 906
Anand Sunderraman Avatar asked Jul 19 '13 20:07

Anand Sunderraman


Video Answer


2 Answers

I ran into this same problem.

At least some of the options can be found in Winston's transport.js in the function Transport.prototype.normalizeQuery.

Here's a quick summary:

options.rows, options.limit = how many results to return. default is 10;

options.start = starting row offset. default is 0

options.from = date string or date object for starting limit. default is now -24 hours

options.until = date string or date object for ending limit. default is now

options.order = either 'asc' or 'desc' order. default is 'desc'

options.fields = which fields to return. default is undefined (which returns all)

like image 109
JoeAndrieu Avatar answered Oct 05 '22 18:10

JoeAndrieu


Here's an example of querying file logger + available options. The main drawback (IMO) is lack of filtering. The most useful feature would be filtering by level but alas...

"use strict";

var logFilename = __dirname + '/log/2014-02-24.log';

var winston = require('winston');
var logger = new (winston.Logger)({
    transports: [
        new (winston.transports.File)({
            filename:  logFilename,
            timestamp: true
        })
    ]
});

var options = {
    from:   new Date - 24 * 60 * 60 * 1000,
    until:  new Date,
    limit:  10,
    start:  0,
    order:  'asc',
    fields: ['message']
};
logger.query(options, function (err, result) {
    if (err) {
        throw err;
    }

    console.log(result);
});

P.S. BTW, here's an open issue about querying logs.

like image 28
dVaffection Avatar answered Oct 05 '22 19:10

dVaffection