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,232 @@
1
+ var util = require('util'),
2
+ winston = require('../../winston'),
3
+ http = require('http'),
4
+ https = require('https'),
5
+ Stream = require('stream').Stream,
6
+ Transport = require('./transport').Transport;
7
+
8
+ //
9
+ // ### function Http (options)
10
+ // #### @options {Object} Options for this instance.
11
+ // Constructor function for the Http transport object responsible
12
+ // for persisting log messages and metadata to a terminal or TTY.
13
+ //
14
+ var Http = exports.Http = function (options) {
15
+ Transport.call(this, options);
16
+ options = options || {};
17
+
18
+ this.name = 'http';
19
+ this.ssl = !!options.ssl;
20
+ this.host = options.host || 'localhost';
21
+ this.port = options.port;
22
+ this.auth = options.auth;
23
+ this.path = options.path || '';
24
+
25
+ if (!this.port) {
26
+ this.port = this.ssl ? 443 : 80;
27
+ }
28
+ };
29
+
30
+ util.inherits(Http, winston.Transport);
31
+
32
+ //
33
+ // Expose the name of this Transport on the prototype
34
+ //
35
+ Http.prototype.name = 'http';
36
+
37
+ //
38
+ // ### function _request (options, callback)
39
+ // #### @callback {function} Continuation to respond to when complete.
40
+ // Make a request to a winstond server or any http server which can
41
+ // handle json-rpc.
42
+ //
43
+ Http.prototype._request = function (options, callback) {
44
+ options = options || {};
45
+
46
+ var auth = options.auth || this.auth,
47
+ path = options.path || this.path || '',
48
+ req;
49
+
50
+ delete options.auth;
51
+ delete options.path;
52
+
53
+ // Prepare options for outgoing HTTP request
54
+ req = (this.ssl ? https : http).request({
55
+ host: this.host,
56
+ port: this.port,
57
+ path: '/' + path.replace(/^\//, ''),
58
+ method: 'POST',
59
+ headers: { 'Content-Type': 'application/json' },
60
+ auth: (auth) ? auth.username + ':' + auth.password : ''
61
+ });
62
+
63
+ req.on('error', callback);
64
+ req.on('response', function (res) {
65
+ res.on('end', function () {
66
+ callback(null, res);
67
+ });
68
+
69
+ res.resume();
70
+ });
71
+
72
+ req.end(new Buffer(JSON.stringify(options), 'utf8'));
73
+ };
74
+
75
+ //
76
+ // ### function log (level, msg, [meta], callback)
77
+ // #### @level {string} Level at which to log the message.
78
+ // #### @msg {string} Message to log
79
+ // #### @meta {Object} **Optional** Additional metadata to attach
80
+ // #### @callback {function} Continuation to respond to when complete.
81
+ // Core logging method exposed to Winston. Metadata is optional.
82
+ //
83
+ Http.prototype.log = function (level, msg, meta, callback) {
84
+ var self = this;
85
+
86
+ if (typeof meta === 'function') {
87
+ callback = meta;
88
+ meta = {};
89
+ }
90
+
91
+ var options = {
92
+ method: 'collect',
93
+ params: {
94
+ level: level,
95
+ message: msg,
96
+ meta: meta
97
+ }
98
+ };
99
+
100
+ if (meta) {
101
+ if (meta.path) {
102
+ options.path = meta.path;
103
+ delete meta.path;
104
+ }
105
+
106
+ if (meta.auth) {
107
+ options.auth = meta.auth;
108
+ delete meta.auth;
109
+ }
110
+ }
111
+
112
+ this._request(options, function (err, res) {
113
+ if (res && res.statusCode !== 200) {
114
+ err = new Error('HTTP Status Code: ' + res.statusCode);
115
+ }
116
+
117
+ if (err) return callback(err);
118
+
119
+ // TODO: emit 'logged' correctly,
120
+ // keep track of pending logs.
121
+ self.emit('logged');
122
+
123
+ if (callback) callback(null, true);
124
+ });
125
+ };
126
+
127
+ //
128
+ // ### function query (options, callback)
129
+ // #### @options {Object} Loggly-like query options for this instance.
130
+ // #### @callback {function} Continuation to respond to when complete.
131
+ // Query the transport. Options object is optional.
132
+ //
133
+ Http.prototype.query = function (options, callback) {
134
+ if (typeof options === 'function') {
135
+ callback = options;
136
+ options = {};
137
+ }
138
+
139
+ var self = this,
140
+ options = this.normalizeQuery(options);
141
+
142
+ options = {
143
+ method: 'query',
144
+ params: options
145
+ };
146
+
147
+ if (options.params.path) {
148
+ options.path = options.params.path;
149
+ delete options.params.path;
150
+ }
151
+
152
+ if (options.params.auth) {
153
+ options.auth = options.params.auth;
154
+ delete options.params.auth;
155
+ }
156
+
157
+ this._request(options, function (err, res, body) {
158
+ if (res && res.statusCode !== 200) {
159
+ err = new Error('HTTP Status Code: ' + res.statusCode);
160
+ }
161
+
162
+ if (err) return callback(err);
163
+
164
+ if (typeof body === 'string') {
165
+ try {
166
+ body = JSON.parse(body);
167
+ } catch (e) {
168
+ return callback(e);
169
+ }
170
+ }
171
+
172
+ callback(null, body);
173
+ });
174
+ };
175
+
176
+ //
177
+ // ### function stream (options)
178
+ // #### @options {Object} Stream options for this instance.
179
+ // Returns a log stream for this transport. Options object is optional.
180
+ //
181
+ Http.prototype.stream = function (options) {
182
+ options = options || {};
183
+
184
+ var self = this,
185
+ stream = new Stream,
186
+ req,
187
+ buff;
188
+
189
+ stream.destroy = function () {
190
+ req.destroy();
191
+ };
192
+
193
+ options = {
194
+ method: 'stream',
195
+ params: options
196
+ };
197
+
198
+ if (options.params.path) {
199
+ options.path = options.params.path;
200
+ delete options.params.path;
201
+ }
202
+
203
+ if (options.params.auth) {
204
+ options.auth = options.params.auth;
205
+ delete options.params.auth;
206
+ }
207
+
208
+ req = this._request(options);
209
+ buff = '';
210
+
211
+ req.on('data', function (data) {
212
+ var data = (buff + data).split(/\n+/),
213
+ l = data.length - 1,
214
+ i = 0;
215
+
216
+ for (; i < l; i++) {
217
+ try {
218
+ stream.emit('log', JSON.parse(data[i]));
219
+ } catch (e) {
220
+ stream.emit('error', e);
221
+ }
222
+ }
223
+
224
+ buff = data[l];
225
+ });
226
+
227
+ req.on('error', function (err) {
228
+ stream.emit('error', err);
229
+ });
230
+
231
+ return stream;
232
+ };
@@ -0,0 +1,89 @@
1
+ var events = require('events'),
2
+ util = require('util'),
3
+ common = require('../common'),
4
+ Transport = require('./transport').Transport;
5
+
6
+ //
7
+ // ### function Memory (options)
8
+ // #### @options {Object} Options for this instance.
9
+ // Constructor function for the Memory transport object responsible
10
+ // for persisting log messages and metadata to a memory array of messages.
11
+ //
12
+ var Memory = exports.Memory = function (options) {
13
+ Transport.call(this, options);
14
+ options = options || {};
15
+
16
+ this.errorOutput = [];
17
+ this.writeOutput = [];
18
+
19
+ this.json = options.json || false;
20
+ this.colorize = options.colorize || false;
21
+ this.prettyPrint = options.prettyPrint || false;
22
+ this.timestamp = typeof options.timestamp !== 'undefined' ? options.timestamp : false;
23
+ this.showLevel = options.showLevel === undefined ? true : options.showLevel;
24
+ this.label = options.label || null;
25
+ this.depth = options.depth || null;
26
+
27
+ if (this.json) {
28
+ this.stringify = options.stringify || function (obj) {
29
+ return JSON.stringify(obj, null, 2);
30
+ };
31
+ }
32
+ };
33
+
34
+ //
35
+ // Inherit from `winston.Transport`.
36
+ //
37
+ util.inherits(Memory, Transport);
38
+
39
+ //
40
+ // Expose the name of this Transport on the prototype
41
+ //
42
+ Memory.prototype.name = 'memory';
43
+
44
+ //
45
+ // ### function log (level, msg, [meta], callback)
46
+ // #### @level {string} Level at which to log the message.
47
+ // #### @msg {string} Message to log
48
+ // #### @meta {Object} **Optional** Additional metadata to attach
49
+ // #### @callback {function} Continuation to respond to when complete.
50
+ // Core logging method exposed to Winston. Metadata is optional.
51
+ //
52
+ Memory.prototype.log = function (level, msg, meta, callback) {
53
+ if (this.silent) {
54
+ return callback(null, true);
55
+ }
56
+
57
+ var self = this,
58
+ output;
59
+
60
+ output = common.log({
61
+ colorize: this.colorize,
62
+ json: this.json,
63
+ level: level,
64
+ message: msg,
65
+ meta: meta,
66
+ stringify: this.stringify,
67
+ timestamp: this.timestamp,
68
+ prettyPrint: this.prettyPrint,
69
+ raw: this.raw,
70
+ label: this.label,
71
+ depth: this.depth,
72
+ formatter: this.formatter,
73
+ humanReadableUnhandledException: this.humanReadableUnhandledException
74
+ });
75
+
76
+ if (level === 'error' || level === 'debug') {
77
+ this.errorOutput.push(output);
78
+ } else {
79
+ this.writeOutput.push(output);
80
+ }
81
+
82
+ self.emit('logged');
83
+ callback(null, true);
84
+ };
85
+
86
+ Memory.prototype.clearLogs = function () {
87
+ this.errorOutput = [];
88
+ this.writeOutput = [];
89
+ };
@@ -0,0 +1,135 @@
1
+ /*
2
+ * transport.js: Base Transport object for all Winston transports.
3
+ *
4
+ * (C) 2010 Charlie Robbins
5
+ * MIT LICENCE
6
+ *
7
+ */
8
+
9
+ var events = require('events'),
10
+ util = require('util');
11
+
12
+ //
13
+ // ### function Transport (options)
14
+ // #### @options {Object} Options for this instance.
15
+ // Constructor function for the Tranport object responsible
16
+ // base functionality for all winston transports.
17
+ //
18
+ var Transport = exports.Transport = function (options) {
19
+ events.EventEmitter.call(this);
20
+
21
+ options = options || {};
22
+ this.silent = options.silent || false;
23
+ this.raw = options.raw || false;
24
+ this.name = options.name || this.name;
25
+ this.formatter = options.formatter;
26
+
27
+ //
28
+ // Do not set a default level. When `level` is falsey on any
29
+ // `Transport` instance, any `Logger` instance uses the
30
+ // configured level (instead of the Transport level)
31
+ //
32
+ this.level = options.level;
33
+
34
+ this.handleExceptions = options.handleExceptions || false;
35
+ this.exceptionsLevel = options.exceptionsLevel || 'error';
36
+ this.humanReadableUnhandledException = options.humanReadableUnhandledException || false;
37
+ };
38
+
39
+ //
40
+ // Inherit from `events.EventEmitter`.
41
+ //
42
+ util.inherits(Transport, events.EventEmitter);
43
+
44
+ //
45
+ // ### function formatQuery (query)
46
+ // #### @query {string|Object} Query to format
47
+ // Formats the specified `query` Object (or string) to conform
48
+ // with the underlying implementation of this transport.
49
+ //
50
+ Transport.prototype.formatQuery = function (query) {
51
+ return query;
52
+ };
53
+
54
+ //
55
+ // ### function normalizeQuery (query)
56
+ // #### @options {string|Object} Query to normalize
57
+ // Normalize options for query
58
+ //
59
+ Transport.prototype.normalizeQuery = function (options) {
60
+ //
61
+ // Use options similar to loggly.
62
+ // [See Loggly Search API](http://wiki.loggly.com/retrieve_events#optional)
63
+ //
64
+
65
+ options = options || {};
66
+
67
+ // limit
68
+ options.rows = options.rows || options.limit || 10;
69
+
70
+ // starting row offset
71
+ options.start = options.start || 0;
72
+
73
+ // now
74
+ options.until = options.until || new Date;
75
+ if (typeof options.until !== 'object') {
76
+ options.until = new Date(options.until);
77
+ }
78
+
79
+ // now - 24
80
+ options.from = options.from || (options.until - (24 * 60 * 60 * 1000));
81
+ if (typeof options.from !== 'object') {
82
+ options.from = new Date(options.from);
83
+ }
84
+
85
+
86
+ // 'asc' or 'desc'
87
+ options.order = options.order || 'desc';
88
+
89
+ // which fields to select
90
+ options.fields = options.fields;
91
+
92
+ return options;
93
+ };
94
+
95
+ //
96
+ // ### function formatResults (results, options)
97
+ // #### @results {Object|Array} Results returned from `.query`.
98
+ // #### @options {Object} **Optional** Formatting options
99
+ // Formats the specified `results` with the given `options` accordinging
100
+ // to the implementation of this transport.
101
+ //
102
+ Transport.prototype.formatResults = function (results, options) {
103
+ return results;
104
+ };
105
+
106
+ //
107
+ // ### function logException (msg, meta, callback)
108
+ // #### @msg {string} Message to log
109
+ // #### @meta {Object} **Optional** Additional metadata to attach
110
+ // #### @callback {function} Continuation to respond to when complete.
111
+ // Logs the specified `msg`, `meta` and responds to the callback once the log
112
+ // operation is complete to ensure that the event loop will not exit before
113
+ // all logging has completed.
114
+ //
115
+ Transport.prototype.logException = function (msg, meta, callback) {
116
+ var self = this,
117
+ called;
118
+
119
+ if (this.silent) {
120
+ return callback();
121
+ }
122
+
123
+ function onComplete () {
124
+ if (!called) {
125
+ called = true;
126
+ self.removeListener('logged', onComplete);
127
+ self.removeListener('error', onComplete);
128
+ callback();
129
+ }
130
+ }
131
+
132
+ this.once('logged', onComplete);
133
+ this.once('error', onComplete);
134
+ this.log(self.exceptionsLevel, msg, meta, function () { });
135
+ };