Log to the console (equivalent to console.log
)
Log to the console (equivalent to console.log
)
log: function() {
if (process.env.LOG_LEVEL >= levels.ALL) {
_log.apply(null, arguments);
}
},
Log error to the console (equivalent to console.error
)
error: function() {
if (process.env.LOG_LEVEL >= levels.ERROR) {
_error.apply(null, arguments);
}
},
Log warning to the console (equivalent to console.warn
)
warn: function() {
if (process.env.LOG_LEVEL >= levels.WARN) {
_warn.apply(null, arguments);
}
},
Log info to the console (equivalent to console.info
)
info: function() {
if (process.env.LOG_LEVEL >= levels.INFO) {
_info.apply(null, arguments);
}
},
Print out all messages retrieved from splunkd
printMessages: function(allMessages) {
allMessages = allMessages || [];
for(var i = 0; i < allMessages.length; i++) {
var message = allMessages[i];
var type = message["type"];
var text = message["text"];
var msg = '[SPLUNKD] ' + text;
switch (type) {
case 'HTTP':
case 'FATAL':
case 'ERROR':
this.error(msg);
break;
case 'WARN':
this.warn(msg);
break;
case 'INFO':
this.info(msg);
break;
case 'HTTP':
this.error(msg);
break;
default:
this.info(msg);
break;
}
}
},
Set the global logging level
Name | Type | Description |
---|---|---|
level | String,Number | A string ( |
splunkjs.Logger.setLevel("WARN");
splunkjs.Logger.setLevel(0); // equivalent to NONE
setLevel: function(level) {
if (utils.isString(level)) {
if (levels.hasOwnProperty(level)) {
process.env.LOG_LEVEL = levels[level];
}
else {
process.env.LOG_LEVEL = levels["ERROR"];
}
}
else if (utils.isNumber(level)) {
process.env.LOG_LEVEL = level;
}
else {
process.env.LOG_LEVEL = levels["ERROR"];
}
},