passenger 5.0.21 → 5.0.22

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of passenger might be problematic. Click here for more details.

Files changed (203) hide show
  1. checksums.yaml +8 -8
  2. checksums.yaml.gz.asc +7 -7
  3. data.tar.gz.asc +7 -7
  4. data/CHANGELOG +38 -2
  5. data/CONTRIBUTORS +3 -0
  6. data/README.md +5 -1
  7. data/bin/passenger-status +2 -7
  8. data/build/agent.rb +2 -0
  9. data/build/cxx_dependency_map.rb +1464 -162
  10. data/build/node_tests.rb +1 -1
  11. data/build/packaging.rb +1 -1
  12. data/dev/ci/run_travis.sh +1 -1
  13. data/dev/vagrant/provision.sh +1 -1
  14. data/npm-shrinkwrap.json +635 -125
  15. data/package.json +1 -1
  16. data/resources/templates/standalone/config.erb +33 -161
  17. data/resources/templates/standalone/global.erb +15 -0
  18. data/resources/templates/standalone/http.erb +40 -0
  19. data/resources/templates/standalone/mass_deployment_default_server.erb +11 -0
  20. data/resources/templates/standalone/rails_asset_pipeline.erb +22 -0
  21. data/resources/templates/standalone/server.erb +58 -0
  22. data/src/agent/Core/ApiServer.h +37 -32
  23. data/src/agent/Core/ApplicationPool/BasicGroupInfo.h +1 -1
  24. data/src/agent/Core/ApplicationPool/BasicProcessInfo.h +6 -0
  25. data/src/agent/Core/ApplicationPool/Common.h +1 -1
  26. data/src/agent/Core/ApplicationPool/Group/OutOfBandWork.cpp +1 -1
  27. data/src/agent/Core/ApplicationPool/Group/ProcessListManagement.cpp +4 -0
  28. data/src/agent/Core/ApplicationPool/Implementation.cpp +2 -2
  29. data/src/agent/Core/ApplicationPool/Options.h +18 -1
  30. data/src/agent/Core/ApplicationPool/Pool.h +1 -1
  31. data/src/agent/Core/ApplicationPool/Pool/AnalyticsCollection.cpp +6 -6
  32. data/src/agent/Core/ApplicationPool/Pool/GeneralUtils.cpp +3 -3
  33. data/src/agent/Core/ApplicationPool/Pool/InitializationAndShutdown.cpp +1 -1
  34. data/src/agent/Core/ApplicationPool/Pool/Miscellaneous.cpp +6 -0
  35. data/src/agent/Core/ApplicationPool/Process.h +6 -1
  36. data/src/agent/Core/ApplicationPool/Socket.h +9 -12
  37. data/src/agent/Core/Controller.h +422 -0
  38. data/src/agent/Core/{RequestHandler → Controller}/AppResponse.h +2 -0
  39. data/src/agent/Core/{RequestHandler → Controller}/BufferBody.cpp +27 -5
  40. data/src/agent/Core/{RequestHandler → Controller}/CheckoutSession.cpp +61 -31
  41. data/src/agent/Core/{RequestHandler → Controller}/Client.h +5 -2
  42. data/src/agent/Core/{RequestHandler → Controller}/ForwardResponse.cpp +93 -42
  43. data/src/agent/Core/{RequestHandler → Controller}/Hooks.cpp +107 -60
  44. data/src/agent/Core/Controller/Implementation.cpp +38 -0
  45. data/src/agent/Core/{RequestHandler → Controller}/InitRequest.cpp +134 -80
  46. data/src/agent/Core/Controller/InitializationAndShutdown.cpp +165 -0
  47. data/src/agent/Core/{RequestHandler/Utils.cpp → Controller/InternalUtils.cpp} +49 -32
  48. data/src/agent/Core/Controller/Miscellaneous.cpp +116 -0
  49. data/src/agent/Core/{RequestHandler → Controller}/Request.h +6 -4
  50. data/src/agent/Core/{RequestHandler → Controller}/SendRequest.cpp +205 -130
  51. data/src/agent/Core/Controller/StateInspectionAndConfiguration.cpp +161 -0
  52. data/src/agent/Core/{RequestHandler → Controller}/TurboCaching.h +3 -0
  53. data/src/agent/Core/CoreMain.cpp +62 -51
  54. data/src/agent/Core/OptionParser.h +24 -0
  55. data/src/agent/Core/ResponseCache.h +5 -5
  56. data/src/agent/Core/SpawningKit/Config.h +2 -2
  57. data/src/agent/Core/SpawningKit/SmartSpawner.h +1 -1
  58. data/src/agent/Core/UnionStation/{Core.h → Context.h} +14 -18
  59. data/src/agent/Core/UnionStation/StopwatchLog.h +3 -2
  60. data/src/agent/Core/UnionStation/Transaction.h +7 -7
  61. data/src/agent/Shared/ApiServerUtils.h +9 -1
  62. data/src/agent/UstRouter/ApiServer.h +5 -2
  63. data/src/agent/UstRouter/Controller.h +27 -9
  64. data/src/agent/UstRouter/UstRouterMain.cpp +1 -0
  65. data/src/agent/Watchdog/ApiServer.h +5 -2
  66. data/src/apache2_module/ConfigurationCommands.cpp +7 -0
  67. data/src/apache2_module/ConfigurationFields.hpp +2 -0
  68. data/src/apache2_module/ConfigurationSetters.cpp +24 -0
  69. data/src/apache2_module/CreateDirConfig.cpp +1 -0
  70. data/src/apache2_module/Hooks.cpp +6 -5
  71. data/src/apache2_module/MergeDirConfig.cpp +7 -0
  72. data/src/apache2_module/SetHeaders.cpp +5 -0
  73. data/src/cxx_supportlib/Constants.h +5 -3
  74. data/src/cxx_supportlib/SafeLibev.h +2 -1
  75. data/src/cxx_supportlib/UnionStationFilterSupport.h +2 -1
  76. data/src/cxx_supportlib/Utils/ReleaseableScopedPointer.h +70 -0
  77. data/src/cxx_supportlib/vendor-modified/boost/libs/regex/src/regex_raw_buffer.cpp +6 -6
  78. data/src/helper-scripts/node-loader.js +59 -0
  79. data/src/nginx_module/CacheLocationConfig.c +48 -0
  80. data/src/nginx_module/ConfigurationCommands.c +20 -0
  81. data/src/nginx_module/ConfigurationFields.h +4 -0
  82. data/src/nginx_module/CreateLocationConfig.c +8 -0
  83. data/src/nginx_module/MergeLocationConfig.c +12 -0
  84. data/src/nodejs_supportlib/phusion_passenger/log_express.js +106 -0
  85. data/src/nodejs_supportlib/phusion_passenger/log_mongodb.js +203 -0
  86. data/src/nodejs_supportlib/phusion_passenger/ustreporter.js +227 -0
  87. data/src/nodejs_supportlib/phusion_passenger/ustrouter_connector.js +446 -0
  88. data/src/nodejs_supportlib/vendor-copy/codify/codify.js +44 -0
  89. data/src/nodejs_supportlib/vendor-copy/codify/package.json +29 -0
  90. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/context.js +200 -0
  91. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/async-listener/glue.js +488 -0
  92. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/async-listener/index.js +407 -0
  93. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/async-listener/node_modules/shimmer/index.js +90 -0
  94. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/async-listener/node_modules/shimmer/package.json +40 -0
  95. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/async-listener/package.json +54 -0
  96. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/emitter-listener/listener.js +160 -0
  97. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/emitter-listener/node_modules/shimmer/index.js +90 -0
  98. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/emitter-listener/node_modules/shimmer/package.json +40 -0
  99. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/emitter-listener/package.json +46 -0
  100. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/package.json +56 -0
  101. data/src/nodejs_supportlib/vendor-copy/network-byte-order/lib/index.js +102 -0
  102. data/src/nodejs_supportlib/vendor-copy/network-byte-order/package.json +51 -0
  103. data/src/nodejs_supportlib/vendor-copy/winston/LICENSE +19 -0
  104. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston.js +165 -0
  105. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/common.js +483 -0
  106. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/config.js +62 -0
  107. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/config/cli-config.js +35 -0
  108. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/config/npm-config.js +27 -0
  109. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/config/syslog-config.js +31 -0
  110. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/container.js +127 -0
  111. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/exception.js +56 -0
  112. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/logger.js +701 -0
  113. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports.js +34 -0
  114. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/console.js +128 -0
  115. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/daily-rotate-file.js +601 -0
  116. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/file.js +675 -0
  117. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/http.js +232 -0
  118. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/memory.js +89 -0
  119. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/transport.js +135 -0
  120. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/webhook.js +146 -0
  121. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/async/LICENSE +19 -0
  122. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/async/lib/async.js +1283 -0
  123. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/async/package.json +66 -0
  124. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/async/support/sync-package-managers.js +53 -0
  125. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/MIT-LICENSE.txt +23 -0
  126. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/colors.js +176 -0
  127. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/custom/trap.js +45 -0
  128. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/custom/zalgo.js +104 -0
  129. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/extendStringPrototype.js +118 -0
  130. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/index.js +12 -0
  131. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/maps/america.js +12 -0
  132. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/maps/rainbow.js +13 -0
  133. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/maps/random.js +8 -0
  134. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/maps/zebra.js +5 -0
  135. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/styles.js +77 -0
  136. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/system/supports-colors.js +61 -0
  137. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/package.json +35 -0
  138. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/safe.js +9 -0
  139. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/themes/generic-logging.js +12 -0
  140. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/cycle/cycle.js +170 -0
  141. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/cycle/package.json +30 -0
  142. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/eyes/LICENSE +20 -0
  143. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/eyes/lib/eyes.js +236 -0
  144. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/eyes/package.json +42 -0
  145. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/isstream/LICENSE.md +11 -0
  146. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/isstream/isstream.js +27 -0
  147. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/isstream/package.json +42 -0
  148. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/pkginfo/LICENSE +19 -0
  149. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/pkginfo/lib/pkginfo.js +136 -0
  150. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/pkginfo/package.json +56 -0
  151. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/stack-trace/License +19 -0
  152. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/stack-trace/lib/stack-trace.js +111 -0
  153. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/stack-trace/package.json +33 -0
  154. data/src/nodejs_supportlib/vendor-copy/winston/package.json +87 -0
  155. data/src/ruby_supportlib/phusion_passenger.rb +3 -4
  156. data/src/ruby_supportlib/phusion_passenger/admin_tools/instance.rb +19 -2
  157. data/src/ruby_supportlib/phusion_passenger/apache2/config_options.rb +8 -0
  158. data/src/ruby_supportlib/phusion_passenger/config/list_instances_command.rb +2 -6
  159. data/src/ruby_supportlib/phusion_passenger/config/reopen_logs_command.rb +13 -0
  160. data/src/ruby_supportlib/phusion_passenger/config/restart_app_command.rb +3 -0
  161. data/src/ruby_supportlib/phusion_passenger/config/utils.rb +9 -7
  162. data/src/ruby_supportlib/phusion_passenger/config/validate_install_command.rb +8 -1
  163. data/src/ruby_supportlib/phusion_passenger/constants.rb +3 -1
  164. data/src/ruby_supportlib/phusion_passenger/native_support.rb +20 -4
  165. data/src/ruby_supportlib/phusion_passenger/nginx/config_options.rb +8 -0
  166. data/src/ruby_supportlib/phusion_passenger/packaging.rb +1 -0
  167. data/src/ruby_supportlib/phusion_passenger/platform_info/apache_detector.rb +1 -1
  168. data/src/ruby_supportlib/phusion_passenger/platform_info/operating_system.rb +11 -4
  169. data/src/ruby_supportlib/phusion_passenger/rack/thread_handler_extension.rb +1 -1
  170. data/src/ruby_supportlib/phusion_passenger/standalone/config_options_list.rb +647 -0
  171. data/src/ruby_supportlib/phusion_passenger/standalone/config_utils.rb +229 -15
  172. data/src/ruby_supportlib/phusion_passenger/standalone/start_command.rb +35 -323
  173. data/src/ruby_supportlib/phusion_passenger/standalone/start_command/builtin_engine.rb +36 -12
  174. data/src/ruby_supportlib/phusion_passenger/standalone/start_command/nginx_engine.rb +123 -14
  175. data/src/ruby_supportlib/phusion_passenger/standalone/status_command.rb +32 -17
  176. data/src/ruby_supportlib/phusion_passenger/standalone/stop_command.rb +32 -21
  177. data/src/ruby_supportlib/phusion_passenger/standalone/version_command.rb +5 -5
  178. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/README.md +2 -2
  179. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/Rakefile +5 -1
  180. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core.rb +68 -24
  181. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/api.rb +9 -1
  182. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/context.rb +9 -7
  183. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/request_reporter.rb +3 -2
  184. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/request_reporter/basics.rb +8 -5
  185. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/simple_json.rb +395 -0
  186. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/transaction.rb +10 -7
  187. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/utils.rb +14 -0
  188. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/version_data.rb +2 -2
  189. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml +4 -2
  190. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml.example +2 -2
  191. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml.travis +2 -2
  192. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml.travis-with-sudo +16 -0
  193. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/Gemfile +1 -1
  194. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/Gemfile.lock +2 -2
  195. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/README.md +1 -1
  196. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails.rb +44 -17
  197. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/active_support_cache_subscriber.rb +16 -7
  198. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/version_data.rb +2 -2
  199. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/union_station_hooks_rails.gemspec +1 -1
  200. metadata +99 -16
  201. metadata.gz.asc +7 -7
  202. data/resources/oss-binaries.phusionpassenger.com.crt +0 -248
  203. data/src/agent/Core/RequestHandler.h +0 -471
@@ -0,0 +1,62 @@
1
+ /*
2
+ * config.js: Default settings for all levels that winston knows about
3
+ *
4
+ * (C) 2010 Charlie Robbins
5
+ * MIT LICENCE
6
+ *
7
+ */
8
+
9
+ var colors = require('colors/safe');
10
+
11
+ var config = exports,
12
+ allColors = exports.allColors = {};
13
+
14
+ config.addColors = function (colors) {
15
+ mixin(allColors, colors);
16
+ };
17
+
18
+ config.colorize = function (level, message) {
19
+ if (typeof message === 'undefined') message = level;
20
+
21
+ var colorized = message;
22
+ if (allColors[level] instanceof Array) {
23
+ for (var i = 0, l = allColors[level].length; i < l; ++i) {
24
+ colorized = colors[allColors[level][i]](colorized);
25
+ }
26
+ } else if (allColors[level].match(/\s/)) {
27
+ var colorArr = allColors[level].split(/\s+/);
28
+ for (var i = 0; i < colorArr.length; ++i) {
29
+ colorized = colors[colorArr[i]](colorized);
30
+ }
31
+ allColors[level] = colorArr;
32
+ } else {
33
+ colorized = colors[allColors[level]](colorized);
34
+ }
35
+ return colorized;
36
+ };
37
+
38
+ //
39
+ // Export config sets
40
+ //
41
+ config.cli = require('./config/cli-config');
42
+ config.npm = require('./config/npm-config');
43
+ config.syslog = require('./config/syslog-config');
44
+
45
+ //
46
+ // Add colors for pre-defined config sets
47
+ //
48
+ config.addColors(config.cli.colors);
49
+ config.addColors(config.npm.colors);
50
+ config.addColors(config.syslog.colors);
51
+
52
+ function mixin (target) {
53
+ var args = Array.prototype.slice.call(arguments, 1);
54
+
55
+ args.forEach(function (a) {
56
+ var keys = Object.keys(a);
57
+ for (var i = 0; i < keys.length; i++) {
58
+ target[keys[i]] = a[keys[i]];
59
+ }
60
+ });
61
+ return target;
62
+ };
@@ -0,0 +1,35 @@
1
+ /*
2
+ * cli-config.js: Config that conform to commonly used CLI logging levels.
3
+ *
4
+ * (C) 2010 Charlie Robbins
5
+ * MIT LICENCE
6
+ *
7
+ */
8
+
9
+ var cliConfig = exports;
10
+
11
+ cliConfig.levels = {
12
+ silly: 0,
13
+ input: 1,
14
+ verbose: 2,
15
+ prompt: 3,
16
+ debug: 4,
17
+ info: 5,
18
+ data: 6,
19
+ help: 7,
20
+ warn: 8,
21
+ error: 9
22
+ };
23
+
24
+ cliConfig.colors = {
25
+ silly: 'magenta',
26
+ input: 'grey',
27
+ verbose: 'cyan',
28
+ prompt: 'grey',
29
+ debug: 'blue',
30
+ info: 'green',
31
+ data: 'grey',
32
+ help: 'cyan',
33
+ warn: 'yellow',
34
+ error: 'red'
35
+ };
@@ -0,0 +1,27 @@
1
+ /*
2
+ * npm-config.js: Config that conform to npm logging levels.
3
+ *
4
+ * (C) 2010 Charlie Robbins
5
+ * MIT LICENCE
6
+ *
7
+ */
8
+
9
+ var npmConfig = exports;
10
+
11
+ npmConfig.levels = {
12
+ silly: 0,
13
+ debug: 1,
14
+ verbose: 2,
15
+ info: 3,
16
+ warn: 4,
17
+ error: 5
18
+ };
19
+
20
+ npmConfig.colors = {
21
+ silly: 'magenta',
22
+ verbose: 'cyan',
23
+ debug: 'blue',
24
+ info: 'green',
25
+ warn: 'yellow',
26
+ error: 'red'
27
+ };
@@ -0,0 +1,31 @@
1
+ /*
2
+ * syslog-config.js: Config that conform to syslog logging levels.
3
+ *
4
+ * (C) 2010 Charlie Robbins
5
+ * MIT LICENCE
6
+ *
7
+ */
8
+
9
+ var syslogConfig = exports;
10
+
11
+ syslogConfig.levels = {
12
+ emerg: 0,
13
+ alert: 1,
14
+ crit: 2,
15
+ error: 3,
16
+ warning: 4,
17
+ notice: 5,
18
+ info: 6,
19
+ debug: 7,
20
+ };
21
+
22
+ syslogConfig.colors = {
23
+ emerg: 'red',
24
+ alert: 'yellow',
25
+ crit: 'red',
26
+ error: 'red',
27
+ warning: 'red',
28
+ notice: 'yellow',
29
+ info: 'green',
30
+ debug: 'blue',
31
+ };
@@ -0,0 +1,127 @@
1
+ /*
2
+ * container.js: Inversion of control container for winston logger instances
3
+ *
4
+ * (C) 2010 Charlie Robbins
5
+ * MIT LICENCE
6
+ *
7
+ */
8
+
9
+ var common = require('./common'),
10
+ winston = require('../winston'),
11
+ extend = require('util')._extend;
12
+
13
+ //
14
+ // ### function Container (options)
15
+ // #### @options {Object} Default pass-thru options for Loggers
16
+ // Constructor function for the Container object responsible for managing
17
+ // a set of `winston.Logger` instances based on string ids.
18
+ //
19
+ var Container = exports.Container = function (options) {
20
+ this.loggers = {};
21
+ this.options = options || {};
22
+ this.default = {
23
+ transports: [
24
+ new winston.transports.Console({
25
+ level: 'silly',
26
+ colorize: false
27
+ })
28
+ ]
29
+ }
30
+ };
31
+
32
+ //
33
+ // ### function get / add (id, options)
34
+ // #### @id {string} Id of the Logger to get
35
+ // #### @options {Object} **Optional** Options for the Logger instance
36
+ // Retreives a `winston.Logger` instance for the specified `id`. If
37
+ // an instance does not exist, one is created.
38
+ //
39
+ Container.prototype.get = Container.prototype.add = function (id, options) {
40
+ var self = this,
41
+ existing;
42
+
43
+ if (!this.loggers[id]) {
44
+ //
45
+ // Remark: Simple shallow clone for configuration options in case we pass in
46
+ // instantiated protoypal objects
47
+ //
48
+ options = extend({}, options || this.options || this.default);
49
+ existing = options.transports || this.options.transports;
50
+ //
51
+ // Remark: Make sure if we have an array of transports we slice it to make copies
52
+ // of those references.
53
+ //
54
+ options.transports = existing ? existing.slice() : [];
55
+
56
+ if (options.transports.length === 0 && (!options || !options['console'])) {
57
+ options.transports.push(this.default.transports[0]);
58
+ }
59
+
60
+ Object.keys(options).forEach(function (key) {
61
+ if (key === 'transports') {
62
+ return;
63
+ }
64
+
65
+ var name = common.capitalize(key);
66
+
67
+ if (!winston.transports[name]) {
68
+ throw new Error('Cannot add unknown transport: ' + name);
69
+ }
70
+
71
+ var namedOptions = options[key];
72
+ namedOptions.id = id;
73
+ options.transports.push(new (winston.transports[name])(namedOptions));
74
+ });
75
+
76
+ this.loggers[id] = new winston.Logger(options);
77
+
78
+ this.loggers[id].on('close', function () {
79
+ self._delete(id);
80
+ });
81
+ }
82
+
83
+ return this.loggers[id];
84
+ };
85
+
86
+ //
87
+ // ### function close (id)
88
+ // #### @id {string} **Optional** Id of the Logger instance to find
89
+ // Returns a boolean value indicating if this instance
90
+ // has a logger with the specified `id`.
91
+ //
92
+ Container.prototype.has = function (id) {
93
+ return !!this.loggers[id];
94
+ };
95
+
96
+ //
97
+ // ### function close (id)
98
+ // #### @id {string} **Optional** Id of the Logger instance to close
99
+ // Closes a `Logger` instance with the specified `id` if it exists.
100
+ // If no `id` is supplied then all Loggers are closed.
101
+ //
102
+ Container.prototype.close = function (id) {
103
+ var self = this;
104
+
105
+ function _close (id) {
106
+ if (!self.loggers[id]) {
107
+ return;
108
+ }
109
+
110
+ self.loggers[id].close();
111
+ self._delete(id);
112
+ }
113
+
114
+ return id ? _close(id) : Object.keys(this.loggers).forEach(function (id) {
115
+ _close(id);
116
+ });
117
+ };
118
+
119
+ //
120
+ // ### @private function _delete (id)
121
+ // #### @id {string} Id of the Logger instance to delete from container
122
+ // Deletes a `Logger` instance with the specified `id`.
123
+ //
124
+ Container.prototype._delete = function (id) {
125
+ delete this.loggers[id];
126
+ }
127
+
@@ -0,0 +1,56 @@
1
+ /*
2
+ * exception.js: Utility methods for gathing information about uncaughtExceptions.
3
+ *
4
+ * (C) 2010 Charlie Robbins
5
+ * MIT LICENCE
6
+ *
7
+ */
8
+
9
+ var os = require('os'),
10
+ stackTrace = require('stack-trace');
11
+
12
+ var exception = exports;
13
+
14
+ exception.getAllInfo = function (err) {
15
+ return {
16
+ date: new Date().toString(),
17
+ process: exception.getProcessInfo(),
18
+ os: exception.getOsInfo(),
19
+ trace: exception.getTrace(err),
20
+ stack: err.stack && err.stack.split('\n')
21
+ };
22
+ };
23
+
24
+ exception.getProcessInfo = function () {
25
+ return {
26
+ pid: process.pid,
27
+ uid: process.getuid ? process.getuid() : null,
28
+ gid: process.getgid ? process.getgid() : null,
29
+ cwd: process.cwd(),
30
+ execPath: process.execPath,
31
+ version: process.version,
32
+ argv: process.argv,
33
+ memoryUsage: process.memoryUsage()
34
+ };
35
+ };
36
+
37
+ exception.getOsInfo = function () {
38
+ return {
39
+ loadavg: os.loadavg(),
40
+ uptime: os.uptime()
41
+ };
42
+ };
43
+
44
+ exception.getTrace = function (err) {
45
+ var trace = err ? stackTrace.parse(err) : stackTrace.get();
46
+ return trace.map(function (site) {
47
+ return {
48
+ column: site.getColumnNumber(),
49
+ file: site.getFileName(),
50
+ function: site.getFunctionName(),
51
+ line: site.getLineNumber(),
52
+ method: site.getMethodName(),
53
+ native: site.isNative(),
54
+ }
55
+ });
56
+ };
@@ -0,0 +1,701 @@
1
+ /*
2
+ * logger.js: Core logger object used by winston.
3
+ *
4
+ * (C) 2010 Charlie Robbins
5
+ * MIT LICENCE
6
+ *
7
+ */
8
+
9
+ var events = require('events'),
10
+ util = require('util'),
11
+ async = require('async'),
12
+ config = require('./config'),
13
+ common = require('./common'),
14
+ exception = require('./exception'),
15
+ Stream = require('stream').Stream;
16
+
17
+ //
18
+ // ### function Logger (options)
19
+ // #### @options {Object} Options for this instance.
20
+ // Constructor function for the Logger object responsible
21
+ // for persisting log messages and metadata to one or more transports.
22
+ //
23
+ var Logger = exports.Logger = function (options) {
24
+ events.EventEmitter.call(this);
25
+ options = options || {};
26
+
27
+ var self = this,
28
+ handleExceptions = false;
29
+
30
+ //
31
+ // Set Levels and default logging level
32
+ //
33
+ this.padLevels = options.padLevels || false;
34
+ this.setLevels(options.levels);
35
+ if (options.colors) {
36
+ config.addColors(options.colors);
37
+ }
38
+
39
+ //
40
+ // Hoist other options onto this instance.
41
+ //
42
+ this.level = options.level || 'info';
43
+ this.emitErrs = options.emitErrs || false;
44
+ this.stripColors = options.stripColors || false;
45
+ this.exitOnError = typeof options.exitOnError !== 'undefined'
46
+ ? options.exitOnError
47
+ : true;
48
+
49
+ //
50
+ // Setup other intelligent default settings.
51
+ //
52
+ this.transports = {};
53
+ this.rewriters = [];
54
+ this.filters = [];
55
+ this.exceptionHandlers = {};
56
+ this.profilers = {};
57
+ this._names = [];
58
+ this._hnames = [];
59
+
60
+ if (options.transports) {
61
+ options.transports.forEach(function (transport) {
62
+ self.add(transport, null, true);
63
+
64
+ if (transport.handleExceptions) {
65
+ handleExceptions = true;
66
+ }
67
+ });
68
+ }
69
+
70
+ if (options.rewriters) {
71
+ options.rewriters.forEach(function (rewriter) {
72
+ self.addRewriter(rewriter);
73
+ });
74
+ }
75
+
76
+ if (options.exceptionHandlers) {
77
+ handleExceptions = true;
78
+ options.exceptionHandlers.forEach(function (handler) {
79
+ self._hnames.push(handler.name);
80
+ self.exceptionHandlers[handler.name] = handler;
81
+ });
82
+ }
83
+
84
+ if (options.handleExceptions || handleExceptions) {
85
+ this.handleExceptions();
86
+ }
87
+ };
88
+
89
+ //
90
+ // Inherit from `events.EventEmitter`.
91
+ //
92
+ util.inherits(Logger, events.EventEmitter);
93
+
94
+ //
95
+ // ### function extend (target)
96
+ // #### @target {Object} Target to extend.
97
+ // Extends the target object with a 'log' method
98
+ // along with a method for each level in this instance.
99
+ //
100
+ Logger.prototype.extend = function (target) {
101
+ var self = this;
102
+ ['log', 'profile', 'startTimer'].concat(Object.keys(this.levels)).forEach(function (method) {
103
+ target[method] = function () {
104
+ return self[method].apply(self, arguments);
105
+ };
106
+ });
107
+
108
+ return this;
109
+ };
110
+
111
+ //
112
+ // ### function log (level, msg, [meta], callback)
113
+ // #### @level {string} Level at which to log the message.
114
+ // #### @msg {string} Message to log
115
+ // #### @meta {Object} **Optional** Additional metadata to attach
116
+ // #### @callback {function} Continuation to respond to when complete.
117
+ // Core logging method exposed to Winston. Metadata is optional.
118
+ //
119
+ Logger.prototype.log = function (level) {
120
+ var self = this,
121
+ args = Array.prototype.slice.call(arguments, 1);
122
+
123
+ while(args[args.length - 1] === null) {
124
+ args.pop();
125
+ }
126
+
127
+ var callback = typeof args[args.length - 1] === 'function' ? args.pop() : null,
128
+ meta = typeof args[args.length - 1] === 'object' && Object.prototype.toString.call(args[args.length - 1]) !== '[object RegExp]' ? args.pop() : {},
129
+ msg = util.format.apply(null, args);
130
+
131
+ // If we should pad for levels, do so
132
+ if (this.padLevels) {
133
+ msg = new Array(this.levelLength - level.length + 1).join(' ') + msg;
134
+ }
135
+
136
+ function onError (err) {
137
+ if (callback) {
138
+ callback(err);
139
+ }
140
+ else if (self.emitErrs) {
141
+ self.emit('error', err);
142
+ }
143
+ }
144
+
145
+
146
+ if (Object.keys(this.transports).length === 0) {
147
+ return onError(new Error('Cannot log with no transports.'));
148
+ }
149
+ else if (typeof self.levels[level] === 'undefined') {
150
+ return onError(new Error('Unknown log level: ' + level));
151
+ }
152
+
153
+ this.rewriters.forEach(function (rewriter) {
154
+ meta = rewriter(level, msg, meta, self);
155
+ });
156
+
157
+ this.filters.forEach(function(filter) {
158
+ var filtered = filter(msg, meta, level, self);
159
+ if (typeof filtered === 'string')
160
+ msg = filtered;
161
+ else {
162
+ msg = filtered.msg;
163
+ meta = filtered.meta;
164
+ }
165
+ });
166
+
167
+ //
168
+ // For consideration of terminal 'color" programs like colors.js,
169
+ // which can add ANSI escape color codes to strings, we destyle the
170
+ // ANSI color escape codes when `this.stripColors` is set.
171
+ //
172
+ // see: http://en.wikipedia.org/wiki/ANSI_escape_code
173
+ //
174
+ if (this.stripColors) {
175
+ var code = /\u001b\[(\d+(;\d+)*)?m/g;
176
+ msg = ('' + msg).replace(code, '');
177
+ }
178
+
179
+ //
180
+ // Log for each transport and emit 'logging' event
181
+ //
182
+ function emit(name, next) {
183
+ var transport = self.transports[name];
184
+ if ((transport.level && self.levels[transport.level] <= self.levels[level])
185
+ || (!transport.level && self.levels[self.level] <= self.levels[level])) {
186
+ transport.log(level, msg, meta, function (err) {
187
+ if (err) {
188
+ err.transport = transport;
189
+ cb(err);
190
+ return next();
191
+ }
192
+ self.emit('logging', transport, level, msg, meta);
193
+ next();
194
+ });
195
+ } else {
196
+ next();
197
+ }
198
+ }
199
+
200
+ //
201
+ // Respond to the callback
202
+ //
203
+ function cb(err) {
204
+ if (callback) {
205
+ if (err) return callback(err);
206
+ callback(null, level, msg, meta);
207
+ }
208
+ callback = null;
209
+ if (!err) {
210
+ self.emit('logged', level, msg, meta);
211
+ }
212
+ }
213
+
214
+ async.forEach(this._names, emit, cb);
215
+
216
+ return this;
217
+ };
218
+
219
+ //
220
+ // ### function query (options, callback)
221
+ // #### @options {Object} Query options for this instance.
222
+ // #### @callback {function} Continuation to respond to when complete.
223
+ // Queries the all transports for this instance with the specified `options`.
224
+ // This will aggregate each transport's results into one object containing
225
+ // a property per transport.
226
+ //
227
+ Logger.prototype.query = function (options, callback) {
228
+ if (typeof options === 'function') {
229
+ callback = options;
230
+ options = {};
231
+ }
232
+
233
+ var self = this,
234
+ options = options || {},
235
+ results = {},
236
+ query = common.clone(options.query) || {},
237
+ transports;
238
+
239
+ //
240
+ // Helper function to query a single transport
241
+ //
242
+ function queryTransport(transport, next) {
243
+ if (options.query) {
244
+ options.query = transport.formatQuery(query);
245
+ }
246
+
247
+ transport.query(options, function (err, results) {
248
+ if (err) {
249
+ return next(err);
250
+ }
251
+
252
+ next(null, transport.formatResults(results, options.format));
253
+ });
254
+ }
255
+
256
+ //
257
+ // Helper function to accumulate the results from
258
+ // `queryTransport` into the `results`.
259
+ //
260
+ function addResults (transport, next) {
261
+ queryTransport(transport, function (err, result) {
262
+ //
263
+ // queryTransport could potentially invoke the callback
264
+ // multiple times since Transport code can be unpredictable.
265
+ //
266
+ if (next) {
267
+ result = err || result;
268
+ if (result) {
269
+ results[transport.name] = result;
270
+ }
271
+
272
+ next();
273
+ }
274
+
275
+ next = null;
276
+ });
277
+ }
278
+
279
+ //
280
+ // If an explicit transport is being queried then
281
+ // respond with the results from only that transport
282
+ //
283
+ if (options.transport) {
284
+ options.transport = options.transport.toLowerCase();
285
+ return queryTransport(this.transports[options.transport], callback);
286
+ }
287
+
288
+ //
289
+ // Create a list of all transports for this instance.
290
+ //
291
+ transports = this._names.map(function (name) {
292
+ return self.transports[name];
293
+ }).filter(function (transport) {
294
+ return !!transport.query;
295
+ });
296
+
297
+ //
298
+ // Iterate over the transports in parallel setting the
299
+ // appropriate key in the `results`
300
+ //
301
+ async.forEach(transports, addResults, function () {
302
+ callback(null, results);
303
+ });
304
+ };
305
+
306
+ //
307
+ // ### function stream (options)
308
+ // #### @options {Object} Stream options for this instance.
309
+ // Returns a log stream for all transports. Options object is optional.
310
+ //
311
+ Logger.prototype.stream = function (options) {
312
+ var self = this,
313
+ options = options || {},
314
+ out = new Stream,
315
+ streams = [],
316
+ transports;
317
+
318
+ if (options.transport) {
319
+ var transport = this.transports[options.transport];
320
+ delete options.transport;
321
+ if (transport && transport.stream) {
322
+ return transport.stream(options);
323
+ }
324
+ }
325
+
326
+ out._streams = streams;
327
+ out.destroy = function () {
328
+ var i = streams.length;
329
+ while (i--) streams[i].destroy();
330
+ };
331
+
332
+ //
333
+ // Create a list of all transports for this instance.
334
+ //
335
+ transports = this._names.map(function (name) {
336
+ return self.transports[name];
337
+ }).filter(function (transport) {
338
+ return !!transport.stream;
339
+ });
340
+
341
+ transports.forEach(function (transport) {
342
+ var stream = transport.stream(options);
343
+ if (!stream) return;
344
+
345
+ streams.push(stream);
346
+
347
+ stream.on('log', function (log) {
348
+ log.transport = log.transport || [];
349
+ log.transport.push(transport.name);
350
+ out.emit('log', log);
351
+ });
352
+
353
+ stream.on('error', function (err) {
354
+ err.transport = err.transport || [];
355
+ err.transport.push(transport.name);
356
+ out.emit('error', err);
357
+ });
358
+ });
359
+
360
+ return out;
361
+ };
362
+
363
+ //
364
+ // ### function close ()
365
+ // Cleans up resources (streams, event listeners) for all
366
+ // transports associated with this instance (if necessary).
367
+ //
368
+ Logger.prototype.close = function () {
369
+ var self = this;
370
+
371
+ this._names.forEach(function (name) {
372
+ var transport = self.transports[name];
373
+ if (transport && transport.close) {
374
+ transport.close();
375
+ }
376
+ });
377
+
378
+ this.emit('close');
379
+ };
380
+
381
+ //
382
+ // ### function handleExceptions ()
383
+ // Handles `uncaughtException` events for the current process
384
+ //
385
+ Logger.prototype.handleExceptions = function () {
386
+ var args = Array.prototype.slice.call(arguments),
387
+ handlers = [],
388
+ self = this;
389
+
390
+ args.forEach(function (a) {
391
+ if (Array.isArray(a)) {
392
+ handlers = handlers.concat(a);
393
+ }
394
+ else {
395
+ handlers.push(a);
396
+ }
397
+ });
398
+
399
+ handlers.forEach(function (handler) {
400
+ self.exceptionHandlers[handler.name] = handler;
401
+ });
402
+
403
+ this._hnames = Object.keys(self.exceptionHandlers);
404
+
405
+ if (!this.catchExceptions) {
406
+ this.catchExceptions = this._uncaughtException.bind(this);
407
+ process.on('uncaughtException', this.catchExceptions);
408
+ }
409
+ };
410
+
411
+ //
412
+ // ### function unhandleExceptions ()
413
+ // Removes any handlers to `uncaughtException` events
414
+ // for the current process
415
+ //
416
+ Logger.prototype.unhandleExceptions = function () {
417
+ var self = this;
418
+
419
+ if (this.catchExceptions) {
420
+ Object.keys(this.exceptionHandlers).forEach(function (name) {
421
+ var handler = self.exceptionHandlers[name];
422
+ if (handler.close) {
423
+ handler.close();
424
+ }
425
+ });
426
+
427
+ this.exceptionHandlers = {};
428
+ Object.keys(this.transports).forEach(function (name) {
429
+ var transport = self.transports[name];
430
+ if (transport.handleExceptions) {
431
+ transport.handleExceptions = false;
432
+ }
433
+ })
434
+
435
+ process.removeListener('uncaughtException', this.catchExceptions);
436
+ this.catchExceptions = false;
437
+ }
438
+ };
439
+
440
+ //
441
+ // ### function add (transport, [options])
442
+ // #### @transport {Transport} Prototype of the Transport object to add.
443
+ // #### @options {Object} **Optional** Options for the Transport to add.
444
+ // #### @instance {Boolean} **Optional** Value indicating if `transport` is already instantiated.
445
+ // Adds a transport of the specified type to this instance.
446
+ //
447
+ Logger.prototype.add = function (transport, options, created) {
448
+ var instance = created ? transport : (new (transport)(options));
449
+
450
+ if (!instance.name && !instance.log) {
451
+ throw new Error('Unknown transport with no log() method');
452
+ }
453
+ else if (this.transports[instance.name]) {
454
+ throw new Error('Transport already attached: ' + instance.name);
455
+ }
456
+
457
+ this.transports[instance.name] = instance;
458
+ this._names = Object.keys(this.transports);
459
+
460
+ //
461
+ // Listen for the `error` event on the new Transport
462
+ //
463
+ instance._onError = this._onError.bind(this, instance)
464
+ if (!created) {
465
+ instance.on('error', instance._onError);
466
+ }
467
+
468
+ //
469
+ // If this transport has `handleExceptions` set to `true`
470
+ // and we are not already handling exceptions, do so.
471
+ //
472
+ if (instance.handleExceptions && !this.catchExceptions) {
473
+ this.handleExceptions();
474
+ }
475
+
476
+ return this;
477
+ };
478
+
479
+ //
480
+ // ### function addRewriter (transport, [options])
481
+ // #### @transport {Transport} Prototype of the Transport object to add.
482
+ // #### @options {Object} **Optional** Options for the Transport to add.
483
+ // #### @instance {Boolean} **Optional** Value indicating if `transport` is already instantiated.
484
+ // Adds a transport of the specified type to this instance.
485
+ //
486
+ Logger.prototype.addRewriter = function (rewriter) {
487
+ this.rewriters.push(rewriter);
488
+ }
489
+
490
+ //
491
+ // ### function addFilter (filter)
492
+ // #### @filter {function} Filter function, called with the message and
493
+ // optional metadata as the two arguments.
494
+ // Expected to return either the filtered message or an object with properties:
495
+ // - msg = the filtered message string
496
+ // - meta = the filtered metadata object
497
+ //
498
+ Logger.prototype.addFilter = function (filter) {
499
+ this.filters.push(filter);
500
+ }
501
+
502
+ //
503
+ // ### function clear ()
504
+ // Remove all transports from this instance
505
+ //
506
+ Logger.prototype.clear = function () {
507
+ for (var name in this.transports) {
508
+ this.remove({ name: name });
509
+ }
510
+ };
511
+
512
+ //
513
+ // ### function remove (transport)
514
+ // #### @transport {Transport|String} Transport or Name to remove.
515
+ // Removes a transport of the specified type from this instance.
516
+ //
517
+ Logger.prototype.remove = function (transport) {
518
+ var name = typeof transport !== 'string'
519
+ ? transport.name || transport.prototype.name
520
+ : transport;
521
+
522
+ if (!this.transports[name]) {
523
+ throw new Error('Transport ' + name + ' not attached to this instance');
524
+ }
525
+
526
+ var instance = this.transports[name];
527
+ delete this.transports[name];
528
+ this._names = Object.keys(this.transports);
529
+
530
+ if (instance.close) {
531
+ instance.close();
532
+ }
533
+
534
+ if (instance._onError) {
535
+ instance.removeListener('error', instance._onError);
536
+ }
537
+ return this;
538
+ };
539
+
540
+ var ProfileHandler = function (logger) {
541
+ this.logger = logger;
542
+
543
+ this.start = Date.now();
544
+
545
+ this.done = function (msg) {
546
+ var args, callback, meta;
547
+ args = Array.prototype.slice.call(arguments);
548
+ callback = typeof args[args.length - 1] === 'function' ? args.pop() : null;
549
+ meta = typeof args[args.length - 1] === 'object' ? args.pop() : {};
550
+
551
+ meta.durationMs = (Date.now()) - this.start;
552
+
553
+ return this.logger.info(msg, meta, callback);
554
+ }
555
+ }
556
+
557
+ Logger.prototype.startTimer = function () {
558
+ return new ProfileHandler(this);
559
+ }
560
+
561
+ //
562
+ // ### function profile (id, [msg, meta, callback])
563
+ // #### @id {string} Unique id of the profiler
564
+ // #### @msg {string} **Optional** Message to log
565
+ // #### @meta {Object} **Optional** Additional metadata to attach
566
+ // #### @callback {function} **Optional** Continuation to respond to when complete.
567
+ // Tracks the time inbetween subsequent calls to this method
568
+ // with the same `id` parameter. The second call to this method
569
+ // will log the difference in milliseconds along with the message.
570
+ //
571
+ Logger.prototype.profile = function (id) {
572
+ var now = Date.now(), then, args,
573
+ msg, meta, callback;
574
+
575
+ if (this.profilers[id]) {
576
+ then = this.profilers[id];
577
+ delete this.profilers[id];
578
+
579
+ // Support variable arguments: msg, meta, callback
580
+ args = Array.prototype.slice.call(arguments);
581
+ callback = typeof args[args.length - 1] === 'function' ? args.pop() : null;
582
+ meta = typeof args[args.length - 1] === 'object' ? args.pop() : {};
583
+ msg = args.length === 2 ? args[1] : id;
584
+
585
+ // Set the duration property of the metadata
586
+ meta.durationMs = now - then;
587
+ return this.info(msg, meta, callback);
588
+ }
589
+ else {
590
+ this.profilers[id] = now;
591
+ }
592
+
593
+ return this;
594
+ };
595
+
596
+ //
597
+ // ### function setLevels (target)
598
+ // #### @target {Object} Target levels to use on this instance
599
+ // Sets the `target` levels specified on this instance.
600
+ //
601
+ Logger.prototype.setLevels = function (target) {
602
+ return common.setLevels(this, this.levels, target);
603
+ };
604
+
605
+ //
606
+ // ### function cli ()
607
+ // Configures this instance to have the default
608
+ // settings for command-line interfaces: no timestamp,
609
+ // colors enabled, padded output, and additional levels.
610
+ //
611
+ Logger.prototype.cli = function () {
612
+ this.padLevels = true;
613
+ this.setLevels(config.cli.levels);
614
+ config.addColors(config.cli.colors);
615
+
616
+ if (this.transports.console) {
617
+ this.transports.console.colorize = this.transports.console.colorize || true;
618
+ this.transports.console.timestamp = this.transports.console.timestamp || false;
619
+ }
620
+
621
+ return this;
622
+ };
623
+
624
+ //
625
+ // ### @private function _uncaughtException (err)
626
+ // #### @err {Error} Error to handle
627
+ // Logs all relevant information around the `err` and
628
+ // exits the current process.
629
+ //
630
+ Logger.prototype._uncaughtException = function (err) {
631
+ var self = this,
632
+ responded = false,
633
+ info = exception.getAllInfo(err),
634
+ handlers = this._getExceptionHandlers(),
635
+ timeout,
636
+ doExit;
637
+
638
+ //
639
+ // Calculate if we should exit on this error
640
+ //
641
+ doExit = typeof this.exitOnError === 'function'
642
+ ? this.exitOnError(err)
643
+ : this.exitOnError;
644
+
645
+ function logAndWait(transport, next) {
646
+ transport.logException('uncaughtException: ' + (err.message || err), info, next, err);
647
+ }
648
+
649
+ function gracefulExit() {
650
+ if (doExit && !responded) {
651
+ //
652
+ // Remark: Currently ignoring any exceptions from transports
653
+ // when catching uncaught exceptions.
654
+ //
655
+ clearTimeout(timeout);
656
+ responded = true;
657
+ process.exit(1);
658
+ }
659
+ }
660
+
661
+ if (!handlers || handlers.length === 0) {
662
+ return gracefulExit();
663
+ }
664
+
665
+ //
666
+ // Log to all transports and allow the operation to take
667
+ // only up to `3000ms`.
668
+ //
669
+ async.forEach(handlers, logAndWait, gracefulExit);
670
+ if (doExit) {
671
+ timeout = setTimeout(gracefulExit, 3000);
672
+ }
673
+ };
674
+
675
+ //
676
+ // ### @private function _getExceptionHandlers ()
677
+ // Returns the list of transports and exceptionHandlers
678
+ // for this instance.
679
+ //
680
+ Logger.prototype._getExceptionHandlers = function () {
681
+ var self = this;
682
+
683
+ return this._hnames.map(function (name) {
684
+ return self.exceptionHandlers[name];
685
+ }).concat(this._names.map(function (name) {
686
+ return self.transports[name].handleExceptions && self.transports[name];
687
+ })).filter(Boolean);
688
+ };
689
+
690
+ //
691
+ // ### @private function _onError (transport, err)
692
+ // #### @transport {Object} Transport on which the error occured
693
+ // #### @err {Error} Error that occurred on the transport
694
+ // Bubbles the error, `err`, that occured on the specified `transport`
695
+ // up from this instance if `emitErrs` has been set.
696
+ //
697
+ Logger.prototype._onError = function (transport, err) {
698
+ if (this.emitErrs) {
699
+ this.emit('error', err, transport);
700
+ }
701
+ };