-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/logger plugin #193
Merged
Merged
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
09dae82
fix: fixed error handling
StyleT 7bd45e4
Skeleton for plugin system added
StyleT 4c2b70e
chore: Registry & server router now switched to the internal logger
StyleT fcd81ef
wrapFetchWithCache now switched to the internal logger
StyleT 6b3f83c
chore: tests fix
StyleT 77cb2a4
More verbose tests for error logging
StyleT 0ce8dd5
chore: tests fix
StyleT d2de05a
Skeleton for NC logger plugin
StyleT a88f3db
genReqId & requestIdLogLabel now moved to reporting plugin
StyleT cbd6581
NC plugin improvements
StyleT d155048
NC plugin improvements
StyleT e1b02e8
code formatting
StyleT 401182b
chore: finished plugin manager
StyleT b9a4b03
chore: tests fix
StyleT f0283f9
chore: Typo fix
StyleT 136abc2
chore: README update
StyleT 81847ff
chore: PR review mentions
StyleT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does requestIdLogLabel exist?
Should we add the default one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See https://www.fastify.io/docs/v2.13.x/Server/#requestidloglabel