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.
- checksums.yaml +8 -8
- checksums.yaml.gz.asc +7 -7
- data.tar.gz.asc +7 -7
- data/CHANGELOG +38 -2
- data/CONTRIBUTORS +3 -0
- data/README.md +5 -1
- data/bin/passenger-status +2 -7
- data/build/agent.rb +2 -0
- data/build/cxx_dependency_map.rb +1464 -162
- data/build/node_tests.rb +1 -1
- data/build/packaging.rb +1 -1
- data/dev/ci/run_travis.sh +1 -1
- data/dev/vagrant/provision.sh +1 -1
- data/npm-shrinkwrap.json +635 -125
- data/package.json +1 -1
- data/resources/templates/standalone/config.erb +33 -161
- data/resources/templates/standalone/global.erb +15 -0
- data/resources/templates/standalone/http.erb +40 -0
- data/resources/templates/standalone/mass_deployment_default_server.erb +11 -0
- data/resources/templates/standalone/rails_asset_pipeline.erb +22 -0
- data/resources/templates/standalone/server.erb +58 -0
- data/src/agent/Core/ApiServer.h +37 -32
- data/src/agent/Core/ApplicationPool/BasicGroupInfo.h +1 -1
- data/src/agent/Core/ApplicationPool/BasicProcessInfo.h +6 -0
- data/src/agent/Core/ApplicationPool/Common.h +1 -1
- data/src/agent/Core/ApplicationPool/Group/OutOfBandWork.cpp +1 -1
- data/src/agent/Core/ApplicationPool/Group/ProcessListManagement.cpp +4 -0
- data/src/agent/Core/ApplicationPool/Implementation.cpp +2 -2
- data/src/agent/Core/ApplicationPool/Options.h +18 -1
- data/src/agent/Core/ApplicationPool/Pool.h +1 -1
- data/src/agent/Core/ApplicationPool/Pool/AnalyticsCollection.cpp +6 -6
- data/src/agent/Core/ApplicationPool/Pool/GeneralUtils.cpp +3 -3
- data/src/agent/Core/ApplicationPool/Pool/InitializationAndShutdown.cpp +1 -1
- data/src/agent/Core/ApplicationPool/Pool/Miscellaneous.cpp +6 -0
- data/src/agent/Core/ApplicationPool/Process.h +6 -1
- data/src/agent/Core/ApplicationPool/Socket.h +9 -12
- data/src/agent/Core/Controller.h +422 -0
- data/src/agent/Core/{RequestHandler → Controller}/AppResponse.h +2 -0
- data/src/agent/Core/{RequestHandler → Controller}/BufferBody.cpp +27 -5
- data/src/agent/Core/{RequestHandler → Controller}/CheckoutSession.cpp +61 -31
- data/src/agent/Core/{RequestHandler → Controller}/Client.h +5 -2
- data/src/agent/Core/{RequestHandler → Controller}/ForwardResponse.cpp +93 -42
- data/src/agent/Core/{RequestHandler → Controller}/Hooks.cpp +107 -60
- data/src/agent/Core/Controller/Implementation.cpp +38 -0
- data/src/agent/Core/{RequestHandler → Controller}/InitRequest.cpp +134 -80
- data/src/agent/Core/Controller/InitializationAndShutdown.cpp +165 -0
- data/src/agent/Core/{RequestHandler/Utils.cpp → Controller/InternalUtils.cpp} +49 -32
- data/src/agent/Core/Controller/Miscellaneous.cpp +116 -0
- data/src/agent/Core/{RequestHandler → Controller}/Request.h +6 -4
- data/src/agent/Core/{RequestHandler → Controller}/SendRequest.cpp +205 -130
- data/src/agent/Core/Controller/StateInspectionAndConfiguration.cpp +161 -0
- data/src/agent/Core/{RequestHandler → Controller}/TurboCaching.h +3 -0
- data/src/agent/Core/CoreMain.cpp +62 -51
- data/src/agent/Core/OptionParser.h +24 -0
- data/src/agent/Core/ResponseCache.h +5 -5
- data/src/agent/Core/SpawningKit/Config.h +2 -2
- data/src/agent/Core/SpawningKit/SmartSpawner.h +1 -1
- data/src/agent/Core/UnionStation/{Core.h → Context.h} +14 -18
- data/src/agent/Core/UnionStation/StopwatchLog.h +3 -2
- data/src/agent/Core/UnionStation/Transaction.h +7 -7
- data/src/agent/Shared/ApiServerUtils.h +9 -1
- data/src/agent/UstRouter/ApiServer.h +5 -2
- data/src/agent/UstRouter/Controller.h +27 -9
- data/src/agent/UstRouter/UstRouterMain.cpp +1 -0
- data/src/agent/Watchdog/ApiServer.h +5 -2
- data/src/apache2_module/ConfigurationCommands.cpp +7 -0
- data/src/apache2_module/ConfigurationFields.hpp +2 -0
- data/src/apache2_module/ConfigurationSetters.cpp +24 -0
- data/src/apache2_module/CreateDirConfig.cpp +1 -0
- data/src/apache2_module/Hooks.cpp +6 -5
- data/src/apache2_module/MergeDirConfig.cpp +7 -0
- data/src/apache2_module/SetHeaders.cpp +5 -0
- data/src/cxx_supportlib/Constants.h +5 -3
- data/src/cxx_supportlib/SafeLibev.h +2 -1
- data/src/cxx_supportlib/UnionStationFilterSupport.h +2 -1
- data/src/cxx_supportlib/Utils/ReleaseableScopedPointer.h +70 -0
- data/src/cxx_supportlib/vendor-modified/boost/libs/regex/src/regex_raw_buffer.cpp +6 -6
- data/src/helper-scripts/node-loader.js +59 -0
- data/src/nginx_module/CacheLocationConfig.c +48 -0
- data/src/nginx_module/ConfigurationCommands.c +20 -0
- data/src/nginx_module/ConfigurationFields.h +4 -0
- data/src/nginx_module/CreateLocationConfig.c +8 -0
- data/src/nginx_module/MergeLocationConfig.c +12 -0
- data/src/nodejs_supportlib/phusion_passenger/log_express.js +106 -0
- data/src/nodejs_supportlib/phusion_passenger/log_mongodb.js +203 -0
- data/src/nodejs_supportlib/phusion_passenger/ustreporter.js +227 -0
- data/src/nodejs_supportlib/phusion_passenger/ustrouter_connector.js +446 -0
- data/src/nodejs_supportlib/vendor-copy/codify/codify.js +44 -0
- data/src/nodejs_supportlib/vendor-copy/codify/package.json +29 -0
- data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/context.js +200 -0
- data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/async-listener/glue.js +488 -0
- data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/async-listener/index.js +407 -0
- data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/async-listener/node_modules/shimmer/index.js +90 -0
- data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/async-listener/node_modules/shimmer/package.json +40 -0
- data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/async-listener/package.json +54 -0
- data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/emitter-listener/listener.js +160 -0
- data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/emitter-listener/node_modules/shimmer/index.js +90 -0
- data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/emitter-listener/node_modules/shimmer/package.json +40 -0
- data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/emitter-listener/package.json +46 -0
- data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/package.json +56 -0
- data/src/nodejs_supportlib/vendor-copy/network-byte-order/lib/index.js +102 -0
- data/src/nodejs_supportlib/vendor-copy/network-byte-order/package.json +51 -0
- data/src/nodejs_supportlib/vendor-copy/winston/LICENSE +19 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston.js +165 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/common.js +483 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/config.js +62 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/config/cli-config.js +35 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/config/npm-config.js +27 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/config/syslog-config.js +31 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/container.js +127 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/exception.js +56 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/logger.js +701 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports.js +34 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/console.js +128 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/daily-rotate-file.js +601 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/file.js +675 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/http.js +232 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/memory.js +89 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/transport.js +135 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/webhook.js +146 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/async/LICENSE +19 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/async/lib/async.js +1283 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/async/package.json +66 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/async/support/sync-package-managers.js +53 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/MIT-LICENSE.txt +23 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/colors.js +176 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/custom/trap.js +45 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/custom/zalgo.js +104 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/extendStringPrototype.js +118 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/index.js +12 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/maps/america.js +12 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/maps/rainbow.js +13 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/maps/random.js +8 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/maps/zebra.js +5 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/styles.js +77 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/system/supports-colors.js +61 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/package.json +35 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/safe.js +9 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/themes/generic-logging.js +12 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/cycle/cycle.js +170 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/cycle/package.json +30 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/eyes/LICENSE +20 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/eyes/lib/eyes.js +236 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/eyes/package.json +42 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/isstream/LICENSE.md +11 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/isstream/isstream.js +27 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/isstream/package.json +42 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/pkginfo/LICENSE +19 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/pkginfo/lib/pkginfo.js +136 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/pkginfo/package.json +56 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/stack-trace/License +19 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/stack-trace/lib/stack-trace.js +111 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/stack-trace/package.json +33 -0
- data/src/nodejs_supportlib/vendor-copy/winston/package.json +87 -0
- data/src/ruby_supportlib/phusion_passenger.rb +3 -4
- data/src/ruby_supportlib/phusion_passenger/admin_tools/instance.rb +19 -2
- data/src/ruby_supportlib/phusion_passenger/apache2/config_options.rb +8 -0
- data/src/ruby_supportlib/phusion_passenger/config/list_instances_command.rb +2 -6
- data/src/ruby_supportlib/phusion_passenger/config/reopen_logs_command.rb +13 -0
- data/src/ruby_supportlib/phusion_passenger/config/restart_app_command.rb +3 -0
- data/src/ruby_supportlib/phusion_passenger/config/utils.rb +9 -7
- data/src/ruby_supportlib/phusion_passenger/config/validate_install_command.rb +8 -1
- data/src/ruby_supportlib/phusion_passenger/constants.rb +3 -1
- data/src/ruby_supportlib/phusion_passenger/native_support.rb +20 -4
- data/src/ruby_supportlib/phusion_passenger/nginx/config_options.rb +8 -0
- data/src/ruby_supportlib/phusion_passenger/packaging.rb +1 -0
- data/src/ruby_supportlib/phusion_passenger/platform_info/apache_detector.rb +1 -1
- data/src/ruby_supportlib/phusion_passenger/platform_info/operating_system.rb +11 -4
- data/src/ruby_supportlib/phusion_passenger/rack/thread_handler_extension.rb +1 -1
- data/src/ruby_supportlib/phusion_passenger/standalone/config_options_list.rb +647 -0
- data/src/ruby_supportlib/phusion_passenger/standalone/config_utils.rb +229 -15
- data/src/ruby_supportlib/phusion_passenger/standalone/start_command.rb +35 -323
- data/src/ruby_supportlib/phusion_passenger/standalone/start_command/builtin_engine.rb +36 -12
- data/src/ruby_supportlib/phusion_passenger/standalone/start_command/nginx_engine.rb +123 -14
- data/src/ruby_supportlib/phusion_passenger/standalone/status_command.rb +32 -17
- data/src/ruby_supportlib/phusion_passenger/standalone/stop_command.rb +32 -21
- data/src/ruby_supportlib/phusion_passenger/standalone/version_command.rb +5 -5
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/README.md +2 -2
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/Rakefile +5 -1
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core.rb +68 -24
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/api.rb +9 -1
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/context.rb +9 -7
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/request_reporter.rb +3 -2
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/request_reporter/basics.rb +8 -5
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/simple_json.rb +395 -0
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/transaction.rb +10 -7
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/utils.rb +14 -0
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/version_data.rb +2 -2
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml +4 -2
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml.example +2 -2
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml.travis +2 -2
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml.travis-with-sudo +16 -0
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/Gemfile +1 -1
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/Gemfile.lock +2 -2
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/README.md +1 -1
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails.rb +44 -17
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/active_support_cache_subscriber.rb +16 -7
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/version_data.rb +2 -2
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/union_station_hooks_rails.gemspec +1 -1
- metadata +99 -16
- metadata.gz.asc +7 -7
- data/resources/oss-binaries.phusionpassenger.com.crt +0 -248
- 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
|
+
};
|