1
1
/**
2
- * !!! The hipchat-appender requires `hipchat-notifier` from npm
3
- * - e.g. list as a dependency in your application's package.json
2
+ * !!! The hipchat-appender requires `hipchat-notifier` from npm, e.g.
3
+ * - list as a dependency in your application's package.json ||
4
+ * - npm install hipchat-notifier
4
5
*/
5
6
6
7
var log4js = require ( '../lib/log4js' ) ;
@@ -9,24 +10,46 @@ log4js.configure({
9
10
"appenders" : [
10
11
{
11
12
"type" : "hipchat" ,
12
- "hipchat_token" : "< User token with Notification Privileges >" ,
13
- "hipchat_room" : "< Room ID or Name >" ,
14
- // optional
15
- "hipchat_from" : "[ additional from label ]" ,
16
- "hipchat_notify" : "[ notify boolean to bug people ]" ,
17
- "hipchat_response_callback" : function ( err , response , body ) {
18
- console . log ( "overridden log4js hipchat-appender response callback" ) ;
19
- }
13
+ "hipchat_token" : process . env . HIPCHAT_TOKEN || '< User token with Notification Privileges >' ,
14
+ "hipchat_room" : process . env . HIPCHAT_ROOM || '< Room ID or Name >'
20
15
}
21
16
]
22
17
} ) ;
23
18
24
19
var logger = log4js . getLogger ( "hipchat" ) ;
25
- logger . warn ( "Test Warn message" ) ; //yello
26
- logger . info ( "Test Info message" ) ; //green
27
- logger . debug ( "Test Debug Message" ) ; //hipchat client has limited color scheme
28
- logger . trace ( "Test Trace Message" ) ; //so debug and trace are the same color: purple
29
- logger . fatal ( "Test Fatal Message" ) ; //hipchat client has limited color scheme
30
- logger . error ( "Test Error Message" ) ; // fatal and error are same color: red
31
- logger . all ( "Test All message" ) ; //grey
32
- //logger.debug("Test log message");
20
+ logger . warn ( "Test Warn message" ) ;
21
+ logger . info ( "Test Info message" ) ;
22
+ logger . debug ( "Test Debug Message" ) ;
23
+ logger . trace ( "Test Trace Message" ) ;
24
+ logger . fatal ( "Test Fatal Message" ) ;
25
+ logger . error ( "Test Error Message" ) ;
26
+
27
+ // alternative configuration
28
+
29
+ // use a custom layout function
30
+ // format: [TIMESTAMP][LEVEL][category] - [message]
31
+ var customLayout = require ( '../lib/layouts' ) . basicLayout ;
32
+
33
+ log4js . configure ( {
34
+ "appenders" : [
35
+ {
36
+ "type" : "hipchat" ,
37
+ "hipchat_token" : process . env . HIPCHAT_TOKEN || '< User token with Notification Privileges >' ,
38
+ "hipchat_room" : process . env . HIPCHAT_ROOM || '< Room ID or Name >' ,
39
+ "hipchat_from" : "Mr. Semantics" ,
40
+ "hipchat_notify" : false ,
41
+ "hipchat_response_callback" : function ( err , response , body ) {
42
+ if ( err || response . statusCode > 300 ) {
43
+ throw new Error ( 'hipchat-notifier failed' ) ;
44
+ }
45
+ console . log ( 'mr semantics callback success' ) ;
46
+ } ,
47
+ "layout" : customLayout
48
+ }
49
+ ]
50
+ } ) ;
51
+
52
+ logger . info ( "Test from processed by customLayout" ) ;
53
+
54
+ // @TODO : implement configuration of send message to allow HipChat cards &c
55
+ // for now, can try to implement by returning object from custom layout
0 commit comments