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
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)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With