Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fluent-logger-node, work with winston > .0.7.1 and add timestamp option #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions lib/winston-fluent.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

var util = require('util');
var fluentLogger = require('fluent-logger');
var fluentLogger = require('fluent-logger-node');
var winston = require('winston');

//
Expand All @@ -29,14 +29,20 @@ var Fluent = exports.Fluent = function (options) {
// Set transport name
this.name = 'fluent';


//
// Merge the options for the target Fluent server.
//
this.tag = options.tag;
this.label = options.label;
this.options = options.options;
this.options = options;

this.fluentSender = fluentLogger.createFluentSender(this.tag, this.options);
// Enable/Disable timestamping of each log event
this.timestamp = options.timestamp || false

/* fluent-logger-node to not break existing API*/
this.options.tagPrefix = this.tag
this.fluentSender = fluentLogger.createLogger( this.options);
};

//
Expand Down Expand Up @@ -69,8 +75,11 @@ Fluent.prototype.log = function (level, msg, meta, callback) {
data = clone(meta) || {};
data.level = level;
data.message = msg;

if( this.timestamp == true )
data['@timestamp'] = new Date()

this.fluentSender.emit(this.label, data, function(err) {
this.fluentSender.post(this.label, data, function(err) {
if (err) return self.emit('error', err);
if (self.fluentSender._sendQueue.length === 0) return self.emit('logged');
});
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
"td-agent"
],
"dependencies": {
"fluent-logger": "~0.2.3"
"fluent-logger-node": "0.0.3"
},
"devDependencies": {
"vows": "~0.7.0"
},
"peerDependencies": {
"winston": ">=0.5.0 <0.7.1"
"winston": "^0.8.0"
},
"main": "./lib/winston-fluent",
"scripts": {
Expand Down