Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / log4js / lib / appenders / hipchat.js
1 "use strict";
2
3 var hipchat = require('hipchat-notifier');
4 var layouts = require('../layouts');
5
6 exports.name = 'hipchat';
7 exports.appender  = hipchatAppender;
8 exports.configure = hipchatConfigure;
9
10 /**
11   @invoke as
12
13   log4js.configure({
14     "appenders": [
15       {
16         "type" : "hipchat",
17         "hipchat_token": "< User token with Notification Privileges >",
18         "hipchat_room": "< Room ID or Name >",
19         // optionl
20         "hipchat_from": "[ additional from label ]",
21         "hipchat_notify": "[ notify boolean to bug people ]",
22         "hipchat_host" : "api.hipchat.com"
23       }
24     ]
25   });
26
27   var logger = log4js.getLogger("hipchat");
28   logger.warn("Test Warn message");
29
30   @invoke
31  */
32
33 function hipchatNotifierResponseCallback(err, response, body){
34   if(err) {
35     throw err;
36   }
37 }
38
39 function hipchatAppender(config) {
40
41         var notifier = hipchat.make(config.hipchat_room, config.hipchat_token);
42
43   // @lint W074 This function's cyclomatic complexity is too high. (10)
44   return function(loggingEvent){
45
46     var notifierFn;
47
48     notifier.setRoom(config.hipchat_room);
49     notifier.setFrom(config.hipchat_from || '');
50     notifier.setNotify(config.hipchat_notify || false);
51
52     if(config.hipchat_host) {
53       notifier.setHost(config.hipchat_host);
54     }
55
56     switch (loggingEvent.level.toString()) {
57       case "TRACE":
58       case "DEBUG":
59         notifierFn = "info";
60         break;
61       case "WARN":
62         notifierFn = "warning";
63         break;
64       case "ERROR":
65       case "FATAL":
66         notifierFn = "failure";
67         break;
68       default:
69         notifierFn = "success";
70     }
71
72     // @TODO, re-work in timezoneOffset ?
73     var layoutMessage = config.layout(loggingEvent);
74
75     // dispatch hipchat api request, do not return anything
76     //  [overide hipchatNotifierResponseCallback]
77     notifier[notifierFn](layoutMessage, config.hipchat_response_callback ||
78       hipchatNotifierResponseCallback);
79   };
80 }
81
82 function hipchatConfigure(config) {
83         var layout;
84
85         if (!config.layout) {
86                 config.layout = layouts.messagePassThroughLayout;
87         }
88
89         return hipchatAppender(config, layout);
90 }