-
Notifications
You must be signed in to change notification settings - Fork 21
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
6559508
commit adcd8f7
Showing
8 changed files
with
158 additions
and
84 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
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
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,78 +1,7 @@ | |||
var journald_lib = require('../build/Release/journald_lib') | var log_journald = require('./log_journald'), | ||
|
winston_journald = require('./winston_journald'); | ||
var noop = function() {}; | |||
|
|||
var journald = { | |||
send: function(args) { | |||
// Send log messages by passing an object as the first argument, | |||
// in the form: | |||
// | |||
// journald.send({ | |||
// MSG: 'Hello', | |||
// MSG2: 'World' | |||
// }); | |||
// | |||
if (typeof args[0] == 'object') { | |||
var strings = []; | |||
for (key in args[0]) { | |||
if (args[0].hasOwnProperty(key)) { | |||
if (typeof args[0][key] == 'string') { | |||
strings.push(key + '=' + args[0][key]); | |||
} | |||
else { | |||
throw { | |||
name: 'ArgumentsError', | |||
message: 'Object has non-string properties' | |||
} | |||
} | |||
} | |||
} | |||
if (strings.length > 1) { | |||
if (typeof args[1] == 'function') { | |||
strings.push(args[1]); | |||
} | |||
journald_lib.send.apply(this, strings); | |||
} | |||
return; | |||
} | |||
|
|||
// Arguments given as individual strings: | |||
// | |||
// journald.send('MSG=Hello', 'MSG2=World') | |||
// | |||
for (i = 0; i < args.length; i++) { | |||
if (typeof args[i] != 'string' && typeof args[i] != 'function') { | |||
throw { | |||
name: 'ArgumentsError', | |||
message: 'Non-string arguments given' | |||
} | |||
} | |||
} | |||
journald_lib.send.apply(this, args); | |||
return; | |||
} | |||
}; | |||
|
|
||
module.exports = { | module.exports = { | ||
log: function() { | Log: log_journald, | ||
if (arguments.length < 1) { | WinstonTransport: winston_journald | ||
throw { | |||
name: 'ArgumentsError', | |||
message: 'No arguments given' | |||
} | |||
} | |||
var args = []; | |||
for (i = 0; i < arguments.length; i++) { | |||
args.push(arguments[i]); | |||
} | |||
// If no callback is provided, add an empty one. | |||
if (typeof arguments[arguments.length-1] !== 'function') { | |||
args.push(noop); | |||
} | |||
journald.send(args); | |||
}, | |||
|
|||
// We don't support a sync version right now. But here's where it would go. | |||
// logSync: function() { | |||
// } | |||
} | } |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,78 @@ | |||
var journald_cpp = require('../build/Release/journald_cpp'); | |||
|
|||
var noop = function() {}; | |||
|
|||
var journald = { | |||
send: function(args) { | |||
// Send log messages by passing an object as the first argument, | |||
// in the form: | |||
// | |||
// journald.send({ | |||
// MSG: 'Hello', | |||
// MSG2: 'World' | |||
// }); | |||
// | |||
if (typeof args[0] == 'object') { | |||
var strings = []; | |||
for (key in args[0]) { | |||
if (args[0].hasOwnProperty(key)) { | |||
if (typeof args[0][key] == 'string') { | |||
strings.push(key + '=' + args[0][key]); | |||
} | |||
else { | |||
throw { | |||
name: 'ArgumentsError', | |||
message: 'Object has non-string properties' | |||
} | |||
} | |||
} | |||
} | |||
if (strings.length > 1) { | |||
if (typeof args[1] == 'function') { | |||
strings.push(args[1]); | |||
} | |||
journald_cpp.send.apply(this, strings); | |||
} | |||
return; | |||
} | |||
|
|||
// Arguments given as individual strings: | |||
// | |||
// journald.send('MSG=Hello', 'MSG2=World') | |||
// | |||
for (i = 0; i < args.length; i++) { | |||
if (typeof args[i] != 'string' && typeof args[i] != 'function') { | |||
throw { | |||
name: 'ArgumentsError', | |||
message: 'Non-string arguments given' | |||
} | |||
} | |||
} | |||
journald_cpp.send.apply(this, args); | |||
return; | |||
} | |||
}; | |||
|
|||
module.exports = { | |||
log: function() { | |||
if (arguments.length < 1) { | |||
throw { | |||
name: 'ArgumentsError', | |||
message: 'No arguments given' | |||
} | |||
} | |||
var args = []; | |||
for (i = 0; i < arguments.length; i++) { | |||
args.push(arguments[i]); | |||
} | |||
// If no callback is provided, add an empty one. | |||
if (typeof arguments[arguments.length-1] !== 'function') { | |||
args.push(noop); | |||
} | |||
journald.send(args); | |||
}, | |||
|
|||
// We don't support a sync version right now. But here's where it would go. | |||
// logSync: function() { | |||
// } | |||
} |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,35 @@ | |||
/** | |||
* | |||
* Winston Transport for outputting to the systemd journal. | |||
* | |||
* (C) 2012 Mark Theunissen | |||
* MIT (EXPAT) LICENCE | |||
* | |||
*/ | |||
|
|||
var util = require('util'), | |||
winston = require('winston'), | |||
Transport = require('winston').Transport, | |||
journald = require('./log_journald'); | |||
|
|||
var Journald = exports.Journald = function (options) { | |||
options = options || {}; | |||
|
|||
this.name = 'journald'; | |||
}; | |||
|
|||
// | |||
// Inherit from `winston.Transport`. | |||
// | |||
util.inherits(Journald, Transport); | |||
|
|||
// | |||
// Expose the name of this Transport on the prototype | |||
// | |||
Journald.prototype.name = 'journald'; | |||
|
|||
Journald.prototype.log = function (level, msg, meta, callback) { | |||
journald.log(msg); | |||
|
|||
callback(null, true); | |||
}; |
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
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
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