-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: fixed error handling * feat: Plugin system added * chore: Registry & server router now switched to the internal logger * wrapFetchWithCache now switched to the internal logger * chore: More verbose tests for error logging * chore: README update
- Loading branch information
Showing
15 changed files
with
220 additions
and
58 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
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 was deleted.
Oops, something went wrong.
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,57 @@ | ||
const httpHeaders = require('http-headers'); | ||
|
||
module.exports = { | ||
level: 'info', | ||
//nestedKey: 'payload', TODO: blocked by https://github.com/pinojs/pino/issues/883 | ||
hooks: { | ||
logMethod(inputArgs, method) { | ||
if (inputArgs[0] instanceof Error) { | ||
const err = inputArgs[0]; | ||
|
||
const causeData = []; | ||
let rawErr = err.cause; | ||
while (rawErr) { | ||
if (rawErr.data) { | ||
causeData.push(rawErr.data); | ||
} else { | ||
causeData.push({}); | ||
} | ||
rawErr = rawErr.cause; | ||
} | ||
|
||
const logObj = { | ||
type: err.name, | ||
message: err.message, | ||
stack: err.stack.split("\n"), | ||
}; | ||
if (err.data) { | ||
logObj.additionalInfo = err.data; | ||
} | ||
if (causeData.length) { | ||
logObj.causeData = causeData; | ||
} | ||
inputArgs[0] = logObj; | ||
} | ||
|
||
return method.apply(this, inputArgs) | ||
} | ||
}, | ||
serializers: { | ||
res(res) { | ||
const r = { | ||
statusCode: res.statusCode, | ||
}; | ||
|
||
if (r.statusCode >= 300 && r.statusCode < 400) { | ||
const headers = httpHeaders(res, true); | ||
if (headers['location']) { | ||
r.headers = { | ||
location: headers['location'] | ||
}; | ||
} | ||
} | ||
|
||
return r; | ||
} | ||
} | ||
}; |
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,18 @@ | ||
'use strict'; | ||
|
||
const _ = require('lodash'); | ||
const pluginManager = require('../pluginManager/factory'); | ||
|
||
|
||
let fastifyConf = pluginManager.getReportingPlugin(); | ||
if (fastifyConf === null) { | ||
const hyperid = require('hyperid') | ||
const instance = hyperid({urlSafe: true, fixedLength: true}); | ||
|
||
fastifyConf = { | ||
logger: require('./index'), | ||
genReqId: instance, | ||
} | ||
} | ||
|
||
module.exports = _.omit(_.pick(fastifyConf, ['logger', 'requestIdLogLabel', 'genReqId']), _.isEmpty); |
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,22 @@ | ||
'use strict'; | ||
|
||
const {PassThrough} = require('stream'); | ||
const pluginManager = require('../pluginManager/factory'); | ||
const pino = require('pino'); | ||
|
||
let logger = pluginManager.getReportingPlugin(); | ||
if (logger === null) { | ||
let destStream = process.stdout; | ||
// We need this to being able to capture stdout of the app. | ||
// As for pure "process.stdout" uses faster logs output via sonic-boom | ||
// which is hard to intercept | ||
if (process.env.NODE_ENV === 'test') { | ||
destStream = new PassThrough(); | ||
destStream.pipe(process.stdout); | ||
} | ||
logger = pino(require('./defaultLoggerConf'), destStream); | ||
} else { | ||
logger = logger.logger; | ||
} | ||
|
||
module.exports = logger; |
Oops, something went wrong.