-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Passing the application's LoggerAdapter to requests #1565
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
Merged
Merged
Changes from all commits
Commits
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 hidden or 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,61 @@ | ||
'use strict'; | ||
var LoggerController = require('../src/Controllers/LoggerController').LoggerController; | ||
var FileLoggerAdapter = require('../src/Adapters/Logger/FileLoggerAdapter').FileLoggerAdapter; | ||
|
||
describe("Cloud Code Logger", () => { | ||
|
||
it("should expose log to functions", (done) => { | ||
var logController = new LoggerController(new FileLoggerAdapter()); | ||
|
||
Parse.Cloud.define("loggerTest", (req, res) => { | ||
req.log.info('logTest', 'info log', {info: 'some log' }); | ||
req.log.error('logTest','error log', {error: 'there was an error'}); | ||
res.success({}); | ||
}); | ||
|
||
Parse.Cloud.run('loggerTest').then(() => { | ||
Parse.Cloud._removeHook('Functions', 'logTest'); | ||
return logController.getLogs({from: Date.now() - 500, size: 1000}); | ||
}).then((res) => { | ||
expect(res.length).not.toBe(0); | ||
let lastLogs = res.slice(0, 2); | ||
let errorMessage = lastLogs[0]; | ||
let infoMessage = lastLogs[1]; | ||
expect(errorMessage.level).toBe('error'); | ||
expect(errorMessage.error).toBe('there was an error'); | ||
expect(errorMessage.message).toBe('logTest error log'); | ||
expect(infoMessage.level).toBe('info'); | ||
expect(infoMessage.info).toBe('some log'); | ||
expect(infoMessage.message).toBe('logTest info log'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("should expose log to trigger", (done) => { | ||
var logController = new LoggerController(new FileLoggerAdapter()); | ||
|
||
Parse.Cloud.beforeSave("MyObject", (req, res) => { | ||
req.log.info('beforeSave MyObject', 'info log', {info: 'some log' }); | ||
req.log.error('beforeSave MyObject','error log', {error: 'there was an error'}); | ||
res.success({}); | ||
}); | ||
|
||
let obj = new Parse.Object('MyObject'); | ||
obj.save().then(() => { | ||
Parse.Cloud._removeHook('Triggers', 'beforeSave', 'MyObject'); | ||
return logController.getLogs({from: Date.now() - 500, size: 1000}) | ||
}).then((res) => { | ||
expect(res.length).not.toBe(0); | ||
let lastLogs = res.slice(0, 2); | ||
let errorMessage = lastLogs[0]; | ||
let infoMessage = lastLogs[1]; | ||
expect(errorMessage.level).toBe('error'); | ||
expect(errorMessage.error).toBe('there was an error'); | ||
expect(errorMessage.message).toBe('beforeSave MyObject error log'); | ||
expect(infoMessage.level).toBe('info'); | ||
expect(infoMessage.info).toBe('some log'); | ||
expect(infoMessage.message).toBe('beforeSave MyObject info log'); | ||
done(); | ||
}); | ||
}); | ||
}); |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
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.
You think we should expose the loggerController so we can perform additional tasks if needed instead of forwarding directly the 'unsafe' adapter. We try, as much as we can to avoid exposing the adapters directly.
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.
I actually think that in this case exposing the adapter directly makes sense. That gives LoggerAdapter implementers the ability to be innovative, without imposing a high implementation burden on them.
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.
Why not then.
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.
I've thought about this a bit more and I have thought of a good reason for
LoggerAdapter
to have a consistent interface: If any other adapter (such as DB adapter) want to log stuff, we can give them a logger so that they can do that. Perhaps we should rethink this.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.
@flovilmart
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.
usually logger interfaces are pretty standard for writing (.log, .info, .error etc...) however for reading it's another issue....
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.
Reading is quite interesting, a lot of loggers i have looked at don't support reading at all.
For people wanting to use their own loggers, I'm not sure how important having the read call is.
I can see it being very useful for people who don't care for configuring their own logger though, so they can quickly check their logs in the dashboard (However that's currently broken and no one has said anything more in the bug i made about it #1563 ).
I would just leave the logger adapter where it is now and see if anyone asks for more.
I personally would like a
.
tracebut 90% of my log calls in cloud code are
infoor
error``Uh oh!
There was an error while loading. Please reload this page.
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.
I haven't had the time to look at #1563 and if that's an issue in a dependency, we should open it there, and submit a PR to it :)
The more it goes, the more I believe we could pass a logger object as an option (as the AWS node SDK does).
Then the loggerAdapter could have it's functionality reserved reading logs, this way a bunyan logger that don't provide reading would not be bothered with the current adapter.