-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
91 lines (74 loc) · 2.87 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
'use strict';
angular
.module('ElasticSearchLoggerDemoApp', [
'cmanaha.angular-elasticsearch-logger'
]);
angular
.module('ElasticSearchLoggerDemoApp')
.config(['CMRESLoggerProvider',function ( esLoggingProvider) {
// Config parameters from
// http://www.elasticsearch.org/guide/en/elasticsearch/client/javascript-api/current/configuration.html
esLoggingProvider.setElasticSearchConfig({
//point the host:port to an elasticsearch instance or run
//an elasticsearch service in your own
'host': 'http://localhost:9200',
'apiVersion': '1.7'
});
esLoggingProvider.setLogConfig({
'index': 'demo_app_index',
'type': 'jslog',
'bufferSize': 1,
'flushIntervalInMS': 1000
});
esLoggingProvider.setApplicationLogContext({
'application': 'DemoApp',
'version': '0.0.1',
'environment': 'Development'
});
}]);
angular
.module('ElasticSearchLoggerDemoApp')
.controller( 'DemoCtrl', ['$log','CMRESLogger',function($log, CMRESLogger){
var self = this;
self.inputToken = null;
self.message = '';
self.TestException = function(message){
this.message = message;
};
self.logIt = function() {
$log.info( self.message );
CMRESLogger.info( self.message );
};
self.logItWithProperties = function(message,number) {
var properties = {};
properties['test1'] = 'property';
properties['number'] = number;
CMRESLogger.info(message,properties);
};
self.logMultipleTimes = function(){
var numberOfLogs = Math.floor((Math.random() * 200) + 1);
for (var i=0 ; i<numberOfLogs; i++){
var level = Math.floor((Math.random() * 6) + 1);
switch(level){
case 1:
CMRESLogger.info( 'message ['+i+']: ' + self.message );
break;
case 2:
CMRESLogger.debug( 'message ['+i+']: ' + self.message );
break;
case 3:
CMRESLogger.warning( 'message ['+i+']: ' + self.message );
break;
case 4:
CMRESLogger.error( 'message ['+i+']: ' + self.message );
break;
case 5:
CMRESLogger.errorWithException( 'message ['+i+']: ' + self.message , new self.TestException('message'));
break;
case 6:
self.logItWithProperties('message ['+i+']: ' + self.message,i);
break;
}
}
};
}]);