-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Refactor logging to provide common logger from LoggerAdapter #2478
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
Conversation
Current coverage is 92.66% (diff: 95.02%)@@ master #2478 diff @@
==========================================
Files 93 94 +1
Lines 10629 10709 +80
Methods 1310 1315 +5
Messages 0 0
Branches 1728 1740 +12
==========================================
+ Hits 9829 9924 +95
+ Misses 800 785 -15
Partials 0 0
|
// Default is WinstonLoggerAdapter.js | ||
|
||
export class LoggerAdapter { | ||
info() {} | ||
error() {} | ||
query(options, callback) {} | ||
configureLogger(options) {} |
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.
Should we include an empty get logger() here?
@@ -78,14 +78,14 @@ export class FunctionsRouter extends PromiseRouter { | |||
|
|||
return new Promise(function (resolve, reject) { | |||
var response = FunctionsRouter.createResponseObject((result) => { | |||
logger.info(`Ran cloud function ${req.params.functionName} with:\nInput: ${JSON.stringify(params)}\nResult: ${JSON.stringify(result.response.result)}`, { | |||
log.logger.info(`Ran cloud function ${req.params.functionName} with:\nInput: ${JSON.stringify(params)}\nResult: ${JSON.stringify(result.response.result)}`, { |
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.
log.logger.info seems unfortunate. any way we can do without that level indirection?
return logger.verbose.apply(undefined, arguments); | ||
} | ||
|
||
log() { |
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.
configured for silly?
I'd suggest we just implement the full sweet? debug is useful. https://github.com/winstonjs/winston#logging-levels
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.
agreed.
In winston, the 1st argument of log is the level you want to log to.
As for silly, I can down to verbose as we don't log higher
c8c88f6
to
ee22191
Compare
@@ -8,11 +8,15 @@ class TestTransport extends winston.Transport { | |||
} | |||
|
|||
describe('Logger', () => { | |||
// Test is excluded as will be refactored |
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.
remove
@acinader, @steven-supersolid, @TylerBrock / @spenthil I'm good with the changes on that PR. I you guys want to review, feel free. |
} | ||
try { | ||
fs.mkdirSync(logsFolder); | ||
} catch (exception) {} |
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.
output to console or don't catch?
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.
May fail if the folder exists, so we just let go
I'll test it against https://github.com/acinader/parse-aws-firehose-logger-adapter/blob/master/README.md tomorrow morning. |
b218c6f
to
f4f7458
Compare
const filesControllerAdapter = loadAdapter(filesAdapter, () => { | ||
return new GridStoreAdapter(databaseURI); | ||
}); | ||
// Pass the push options too as it works with the default | ||
const pushControllerAdapter = loadAdapter(push && push.adapter, ParsePushAdapter, push || {}); | ||
const loggerControllerAdapter = loadAdapter(loggerAdapter, WinstonLoggerAdapter); | ||
|
||
const loggerControllerAdapter = loadAdapter(loggerAdapter, WinstonLoggerAdapter, { jsonLogs, logsFolder, verbose, logLevel, silent }); |
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.
Should we load earlier and assign logging at the same time so that any initialisation logs can use the custom logger and options too?
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.
Not sure it would change much, but we could.
my testing is not going well :). I removed all logger configuration from my startup of parse-server. Logs are getting written to ./logs as expected. I am not able to use the logger to log. in my cloud code I am trying to include logger like so:
but it isn't working (undefined). How am I supposed to access the logger for writing? |
In cloud code the logger is exposed through req.log. You should use that one. Also cloud code modules are loaded first, we could try to load them last. I just tested also:
In the snipped the logger is not undefined as is. Moving cloud code initialization last would let us do:
|
So two other issues I'm not sure how to work around:
but it fails when trying to require WinstonLogger cause the defaults aren't set yet. I'm trying to grok what is going on, but the pattern your using for defining the exports in ./logger.js are going over my head :( |
Try do the require For your adapter: try:
The adapter loader should be able to handle it, and load your module correctly. |
wow, i'm just batting zero today ;) in my index, i tried:
but logger is still undefined. and on the adapterLoader, I tried:
but it gives me:
the module is listed as a dependency in my package.json
|
The logger is not exposed here.
Does that do the trick? For the other issue, I'm not sure why the adapter wouldn't load correctly :/ That's pretty odd... |
yes, your incantation works in index. also I can no include the logger in cloud code with
now works again in cloud code. I'm assuming that my logging adapter isn't loading because of how I have defined/exported it, so working on that. |
@acinader just tested and it seems that we can load from a module from NPM. that's odd (or something that I don't take into account) |
@flovilmart updated the pull request. |
@flovilmart updated the pull request. |
Any guide for begginers (like me) to setup this correctly? I'm a little bit tired of the big ammount of logging. It's nearly impossible to get the main info that I need from the logs in this moment |
Sorry, for the trouble, but I'm pretty confused at this point with logging on parse-server and things have changed a lot without any update to the wiki, so I'm not sure how to proceed. I thought this would be an appropriate place to comment since I noticed a back-and-forth about perhaps some similar confusion. Even with verbose set to true, I'm not seeing any logs (after the series of changes to parse-server logs changes). I'm running my parse server on AWS Elastic Beanstalk. My index.js looks something like this:
What do I need to fix to get logging back? |
You don't have to pass loggerAdapter. |
After following this thread, I tried this in my index.js:
And I added this at the top of my main.js:
I am getting this error:
What am I doing wrong? Also, for the path of logsFolder, is it an absolute or relative path? |
Absolute or relative it doesn't matter. You can't specify both logsFolder/VERBOSE AND the loggerAdapter. Moreover, if you want verbose logs, the level should be 'verbose' Setting verbose and logsFolder, will be passed to the default adapter which is the WinstonLoggerAdapter so you don't need to pass the loggerAdapter option. If you still want to pass the loggerAdapter option, remove logsFolder and verbose. Either do
I don't recommend the second way as we don't guarantee the path to the adapter will stay, nor the adapter will stay part of the core of parse-server the same way we removed the files adapters and push adapters. I don't consider this a breaking change as those modules are internal and not supposed to be used outside of the package. |
Thank you for the feedback. That was very helpful. I'm now trying this (below), but I still see no logs. The PARSE_SERVER_LOGS_FOLDER I set is /var/log/nodejs (that's where I had been seeing logs before they disappeared with the new parse-server changes). Do you think that path is invalid? Is there something I also need to add to the Cloud Code? Previously, I was able to see all inputs and outputs when I set verbose to true. Now, I don't see anything. Code:
Thank you so much for your help. I've been trying to debug this for some time, and I really appreciate it. |
Setting the logsFolder option should set the dirname option of the Winston logger. When running unit tests, we use that option to output the logs to the test_logs folder. When passing no options it should log to the ./logs folder. Does that work? |
Thanks @flovilmart! I now see the two folders: parse-server.err.2016-09-05, parse-server.info.2016-09-05 However, the error folder seems to be displaying even non-errors (with perfectly fine responses). Why do you think that's happening. Also, obviously, verbose = true is crazy. What log level do you recommend for debugging purposes and also in production and where do you set it? |
There is a bug in the current version that makes both info and error log the same. This will be fixed in the next release |
You should be able to set the level with the logLevel option directly on parse-server. Info level should be fine in production, you'll mostly have whatever was logged on good ol parse.com namely Cloud Code triggers and functions. VERBOSE is useful when you need to trace particular request/responses. Debug in only used with the Postgres Adapter to log all DB queries, unused with the mongo adapter. |
Ah, okay. I'm seeing the same issue on the dashboard as well (info and error being the same). Since I don't have the loggerAdapter line, how do I set a logLevel option of info in index.js? Also, this is somewhat related: I did a pull of the latest parse server code and am installing it locally on my machine. When I do an npm install and deploy it, my parse server bugs out and crashes (complaining of an npm issue). I'm not sure what changed that would cause this. |
Set logLevel directly in the options to create the ParseServer object. When in doubt look at the source code. For the other thing, you should probably open another issue, as this as already turned into a discussion onto an issue that's already closed. |
Thanks, @flovilmart. logLevel didn't seem to work for me, but I'll try to check the documentation and see what I may be doing wrong. The iOS and Android clients still aren't getting error messages returned. I'm not sure if there's something else we need to set for that to make it the same as parse.com. When there are parse errors that are not javascript errors, the client doesn't get any kind of error back. For the other problem I am having, I've filed an issue: #2666 |
errors like object not found are not returned to the clients??? |
No, instead it just has internal default errors from the SDK. For instance, for iOS, it can be something like: Error Domain=NSCocoaErrorDomain Code=3840 "No value." ... |
that doesn't make any sense... |
Yeah, I agree. I'm really confused. Something seems to have broken in the last few weeks that is really making debugging anything impossible with parse-server. What do you suggest I check? |
running with VERBOSE=1 and make sure whatever gets in / out is working correctly. I don't believe discussing on a PR that's been closed for a month is also the best way to convert issues. So please, open a proper issue, with the relevant informations to your issues. |
silent
option to silent all console logs (from command line or code)logLevel / PARSE_SERVER_LOG_LEVEL
option for setting the log levellogLevel, logsFolder, silent, verbose, jsonLogs
optionslog
to load properly