Skip to content

Commit 98acb52

Browse files
author
Eran Hammer
committed
Split debug setting. Closes hapijs#2247
1 parent e6c369d commit 98acb52

File tree

5 files changed

+26
-12
lines changed

5 files changed

+26
-12
lines changed

docs/Reference.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,23 @@ Creates a new `Server` object where:
162162
[`server.state()`](#serverstatename-options) or implicitly (without definition) using
163163
the [state configuration](#serverstatename-options) object.
164164

165-
- `debug` - determines which logged events are sent to the console:
165+
- `debug` - determines which logged events are sent to the console (this should only be used
166+
for development and does not affect which events are actually logged internally and
167+
recorded). Set to `false` to disable all console logging, or to an object with:
168+
- `log` - a string array of server log tags to be displayed via `console.error()` when
169+
the events are logged via [`server.log()`](#serverlogtags-data-timestamp) as well as
170+
internally generated [server logs](#server-logs). For example, to display all errors,
171+
set the option to `['error']`. To turn off all console debug messages set it to `false`.
172+
Defaults to uncaught errors thrown in external code (these errors are handled
173+
automatically and result in an Internal Server Error response) or runtime errors due to
174+
developer error.
166175
- `request` - a string array of request log tags to be displayed via `console.error()` when
167-
the events are logged via [`request.log()`](#requestlogtags-data-timestamp). Defaults to
168-
uncaught errors thrown in external code (these errors are handled automatically and
169-
result in an Internal Server Error response) or runtime errors due to developer error.
170-
For example, to display all errors, change the option to `['error']`. To turn off all
171-
console debug messages set it to `false`.
176+
the events are logged via [`request.log()`](#requestlogtags-data-timestamp) as well as
177+
internally generated [request logs](#request-logs). For example, to display all errors,
178+
set the option to `['error']`. To turn off all console debug messages set it to `false`.
179+
Defaults to uncaught errors thrown in external code (these errors are handled
180+
automatically and result in an Internal Server Error response) or runtime errors due to
181+
developer error.
172182

173183
- `files` - file system related settings:
174184
- `etagsCacheMaxSize` - sets the maximum number of file etag hash values stored in the

lib/defaults.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ var Os = require('os');
66
// Declare internals
77

88
exports.server = {
9-
debug: { request: ['implementation'] },
9+
debug: {
10+
request: ['implementation'],
11+
log: ['implementation']
12+
},
1013
load: {
1114
sampleInterval: 0
1215
},

lib/plugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,8 @@ internals.Plugin.prototype.log = function (tags, data, timestamp, _internal) {
360360
this.root._events.emit('log', event, tagsMap);
361361

362362
if (this.root._settings.debug &&
363-
this.root._settings.debug.request &&
364-
Hoek.intersect(tagsMap, this.root._settings.debug.request, true)) {
363+
this.root._settings.debug.log &&
364+
Hoek.intersect(tagsMap, this.root._settings.debug.log, true)) {
365365

366366
console.error('Debug:', event.tags.join(', '), (data ? '\n ' + (data.stack || (typeof data === 'object' ? Hoek.stringify(data) : data)) : ''));
367367
}

lib/schema.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ internals.server = Joi.object({
174174
]).allow(null),
175175
connections: internals.connectionBase,
176176
debug: Joi.object({
177-
request: Joi.array().allow(false)
177+
request: Joi.array().allow(false),
178+
log: Joi.array().allow(false)
178179
}).allow(false),
179180
files: Joi.object({
180181
etagsCacheMaxSize: Joi.number().min(0)

test/plugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,9 +1712,9 @@ describe('Plugin', function () {
17121712
done();
17131713
});
17141714

1715-
it('does not output events when debug.request disabled', function (done) {
1715+
it('does not output events when debug.log disabled', function (done) {
17161716

1717-
var server = new Hapi.Server({ debug: { request: false } });
1717+
var server = new Hapi.Server({ debug: { log: false } });
17181718
server.connection();
17191719

17201720
var i = 0;

0 commit comments

Comments
 (0)