1
1
"use strict" ;
2
- var HipChatClient = require ( 'hipchat-client ' ) ;
2
+ var hipchat = require ( 'hipchat-notifier ' ) ;
3
3
var layouts = require ( '../layouts' ) ;
4
4
5
5
exports . name = 'hipchat' ;
6
6
exports . appender = hipchatAppender ;
7
7
exports . configure = hipchatConfigure ;
8
8
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
+ }
20
32
21
33
function hipchatAppender ( config , layout ) {
22
34
@@ -26,20 +38,38 @@ function hipchatAppender(config, layout) {
26
38
27
39
return function ( loggingEvent ) {
28
40
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 ) ;
43
73
}
44
74
}
45
75
0 commit comments