discord-baymax-bot/node_modules/log4js/examples/hipchat-appender.js

55 lines
1.7 KiB
JavaScript
Raw Permalink Normal View History

2017-03-24 04:52:08 +00:00
/**
* !!! The hipchat-appender requires `hipchat-notifier` from npm, e.g.
* - list as a dependency in your application's package.json ||
* - npm install hipchat-notifier
*/
var log4js = require('../lib/log4js');
log4js.configure({
"appenders": [
{
"type" : "hipchat",
"hipchat_token": process.env.HIPCHAT_TOKEN || '< User token with Notification Privileges >',
"hipchat_room": process.env.HIPCHAT_ROOM || '< Room ID or Name >'
}
]
});
var logger = log4js.getLogger("hipchat");
logger.warn("Test Warn message");
logger.info("Test Info message");
logger.debug("Test Debug Message");
logger.trace("Test Trace Message");
logger.fatal("Test Fatal Message");
logger.error("Test Error Message");
// alternative configuration demonstrating callback + custom layout
///////////////////////////////////////////////////////////////////
// use a custom layout function (in this case, the provided basicLayout)
// format: [TIMESTAMP][LEVEL][category] - [message]
var customLayout = require('../lib/layouts').basicLayout;
log4js.configure({
"appenders": [
{
"type" : "hipchat",
"hipchat_token": process.env.HIPCHAT_TOKEN || '< User token with Notification Privileges >',
"hipchat_room": process.env.HIPCHAT_ROOM || '< Room ID or Name >',
"hipchat_from": "Mr. Semantics",
"hipchat_notify": false,
"hipchat_response_callback": function(err, response, body){
if(err || response.statusCode > 300){
throw new Error('hipchat-notifier failed');
}
console.log('mr semantics callback success');
},
"layout": customLayout
}
]
});
logger.info("Test customLayout from Mr. Semantics");