Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50659 views
1
/*
2
* exceptions.js: Plugin responsible for logging all uncaughtExceptions in a flatiron App.
3
*
4
* (C) 2011, Nodejitsu Inc.
5
* MIT LICENSE
6
*
7
*/
8
9
var winston = require('winston'),
10
common = require('../common');
11
12
var exceptions = exports;
13
14
//
15
// ### Setup default state for the exceptions plugin
16
//
17
exceptions.name = 'exceptions';
18
exceptions.initalized = false;
19
20
var defaultConfig = exceptions.defaultConfig = {
21
console: {
22
colorize: false,
23
json: true,
24
level: 'silly'
25
}
26
};
27
28
//
29
// ### function attach (options)
30
// #### @options {Object} Options for this plugin
31
// Extends `this` the application with exception handling
32
// functionality from `winston`.
33
//
34
exceptions.attach = function (options) {
35
options = options || {};
36
37
if (this.config) {
38
options = common.mixin({}, options, this.config.get('exceptions') || {});
39
}
40
41
if (exceptions.initalized) {
42
return;
43
}
44
45
var exceptionHandlers = [];
46
47
//
48
// Create the exceptionHandlers defaulting to Console and Loggly.
49
//
50
exceptionHandlers.push(new winston.transports.Console(options.console || defaultConfig.console));
51
52
Object.keys(options).forEach(function (name) {
53
if (name === 'console') {
54
return;
55
}
56
57
exceptionHandlers.push(new (winston.transports[common.capitalize(name)])(options[name]));
58
});
59
60
//
61
// Update the state of the plugin with the logger.
62
//
63
exceptions.logger = new winston.Logger({ exceptionHandlers: exceptionHandlers });
64
exceptions.initalized = true;
65
66
//
67
// Have the logger handle uncaught exceptions.
68
//
69
exceptions.logger.handleExceptions();
70
};
71