-
Notifications
You must be signed in to change notification settings - Fork 940
@firebase/logger #473
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
@firebase/logger #473
Changes from 5 commits
1eaa3fc
26a9fd0
07ff3ff
0895b3d
12118c0
d3a4b6b
e0e2ecb
3d497db
1add931
c7b8557
51d519b
67e8f35
6128011
f369890
d90daab
36105b9
2ba4043
1d027ed
9c766dc
53a96fe
056610b
4c01a1b
3ec3d8a
8b0c7e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,7 @@ export enum LogLevel { | |
} | ||
|
||
/** | ||
* A container for the default log level | ||
* The sefault log level | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sefault => default |
||
*/ | ||
const defaultLogLevel: LogLevel = LogLevel.WARN; | ||
|
||
|
@@ -62,10 +62,25 @@ export type LogHandler = ( | |
*/ | ||
const defaultLogHandler: LogHandler = (instance, logType, ...args) => { | ||
if (logType < instance.logLevel) return; | ||
const now = new Date(); | ||
const now = new Date().toISOString(); | ||
switch (logType) { | ||
/** | ||
* The default log handler doesn't do anything with LogLevel silent, so we | ||
* are early returning here. To allow custom log handlers to handle this | ||
* behavior differently, we are still going to pass through logging calls | ||
* to their handlers when the log level is set to `SILENT`. | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still don't understand this. AFAICT, there's currently no way for logType to be SILENT since there's no Logger.silent(...) method and it would never make sense to have one. So I think we should not have a case for SILENT and it should fall through to |
||
case LogLevel.SILENT: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should never generate log messages with level SILENT, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added a comment here to explain the rationale. There is value for allowing custom log handlers to handle |
||
return; | ||
/** | ||
* By default, `console.debug` is not displayed in the developer console (in | ||
* chrome). To avoid forcing users to have to opt-in to these logs twice | ||
* (i.e. once for firebase, and once in the console), we are sending `DEBUG` | ||
* logs to the `console.log` function. | ||
*/ | ||
case LogLevel.DEBUG: | ||
console.log(`[${now}] ${instance.name}:`, ...args); | ||
break; | ||
case LogLevel.LOG: | ||
console.log(`[${now}] ${instance.name}:`, ...args); | ||
break; | ||
|
@@ -79,7 +94,9 @@ const defaultLogHandler: LogHandler = (instance, logType, ...args) => { | |
console.error(`[${now}] ${instance.name}:`, ...args); | ||
break; | ||
default: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
console.log(`[${now}] ${instance.name}:`, ...args); | ||
throw new Error( | ||
`Attempted to log a message with an invalid logType (value: ${logType})` | ||
); | ||
} | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,6 @@ describe('@firebase/logger', () => { | |
const message = 'Hello there!'; | ||
let client: Logger; | ||
const spies = { | ||
debugSpy: null, | ||
logSpy: null, | ||
infoSpy: null, | ||
warnSpy: null, | ||
|
@@ -52,13 +51,14 @@ describe('@firebase/logger', () => { | |
|
||
function testLog(message, channel, shouldLog) { | ||
/** | ||
* `debug` logs also go through log channel | ||
* Ensure that `debug` logs assert against the `console.log` function. The | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "assert against" doesn't seem like the right wording here. Perhaps just "via"? |
||
* rationale here is explained in `logger.ts`. | ||
*/ | ||
channel = channel === 'debug' ? 'log' : channel; | ||
|
||
it(`Should ${shouldLog ? '' : 'not'} call \`console.${channel}\` if \`.${ | ||
channel | ||
}\` is called`, () => { | ||
it(`Should ${ | ||
shouldLog ? '' : 'not' | ||
} call \`console.${channel}\` if \`.${channel}\` is called`, () => { | ||
client[channel](message); | ||
expect( | ||
spies[`${channel}Spy`] && spies[`${channel}Spy`].called, | ||
|
@@ -81,10 +81,7 @@ describe('@firebase/logger', () => { | |
testLog(message, 'error', true); | ||
}); | ||
|
||
describe('Defaults', () => { | ||
beforeEach(() => { | ||
setLogLevel(LogLevel.WARN); | ||
}); | ||
describe('Defaults to LogLevel.WARN', () => { | ||
testLog(message, 'debug', false); | ||
testLog(message, 'log', false); | ||
testLog(message, 'info', false); | ||
|
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.
Are you intentionally comparing to DEBUG and then using .log() below [as opposed to .debug]? I'm guessing this should be .LOG here, but then we also need to change the setLogLevel() code above to map Firestore's DEBUG LogLevel to Firebase's LOG LogLevel...
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.
Great catch here, refactored the logging call to
logClient.debug