fxa-oauth-server/lib/logging/summary.js

39 строки
1.1 KiB
JavaScript
Исходник Обычный вид История

2014-05-09 23:23:41 +04:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const logger = require('./')('summary');
2014-05-09 23:23:41 +04:00
module.exports = function summary(request, response) {
if (request.method === 'options') {
return;
}
var payload = request.payload || {};
var query = request.query || {};
var params = request.params || {};
var auth = request.auth && request.auth.credentials && {
user: request.auth.credentials.user,
scope: request.auth.credentials.scope
};
2014-05-09 23:23:41 +04:00
var line = {
code: response.isBoom ? response.output.statusCode : response.statusCode,
errno: response.errno || 0,
method: request.method,
2014-05-09 23:23:41 +04:00
path: request.path,
agent: request.headers['user-agent'],
t: Date.now() - request.info.received,
client_id: payload.client_id || query.client_id || params.client_id,
auth: auth,
payload: Object.keys(payload)
2014-05-09 23:23:41 +04:00
};
if (line.code >= 500) {
line.stack = response.stack;
logger.error('summary', line);
2014-05-09 23:23:41 +04:00
} else {
logger.info('summary', line);
2014-05-09 23:23:41 +04:00
}
};