8000 use hipchat-notifier lib for apiv2 support · wxqGitHub/log4js-node@4ab05a5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4ab05a5

Browse files
committed
use hipchat-notifier lib for apiv2 support
1 parent 32070ca commit 4ab05a5

File tree

1 file changed

+56
-26
lines changed

1 file changed

+56
-26
lines changed

lib/appenders/hipchat.js

Lines changed: 56 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,34 @@
11
"use strict";
2-
var HipChatClient = require('hipchat-client');
2+
var hipchat = require('hipchat-notifier');
33
var layouts = require('../layouts');
44

55
exports.name = 'hipchat';
66
exports.appender = hipchatAppender;
77
exports.configure = hipchatConfigure;
88

9-
//hipchat has more limited colors
10-
var colours = {
11-
ALL: "grey",
12-
TRACE: "purple",
13-
DEBUG: "purple",
14-
INFO: "green",
15-
WARN: "yellow",
16-
ERROR: "red",
17-
FATAL: "red",
18-
OFF: "grey"
19-
};
9+
/**
10+
@invoke as
11+
log4js.configure({
12+
"appenders": [
13+
{
14+
"type" : "hipchat",
15+
"hipchat_token": "< User token with Notification Privileges >",
16+
"hipchat_room": "< Room ID or Name >",
17+
// optionl
18+
"hipchat_from": "[ additional from label ]",
19+
"hipchat_notify": "[ notify boolean to bug people ]",
20+
"hipchat_host" : "api.hipchat.com"
21+
}
22+
]
23+
});
24+
@invoke
25+
*/
26+
27+
function hipchatNotifierResponseCallback(err, response, body){
28+
if(err) {
29+
throw err;
30+
}
31+
}
2032

2133
function hipchatAppender(config, layout) {
2234

@@ -26,20 +38,38 @@ function hipchatAppender(config, layout) {
2638

2739
return function(loggingEvent) {
2840

29-
var data = {
30-
room_id: _config.room_id,
31-
from: _config.from,
32-
message: layout(loggingEvent, _config.timezoneOffset),
33-
format: _config.format,
34-
color: colours[loggingEvent.level.toString()],
35-
notify: _config.notify
36-
};
37-
38-
client.api.rooms.message(data, function(err, res) {
39-
if (err) {
40-
throw err;
41-
}
42-
});
41+
notifier.setRoom(config.hipchat_room);
42+
notifier.setRoom(config.hipchat_room);
43+
notifier.setFrom(config.hipchat_from || '');
44+
notifier.setNotify(config.hipchat_notify || false);
45+
46+
if(config.hipchat_host) {
47+
notifier.setHost(config.hipchat_host);
48+
}
49+
50+
var notifierFn = "success";
51+
switch (loggingEvent.level.toString()) {
52+
case "TRACE":
53+
case "DEBUG":
54+
notifierFn = "notice";
55+
break;
56+
case "WARN":
57+
notifierFn = "warning";
58+
break;
59+
case "ERROR":
60+
case "FATAL":
61+
notifierFn = "failure";
62+
break;
63+
default:
64+
notifierFn = "info";
65+
}
66+
67+
// @TODO, re-work in timezoneOffset ?
68+
var layoutMessage = layout(loggingEvent);
69+
70+
// dispatch hipchat api request, do not return anything
71+
// [overide hipchatNotifierResponseCallback]
72+
notifier[notifierFn](layoutMessage, hipchatNotifierResponseCallback);
4373
}
4474
}
4575

0 commit comments

Comments
 (0)
0