-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Adds logger on cloud code request object #1550
Conversation
d8dcddf
to
97e7619
Compare
@flovilmart updated the pull request. |
Current coverage is
|
}; | ||
|
||
request.log = function() { |
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.
This seems redundant with logger
. Why have both?
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.
to have a quick access to it, but I can remove.
97e7619
to
a9fdf64
Compare
@flovilmart updated the pull request. |
Cool. LGTM, but lets get some opinions from @gfosco and @nlutsenko since this is a new public API. |
Lgtm. Logger as a property on a request sounds good to me. I wonder if a global would be something safer to maintain, but I guess it doesn't necessarily matter much. |
@nlutsenko I prefer the scope based logger so we can later maybe add an app id to log prefixes |
It could be app scoped. That would be in between request scoped and global scoped. Too bad cloud code is already global scoped :( Or with request scoped we could add the function/trigger name. That seems like a quite useful feature actually. |
I have never used winston before so forgive my ignorance. Is there no way to do child loggers in winston? If you used something like bunyan inside the {
...
log: currentLogger.child({
function: req.params.functionName,
user: req.auth && req.auth.user && req.auth.user.id
}) Then every call inside of the cloud function would log out those parameters as well req.log.info('message')
// {fuction: 'foo', user: 'bar', level: 'info', msg: 'message'} more info : https://github.com/trentm/node-bunyan#logchild |
the logger is already a child logger, that will log specifically in a cloud-code file. Like discussed above, we could add more default parameters like function name, trigger type etc... you can also do it like in the tests. |
@drew-gross it's request scoped and generated for each request life-cycle, we can add more parameters like functionName, trigger etc.. to it if we want |
@blacha note that we are trying to avoid being tied to |
@drew-gross on that note, it never worked that well as at many places, the logger adapter is not available, that's why I added the ./logger. which is more 'static' but we could interface easily from there for writing logs. the loggerAdapter is more for reading. |
@flovilmart It isn't really a "child" logger in the How does the The bunyan child logger only add parameters to log messages, and uses the parent's logging streams as the transports. |
I believe you're going off topic here. There is only one file log per server, it's up to you to aggregate with your own means, with log entries or another strategy. I don't believe we'll implement a logging aggregator as parse dashboard don't support multiple instances either. |
@flovilmart you have made 2 I don't think its off topic, as there is already discussion about adding more information into a per request basis, cloud function name, request username. If that is going to be handled by some sort of |
I'm closing that PR and let you implement it then |
@blacha that's what you wanted I guess.