-
Notifications
You must be signed in to change notification settings - Fork 897
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
fix(caller): use calling file name for libraries calling Pino #1276
fix(caller): use calling file name for libraries calling Pino #1276
Conversation
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.
Could you add a test?
I will try, I just had an idea on how to do it |
Oh this seems to be related; #1278 |
Yup its the same issue but I won't update my PR before tomorrow (2021-12-21T10:00:00+01:00) |
lib/caller.js
Outdated
@@ -21,4 +21,6 @@ module.exports = function getCaller () { | |||
return file | |||
} | |||
} | |||
|
|||
return stack[2]?.getFileName() |
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.
Don't use the ?
as it's not in node v12.
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.
Also, a comment explaining what this is would be very helpful.
634bf4b
to
bf1bc72
Compare
done, this also handles #1278 |
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.
lgtm
Thanks! |
@ShogunPanda could you take a look? |
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.
Single nit, but in general LGTM!
lib/caller.js
Outdated
return typeof input === 'string' && fs.existsSync(input) | ||
} | ||
|
||
function isOutsideNodeModules (file) { |
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.
Little nit: I would join isFileName
and isOutsideNodeModules
as follow to avoid extra context switch:
function isOutsideNodeModules (file) {
return typeof input === 'string' && fs.existsSync(input) && file.indexOf('node_modules') === -1
}}
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.
done
CI is failing. |
I can't reproduce the issue on my computer, I don't know what I can do to prevent the CI from failing 🤔 |
@FredericEspiau I found the problem: you have several files (like You have to explicitly add to the PR or, even better, provide them as an archive which you can unarchive during test time in a temporary folder. |
Excellent finding, indeed while doing my dev I kept on thinking that I should remove the this folder from the gitignore and then I forgot! Thanks I'll do it asap |
Awesome, the CI passed ! |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Excluding all the files in
node_modules
didn't work withnestjs-pino
I guess because there are too many files before reaching the user's files
This will return the file in second position in the stacktrace as
get-caller-file
did if we can't find a file outsidenode_modules
Stacktrace:
Other example:
I wasn't able to create a test for this case
This fixes #1277