forked from Automattic/kue
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.js
More file actions
125 lines (101 loc) · 2.92 KB
/
Copy pathdebug.js
File metadata and controls
125 lines (101 loc) · 2.92 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*!
* Cluster - debug
* Copyright (c) 2011 LearnBoost <dev@learnboost.com>
* MIT Licensed
*/
/**
* Enable verbose debugging output.
*
* @return {Function}
* @api public
*/
module.exports = function(options){
options = options || {};
// strip colors
function color(text) {
if (options.colors === false) return text.replace(/\033\[\d+m/g, '');
return text
}
// logger
var log = {
debug: function(str){
console.error(color(' \033[90mdebug - %s\033[0m'), str);
},
info: function(str){
console.error(color(' info \033[90m- %s\033[0m'), str);
},
warning: function(str){
console.error(color(' \033[33mwarning\033[0m \033[90m- %s\033[0m'), str);
},
error: function(str){
console.error(color(' \033[31merror\033[0m \033[90m- %s\033[0m'), str);
}
};
return function(master){
// start
master.on('start', function(){
log.info('master started');
});
// closing
master.on('closing', function(){
log.info('shutting down');
});
// close
master.on('close', function(){
log.info('shutdown complete');
});
// killing workers
master.on('kill', function(sig){
log.warning('kill(' + (sig || 'SIGTERM') + ')');
});
// worker died
master.on('worker killed', function(worker){
if ('restarting' == master.state) return;
log.warning('worker ' + worker.id + ' died');
});
// worker exception
master.on('worker exception', function(worker, err){
log.error('worker ' + worker.id + ' uncaught exception ' + err.message);
});
// worker is waiting on connections to be closed
master.on('worker waiting', function(worker, connections){
log.warning('worker ' + worker.id + ' waiting on ' + connections + ' connections');
});
// worker has timed out
master.on('worker timeout', function(worker, timeout){
log.warning('worker ' + worker.id + ' timed out after ' + timeout + 'ms');
});
// connection
master.on('worker connected', function(worker){
log.info('worker ' + worker.id + ' connected');
});
// removed
master.on('worker removed', function(worker){
log.info('worker ' + worker.id + ' removed');
});
// worker
master.on('worker', function(worker){
log.info('worker ' + worker.id + ' spawned');
});
// listening
master.on('listening', function(){
log.info('listening for connections');
});
// cyclic or immediate restart
master.on('cyclic restart', function(){
log.warning('cyclic restart detected, restarting in ' + master.options['restart timeout'] + 'ms');
});
// restart requested
master.on('restarting', function(){
log.info('restart requested');
});
// restart complete
master.on('restart', function(){
log.info('restart complete');
});
// exit
process.on('exit', function(){
log.debug('exit');
});
}
};