Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
var util = require('util'); | ||
var winston = require('winston'); | ||
var scribe = require('scribe'); | ||
var os = require('os'); | ||
|
||
var Scribe = exports.Scribe = function (options) { | ||
options = options || {}; | ||
options.host = options.host || 'localhost'; | ||
options.port = options.port || 1463; | ||
|
||
this.name = 'scribe'; | ||
this.level = options.level || 'info'; | ||
this.category = options.category || 'winston'; | ||
this.client = new scribe.Scribe(options.host, options.port, {autoReconnect:true}); | ||
this.isReady = false; | ||
|
||
var self = this; | ||
this.client.open(function(err){ | ||
if(!err) | ||
self.isReady = true; | ||
}); | ||
}; | ||
|
||
util.inherits(Scribe, winston.Transport); | ||
Scribe.prototype.log = function (level, msg, meta, callback) { | ||
|
||
var entry = { | ||
timestamp: (new Date()).toISOString(), | ||
host: os.hostname(), | ||
level: level, | ||
message: msg, | ||
}; | ||
|
||
if (meta) { | ||
entry.meta = meta; | ||
} | ||
|
||
if (this.isReady){ | ||
this.emit('logged'); | ||
this.client.send(this.category, JSON.stringify(entry)); | ||
return callback(null, true); | ||
} | ||
else | ||
{ | ||
this.emit('error', null); | ||
return callback("Error: Scribe is not ready yet.",null) | ||
} | ||
}; | ||
|
||
winston.transports.Scribe = Scribe; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"author": { | ||
"name": "Warren Noronha", | ||
"email": "warren.noronha@gmail.com" | ||
}, | ||
"name": "winston-scribe", | ||
"description": "A scribe transport for winston", | ||
"keywords": [ | ||
"logging", | ||
"sysadmin", | ||
"tools", | ||
"winston", | ||
"scribe" | ||
], | ||
"version": "0.1.2", | ||
"homepage": "https://github.com/chitika/winston-scribe", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/chitika/winston-scribe.git" | ||
}, | ||
"main": "./lib/winston-scribe", | ||
"dependencies": { | ||
"scribe": "0.0.2" | ||
}, | ||
"engines": { | ||
"node": ">= 0.4.0" | ||
}, | ||
"readme": "ERROR: No README data found!", | ||
"readmeFilename": "README", | ||
"bugs": { | ||
"url": "https://github.com/chitika/winston-scribe/issues" | ||
}, | ||
"_id": "winston-scribe@0.1.2", | ||
"dist": { | ||
"shasum": "ef0440ef7a1a3c6f3a767f7622bfcbf942ef2eda" | ||
}, | ||
"_from": "winston-scribe@", | ||
"_resolved": "https://registry.npmjs.org/winston-scribe/-/winston-scribe-0.1.2.tgz" | ||
} |