-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[logging] Support configuration reloads for logging. Fixes #4407.
- Loading branch information
Showing
6 changed files
with
94 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import _ from 'lodash'; | ||
import logReporter from './log_reporter'; | ||
|
||
export default function loggingConfiguration(config) { | ||
let events = config.get('logging.events'); | ||
|
||
if (config.get('logging.silent')) { | ||
_.defaults(events, {}); | ||
} | ||
else if (config.get('logging.quiet')) { | ||
_.defaults(events, { | ||
log: ['listening', 'error', 'fatal'], | ||
request: ['error'], | ||
error: '*' | ||
}); | ||
} | ||
else if (config.get('logging.verbose')) { | ||
_.defaults(events, { | ||
log: '*', | ||
ops: '*', | ||
request: '*', | ||
response: '*', | ||
error: '*' | ||
}); | ||
} | ||
else { | ||
_.defaults(events, { | ||
log: ['info', 'warning', 'error', 'fatal'], | ||
response: config.get('logging.json') ? '*' : '!', | ||
request: ['info', 'warning', 'error', 'fatal'], | ||
error: '*' | ||
}); | ||
} | ||
|
||
const options = { | ||
opsInterval: config.get('ops.interval'), | ||
requestHeaders: true, | ||
requestPayload: true, | ||
reporters: [ | ||
{ | ||
reporter: logReporter, | ||
config: { | ||
json: config.get('logging.json'), | ||
dest: config.get('logging.dest'), | ||
// I'm adding the default here because if you add another filter | ||
// using the commandline it will remove authorization. I want users | ||
// to have to explicitly set --logging.filter.authorization=none to | ||
// have it show up int he logs. | ||
filter: _.defaults(config.get('logging.filter'), { | ||
authorization: 'remove' | ||
}) | ||
}, | ||
events: _.transform(events, function (filtered, val, key) { | ||
// provide a string compatible way to remove events | ||
if (val !== '!') filtered[key] = val; | ||
}, {}) | ||
} | ||
] | ||
}; | ||
return options; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,15 @@ | ||
import _ from 'lodash'; | ||
import { fromNode } from 'bluebird'; | ||
import evenBetter from 'even-better'; | ||
import loggingConfiguration from './configuration'; | ||
|
||
module.exports = function (kbnServer, server, config) { | ||
export default function (kbnServer, server, config) { | ||
// prevent relying on kbnServer so this can be used with other hapi servers | ||
kbnServer = null; | ||
|
||
return fromNode(function (cb) { | ||
let events = config.get('logging.events'); | ||
|
||
if (config.get('logging.silent')) { | ||
_.defaults(events, {}); | ||
} | ||
else if (config.get('logging.quiet')) { | ||
_.defaults(events, { | ||
log: ['listening', 'error', 'fatal'], | ||
request: ['error'], | ||
error: '*' | ||
}); | ||
} | ||
else if (config.get('logging.verbose')) { | ||
_.defaults(events, { | ||
log: '*', | ||
ops: '*', | ||
request: '*', | ||
response: '*', | ||
error: '*' | ||
}); | ||
} | ||
else { | ||
_.defaults(events, { | ||
log: ['info', 'warning', 'error', 'fatal'], | ||
response: config.get('logging.json') ? '*' : '!', | ||
request: ['info', 'warning', 'error', 'fatal'], | ||
error: '*' | ||
}); | ||
} | ||
|
||
server.register({ | ||
register: require('good'), | ||
options: { | ||
opsInterval: config.get('ops.interval'), | ||
requestHeaders: true, | ||
requestPayload: true, | ||
reporters: [ | ||
{ | ||
reporter: require('./log_reporter'), | ||
config: { | ||
json: config.get('logging.json'), | ||
dest: config.get('logging.dest'), | ||
// I'm adding the default here because if you add another filter | ||
// using the commandline it will remove authorization. I want users | ||
// to have to explicitly set --logging.filter.authorization=none to | ||
// have it show up int he logs. | ||
filter: _.defaults(config.get('logging.filter'), { | ||
authorization: 'remove' | ||
}) | ||
}, | ||
events: _.transform(events, function (filtered, val, key) { | ||
// provide a string compatible way to remove events | ||
if (val !== '!') filtered[key] = val; | ||
}, {}) | ||
} | ||
] | ||
} | ||
register: evenBetter, | ||
options: loggingConfiguration(config) | ||
}, cb); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters