Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: wnoronha/winston-scribe
base: master
...
head fork: chitika/winston-scribe
compare: master
Checking mergeability… Don't worry, you can still create the pull request.
  • 5 commits
  • 2 files changed
  • 0 commit comments
  • 2 contributors
Showing with 16 additions and 5 deletions.
  1. +15 −4 lib/winston-scribe.js
  2. +1 −1  package.json
View
19 lib/winston-scribe.js
@@ -3,6 +3,10 @@ var winston = require('winston');
var scribe = require('scribe');
var os = require('os');
+function formatLogMessage(entry) {
+ return JSON.stringify(entry);
+}
+
var Scribe = exports.Scribe = function (options) {
options = options || {};
options.host = options.host || 'localhost';
@@ -11,13 +15,19 @@ var Scribe = exports.Scribe = function (options) {
this.name = 'scribe';
this.level = options.level || 'info';
this.category = options.category || 'winston';
+ this.formatter = options.formatter || formatLogMessage;
this.client = new scribe.Scribe(options.host, options.port, {autoReconnect:true});
this.isReady = false;
+ this.sendQueue = [];
var self = this;
this.client.open(function(err){
if(!err)
self.isReady = true;
+
+ for (var entry in self.sendQueue) {
+ self.client.send(self.category, self.formatter(self.sendQueue[entry]));
+ }
});
};
@@ -28,7 +38,7 @@ Scribe.prototype.log = function (level, msg, meta, callback) {
timestamp: (new Date()).toISOString(),
host: os.hostname(),
level: level,
- message: msg,
+ message: msg
};
if (meta) {
@@ -37,13 +47,14 @@ Scribe.prototype.log = function (level, msg, meta, callback) {
if (this.isReady){
this.emit('logged');
- this.client.send(this.category, JSON.stringify(entry));
+ this.client.send(this.category, this.formatter(entry));
return callback(null, true);
}
else
{
- this.emit('error', null);
- return callback("Error: Scribe is not ready yet.",null)
+ this.emit('queued');
+ this.sendQueue.push(entry);
+ return callback(null, true);
}
};
View
2  package.json
@@ -12,7 +12,7 @@
"winston",
"scribe"
],
- "version": "0.1.2",
+ "version": "0.1.3",
"homepage": "https://github.com/chitika/winston-scribe",
"repository": {
"type": "git",

No commit comments for this range

Something went wrong with that request. Please try again.