-
Notifications
You must be signed in to change notification settings - Fork 5
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
1 parent
33e580e
commit 786b35d
Showing
4 changed files
with
99 additions
and
2 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
node_modules/* | ||
winser*tgz | ||
*tgz | ||
npm-debug.log |
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,75 @@ | ||
/* | ||
* eventlog.js: Transport for outputting to the Windows Event Log | ||
* | ||
* (C) 2012 Jose Fernando Romaniello | ||
* MIT LICENCE | ||
* | ||
*/ | ||
|
||
var events = require('events'), | ||
util = require('util'), | ||
Transport = require('winston').Transport, | ||
exec = require("child_process").exec, | ||
levelsMap = {"info": "information", "warn": "warning", "warning": "warning", "error": "error"}, | ||
isWindows = require("os").platform() === "win32"; | ||
|
||
// | ||
// ### function EventLog (options) | ||
// #### @options {Object} Options for this instance. | ||
// Constructor function for the EventLog transport object responsible | ||
// for persisting log messages and metadata to the windows event log. | ||
// | ||
var EventLog = exports.EventLog = function (options) { | ||
Transport.call(this, options); | ||
options = options || {}; | ||
|
||
this.name = 'eventlog'; | ||
this.eventlog = options.eventlog || "application"; //system is also valid. | ||
this.appName = options.appName || "node"; //system is also valid | ||
this.json = options.json || false; | ||
this.timestamp = typeof options.timestamp !== 'undefined' ? options.timestamp : false; | ||
|
||
if (this.json) { | ||
this.stringify = options.stringify || function (obj) { | ||
return JSON.stringify(obj, null, 2); | ||
}; | ||
} | ||
}; | ||
|
||
// | ||
// Inherit from `winston.Transport`. | ||
// | ||
util.inherits(EventLog, Transport); | ||
|
||
// | ||
// Expose the name of this Transport on the prototype | ||
// | ||
EventLog.prototype.name = 'eventlog'; | ||
|
||
// | ||
// ### function log (level, msg, [meta], callback) | ||
// #### @level {string} Level at which to log the message. | ||
// #### @msg {string} Message to log | ||
// #### @meta {Object} **Optional** Additional metadata to attach | ||
// #### @callback {function} Continuation to respond to when complete. | ||
// Core logging method exposed to Winston. Metadata is optional. | ||
// | ||
EventLog.prototype.log = function (level, msg, meta, callback) { | ||
if (this.silent || !isWindows) { | ||
return callback(null, true); | ||
} | ||
|
||
var self = this, | ||
output, | ||
message = msg + (meta ? ("" + "metadata: " + JSON.stringify(meta)) : ""), | ||
mapedlevel = levelsMap[level] || "information"; | ||
|
||
exec("eventcreate /t " + mapedlevel + " /id 100 /l " + this.eventlog + " /d \"" + message + "\" /so " + this.appName, function(err, stdout, stderr){ | ||
self.emit('logged'); | ||
}); | ||
|
||
|
||
callback(null, true); | ||
}; | ||
|
||
exports.config = require("./windowslogs-config"); |
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,21 @@ | ||
/* | ||
* windowslogs-config.js: Config that conform to commonly used Windows logging levels. | ||
* | ||
* (C) 2012 Jose Fernando Romaniello | ||
* MIT LICENCE | ||
* | ||
*/ | ||
|
||
var winlogconfig = exports; | ||
|
||
winlogconfig.levels = { | ||
info: 0, | ||
warning: 1, | ||
error: 2 | ||
}; | ||
|
||
winlogconfig.colors = { | ||
info: 'green', | ||
warning: 'yellow', | ||
error: 'red' | ||
}; |
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 |
---|---|---|
|
@@ -16,5 +16,6 @@ | |
}, | ||
"dependencies": { | ||
"winston" : "*" | ||
} | ||
}, | ||
"main": "./lib/eventlog" | ||
} |