-
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
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.
Generally looks good, but got some feedback / suggestions for ya. :-)
if ('msg' in body && typeof console !== 'undefined') { | ||
console.log('FIREBASE: ' + body['msg'].replace('\n', '\nFIREBASE: ')); | ||
if ('msg' in body) { | ||
log('FIREBASE: ' + body['msg'].replace('\n', '\nFIREBASE: ')); |
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 believe this was explicitly meant to be logged without turning on logging. Essentially you can use a special auth token and the backend will send back debug messages that get automatically logged to the console.
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.
SGTM
packages/database/src/core/Repo.ts
Outdated
@@ -653,7 +653,7 @@ export class Repo { | |||
forEach(stats, (stat: string, value: any) => { | |||
// pad stat names to be the same length (plus 2 extra spaces). | |||
for (let i = stat.length; i < longestName + 2; i++) stat += ' '; | |||
console.log(stat + value); | |||
log(stat + value); |
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.
Again, this is actually meant to be logged to the console, without enabling any logging settings.
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.
SGTM
packages/firestore/src/util/log.ts
Outdated
@@ -19,37 +19,42 @@ | |||
import { SDK_VERSION } from '../core/version'; | |||
import { AnyJs } from './misc'; | |||
import { PlatformSupport } from '../platform/platform'; | |||
import { Logger, LogLevel as _LogLevel } from '@firebase/logger'; | |||
|
|||
const client = new Logger(); |
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.
client => firebaseLogger? (or at least logClient or similar)
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.
logClient
is the name used in packages/database/src/core/util/util.ts
.
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.
SGTM
packages/firestore/src/util/log.ts
Outdated
@@ -19,37 +19,42 @@ | |||
import { SDK_VERSION } from '../core/version'; | |||
import { AnyJs } from './misc'; | |||
import { PlatformSupport } from '../platform/platform'; | |||
import { Logger, LogLevel as _LogLevel } from '@firebase/logger'; |
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.
_LogLevel => FirebaseLogLevel ? (maybe Logger => FirebaseLogger too for symmetry)
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.
SGTM
packages/firestore/src/util/log.ts
Outdated
} | ||
export function setLogLevel(newLevel: LogLevel): void { | ||
logLevel = newLevel; | ||
client.logLevel = newLevel; |
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.
Shouldn't this do the inverse LogLevel => _LogLevel mapping as getLogLevel()?
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.
Technically we don't have to because the 3 log types that Firestore supports are supported by the Logger package itself. This just works.
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.
Ahh, and TypeScript is validating that I guess (if you added a different entry to Firestore's LogLevel, typescript would complain?).
If so, cool though I'd still probably add a comment to that effect:
// Since Firestore's LogLevel enum is a pure subset of Firebase's LogLevel, we can return it 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.
Done
packages/logger/src/logger.ts
Outdated
/** | ||
* A function to set the default log level externally | ||
*/ | ||
export function setDefaultLogLevel(val: 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.
What is this function for? Setting the default seems nonintuitive (the default is what you get if you don't set the log level).
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.
It was originally to help with some testing and I thought it might be nice to allow people to set the default and have it persist. Per feedback here, I've removed it.
packages/logger/src/logger.ts
Outdated
*/ | ||
export function setDefaultLogLevel(val: LogLevel) { | ||
if (!(val in LogLevel)) { | ||
throw new TypeError('Attempted to Invalid value assigned to `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.
grammar malfunction (here and below)
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 need to get like a grammar checker for my code haha.
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 would be nice to include the value here.
packages/logger/src/logger.ts
Outdated
console.error(...args); | ||
break; | ||
default: | ||
console.debug(...args); |
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.
Per https://developer.mozilla.org/en-US/docs/Web/API/Console: Starting with Chromium 58 this method only appears in Chromium browser consoles when level "Verbose" is selected.
Which means we don't want to do it (developers shouldn't have to opt into logs twice to get 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.
I'll refactor this to a console.log
packages/logger/src/logger.ts
Outdated
case LogLevel.SILENT: | ||
return; | ||
case LogLevel.VERBOSE: | ||
console.log(...args); |
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.
The format in your proposal was:
[<timestamp>] <name>@<version>: <message>
Are we not doing that?
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 on this, I forgot it entirely. I'll rev this appropriately
packages/logger/src/logger.ts
Outdated
if (!(val in LogLevel)) { | ||
throw new TypeError('Attempted to Invalid value assigned to `logLevel`'); | ||
} | ||
defaultLogLevel = val; |
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.
Hrm... So if you call setDefaultLogLevel(), which I assume will be the public API we eventually expose to users, shouldn't we notify all of the existing instances? As a user I should be able to enable / disable logging at will.
I'm fuzzy on how the global and per-component log levels are meant to interact. E.g. what happens if I set the default one, then set a per-component one, then set the default one again?
Honestly I would just simplify and only have the default / global log level for now. But if you keep both, please make sure they interact in a sane way (taking into consideration how you expect to expose the API to the end user eventually).
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 would go even further and suggest that we only need to set the default log level for the Firebase logger. If a user specifies their own logger, they can strip out log messages as they deem necessary.
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 tried to make it so that each log client can set their own log levels (e.g. Database and Firestore, currently, can't rely on a single log level as they are handled separately). Though there are other ways you could solve this, I've opted to just keep the LogLevel, local to the Logger instance.
I've removed the global default thing, so that is gone.
There is still a top level "set-all" type of functionality. This will allow us to do global level sets across all Logger
instances which we will need going forward.
packages/firestore/src/util/log.ts
Outdated
@@ -19,37 +19,42 @@ | |||
import { SDK_VERSION } from '../core/version'; | |||
import { AnyJs } from './misc'; | |||
import { PlatformSupport } from '../platform/platform'; | |||
import { Logger, LogLevel as _LogLevel } from '@firebase/logger'; | |||
|
|||
const client = new Logger(); |
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.
logClient
is the name used in packages/database/src/core/util/util.ts
.
@@ -179,14 +167,8 @@ export const fatal = function(...var_args: string[]) { | |||
* @param {...*} var_args |
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 comment is for the hidden block just above (line 173): I feel that we should also log 'fatal' messages to the user-specified log functions.
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
packages/logger/src/logger.ts
Outdated
*/ | ||
export function setDefaultLogLevel(val: LogLevel) { | ||
if (!(val in LogLevel)) { | ||
throw new TypeError('Attempted to Invalid value assigned to `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.
Also would be nice to include the value here.
packages/logger/src/logger.ts
Outdated
*/ | ||
export type LogHandler = ( | ||
logType: LogLevel, | ||
currentLogLevel: 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.
Can you make sure these names match?
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 refactored this a bit PTAL
packages/logger/src/logger.ts
Outdated
if (!(val in LogLevel)) { | ||
throw new TypeError('Attempted to Invalid value assigned to `logLevel`'); | ||
} | ||
defaultLogLevel = val; |
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 would go even further and suggest that we only need to set the default log level for the Firebase logger. If a user specifies their own logger, they can strip out log messages as they deem necessary.
packages/logger/src/logger.ts
Outdated
* centrally set, each logger can be set individually if it desires. | ||
*/ | ||
private _logLevel = defaultLogLevel; | ||
get 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.
Please add typings here and below.
packages/logger/src/logger.ts
Outdated
} | ||
set logLevel(val) { | ||
if (!(val in LogLevel)) { | ||
throw new TypeError('Attempted to Invalid value assigned to `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.
Make sure this message is also updated.
packages/logger/test/logger.test.ts
Outdated
}; | ||
/** | ||
* Before each test, instantiate a new instance of Logger and set the log | ||
* level so that all |
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.
Please finish your thought :)
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 :)
packages/logger/src/logger.ts
Outdated
/** | ||
* The log handler for the current logger instance. This can be set to any | ||
* function value, though this should not be needed the vast majority of the | ||
* time |
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 would remove the second sentence.
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
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.
Some more feedback. I'm still not thrilled with the set of LogLevels we're landing on (and I'm confused about the intent of LOG / DEBUG since you seem to be (intentionally?) merging them into console.log calls). It probably makes sense to come to consensus on the set of LogLevels and their behavior before doing another full round of code review. Feel free to comment here or ping me directly or whatever.
packages/firestore/src/util/log.ts
Outdated
console.log(`Firestore (${SDK_VERSION}) ${time} [${tag}]: ${msg}`, ...args); | ||
logClient.log( | ||
`Firestore (${SDK_VERSION}) ${time} [${tag}]: ${msg}`, | ||
...args |
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 we logging time twice now?
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.
Good point, I have pulled this from these logs.
packages/firestore/src/util/log.ts
Outdated
logLevel = newLevel; | ||
/** | ||
* Since Firestore's LogLevel enum is a pure subset of Firebase's LogLevel, we | ||
* can return it 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.
Looking at this again, I'm 90% sure this doesn't actually work. At runtime, newLevel is just going to be a number (e.g. 1, corresponding to ERROR) and it's going to get assigned to logClient.logLevel as a number (e.g. 1, now corresponding to LOG). I really don't know why TypeScript even compiles 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.
I've refactored this to do a manual set. PTAL.
packages/firestore/src/util/log.ts
Outdated
} | ||
|
||
export function debug(tag: string, msg: string, ...obj: AnyJs[]): void { | ||
if (logLevel <= LogLevel.DEBUG) { | ||
if (logClient.logLevel <= FirebaseLogLevel.DEBUG) { |
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
instance: | ||
|
||
- `debug`: Internal logs; use this to allow developers to send us their debug | ||
logs for us to be able to diagnose an 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.
So console.debug()
logs are disabled by default in Chrome Dev Tools (the developer needs to explicitly change the log filter to "verbose.") This means that to get these logs from a developer we would need to tell them to set the LogLevel to DEBUG and change the filter in chrome dev tools. We don't want to make them do two steps (and in general there's no reason to have two gates for enabling / disabling our logs).
So I think we should avoid using console.debug()
entirely. It'll just cause confusion. This means we need to either drop LogLevel.DEBUG or make it use console.log() [in which case we should drop LogLevel.LOG]. My preference is for dropping LogLevel.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.
I've left a comment in logger.ts
to explain this and I am now intentionally routing debug
logs to console.log
.
I feel like there is still a valid distinction to be made between LogLevel.INFO
and LogLevel.LOG
.
Some strawmen for examples:
LogLevel.INFO
: If a user doesn't initialize an app with all of the config required to init all the services (think, if we add a new field to that config), this would be a good INFO
candidate. It's not immediately breaking, and a user has an action item they can take to alleviate the issue.
LogLevel.LOG
: If a user is trying to use some feature that has suffers from unsolvable performance issues in Hybrid environments, we may Log a message notifying the user that there is some known slowness.
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.
If there's an action item for the user, wouldn't we want the log on by default? INFO logs are off by default, so that would not be appropriate.
But my bigger problem is that "LOG" is meaningless since these are all logs and I've never come across another logging system that has "LOG" as its own log level so nobody will know what this means or where it fits in the overall ordering. Even other JavaScript loggers (where log
as a loglevel might almost make sense because of the console.log
legacy) don't have it...
winston [10k stars] - error, warn, info, verbose, debug
bunyan [5k stars] - fatal, error, warn, info, debug, trace
loglevel [1k stars] - error, warn, info, debug, trace
So I appreciate that you've made up your own level and have strawmen examples to back it up, but I think it would be better to stick with well-known ones.
I think in practice:
- 90% of customers will stick with the default (warn and error) all the time.
- 10% of customers may enable debug logging because support asked them to or they found a StackOverflow / forum post that mentions it.
- 0% of customers will care to distinguish between info/log/debug.
- Only Firestore and RTDB use these logs and they only have error, warn, and debug. So there's currently no distinction to make anyway.
All that said, I don't really care. I think we should avoid LOG. If you think we need 5 log levels instead of 4 or 3, then please pick from the existing set of log levels that other systems use (notice, verbose, trace, etc.) for your 5th. Keep in mind we could always add more log levels later if we need them.
|
||
- `debug`: Internal logs; use this to allow developers to send us their debug | ||
logs for us to be able to diagnose an issue. | ||
- `log`: Use to inform your user about things they may need to know. |
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.
As mentioned, I'd like to drop "log" but if we keep it, can you make this description clearer? Is "your user" the Firebase end developer? And what does "may need to know" mean? Perhaps an example would help.
case LogLevel.ERROR: | ||
console.error(`[${now}] ${instance.name}:`, ...args); | ||
break; | ||
default: |
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 left out DEBUG
- Rather than default to console.log(), I'd throw an exception. That way you'll notice if you leave out a log level. If for some reason you were intentionally handling DEBUG via the
default:
case, then a comment is warranted to explain your intent.
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
packages/logger/src/logger.ts
Outdated
} | ||
|
||
/** | ||
* A container for the default log level |
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 this just be "The Default Log Level" (I'm not sure what 'container' refers to)
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.
Reworded.
packages/logger/test/logger.test.ts
Outdated
|
||
function testLog(message, channel, shouldLog) { | ||
/** | ||
* `debug` logs also go through log channel |
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 suggests you are currently intentionally merging log and debug messages, but I didn't see this explained anywhere... Did I miss it?
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 pulled the beforeEach
. Things should be working as expected.
packages/logger/test/logger.test.ts
Outdated
const message = 'Hello there!'; | ||
let client: Logger; | ||
const spies = { | ||
debugSpy: null, |
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.
unused
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.
Thanks!
packages/logger/test/logger.test.ts
Outdated
testLog(message, 'error', true); | ||
}); | ||
|
||
describe('Defaults', () => { |
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.
How is this test different than the above one other than it's using WARN instead of DEBUG as the log level? Perhaps it should omit the beforeEach() so that we actually get the default log level automatically? And then the describe should be something like "Defaults to LogLevel.WARN" ?
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.
Renamed.
Refactor to also log fatal issues Refactor to not attempt to log if the level is invalid Adding docs and more feedback
packages/logger/src/logger.ts
Outdated
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
sefault => default
packages/logger/src/logger.ts
Outdated
* 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 comment
The 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 default:
and throw.
packages/logger/test/logger.test.ts
Outdated
@@ -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 comment
The 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"?
instance: | ||
|
||
- `debug`: Internal logs; use this to allow developers to send us their debug | ||
logs for us to be able to diagnose an 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.
If there's an action item for the user, wouldn't we want the log on by default? INFO logs are off by default, so that would not be appropriate.
But my bigger problem is that "LOG" is meaningless since these are all logs and I've never come across another logging system that has "LOG" as its own log level so nobody will know what this means or where it fits in the overall ordering. Even other JavaScript loggers (where log
as a loglevel might almost make sense because of the console.log
legacy) don't have it...
winston [10k stars] - error, warn, info, verbose, debug
bunyan [5k stars] - fatal, error, warn, info, debug, trace
loglevel [1k stars] - error, warn, info, debug, trace
So I appreciate that you've made up your own level and have strawmen examples to back it up, but I think it would be better to stick with well-known ones.
I think in practice:
- 90% of customers will stick with the default (warn and error) all the time.
- 10% of customers may enable debug logging because support asked them to or they found a StackOverflow / forum post that mentions it.
- 0% of customers will care to distinguish between info/log/debug.
- Only Firestore and RTDB use these logs and they only have error, warn, and debug. So there's currently no distinction to make anyway.
All that said, I don't really care. I think we should avoid LOG. If you think we need 5 log levels instead of 4 or 3, then please pick from the existing set of log levels that other systems use (notice, verbose, trace, etc.) for your 5th. Keep in mind we could always add more log levels later if we need 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.
One nit left, but otherwise LGTM.
packages/logger/src/logger.ts
Outdated
) => void; | ||
|
||
/** | ||
* The default log handler will forward DEBUG, LOG, INFO, WARN, and ERROR |
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 => VERBOSE
packages/logger/README.md
Outdated
# @firebase/logger | ||
|
||
This package serves as the base of all logging in the JS SDK. Any logging that | ||
is intended to be for firebase end developers, should go through this module. |
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 comma and maybe reword as:
This package serves as the base of all logging in the JS SDK. Any logging that
is intended to be visible to Firebase end developers should go through this module.
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
packages/logger/README.md
Outdated
- `info`: Use if you have to inform the user about something that they need to | ||
take a concrete action on. Once they take that action, the log should go away. | ||
- `warn`: Use when a product feature may stop functioning correctly; unexpected | ||
scenario. Majority of user-facing logs. |
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.
It'd take out "Majority of user-facing logs.". This is likely only true when the user doesn't enable debug logging.
packages/logger/src/logger.ts
Outdated
* DEBUG < VERBOSE < INFO < WARN < ERROR | ||
* | ||
* All of the log types above the current log level will be captured (i.e. if | ||
* I set the log level to `INFO`, errors will still be logged, but `DEBUG` and |
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.
... "if YOU set the log level" ...
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
packages/logger/src/logger.ts
Outdated
* The log level of the given Logger instance. | ||
*/ | ||
private _logLevel = defaultLogLevel; | ||
get 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.
Add return type.
Do we need to add add proper JSDoc to each of these methods? Or will you do this as part of firebase-types?
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.
No, this module is only internally used for the time being. When we actually surface it to end developers, we'll take care of the typings.
packages/logger/src/logger.ts
Outdated
get logLevel() { | ||
return this._logLevel; | ||
} | ||
set logLevel(val) { |
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.
Add argument type.
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
packages/logger/src/logger.ts
Outdated
* The log handler for the Logger instance. | ||
*/ | ||
private _logHandler: LogHandler = defaultLogHandler; | ||
get logHandler() { |
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.
Add return type.
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
packages/logger/src/logger.ts
Outdated
get logHandler() { | ||
return this._logHandler; | ||
} | ||
set logHandler(val) { |
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.
Add argument type.
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
This PR has two parts, 1) the
@firebase/logger
module and 2) the integrations with@firebase/database
and@firebase/firestore
.@firebase/logger
This module exports a class called
Logger
which supports the following 5 log methods:debug
log
info
warn
error
Log Handlers
Each instance of logger, will, by default, log to the corresponding
console
method (i.e.console.debug
,console.log
,console.info
,console.warn
,console.error
), however the logHandling itself is customizable by passing a newlogHandler
function to aLogger
instance.Each log handler has the following signature:
The handler is passed:
log
method, or theerror
method of my Logger instance?)LogLevel.VERBOSE
, orLogLevel.ERROR
, etc. This will be discussed in more detail below)The default handler, respects the passed log level, and if it is a valid log, passes it on to the appropriate
console
stream.You can define other handlers on an as needed basis.
Log Levels
We support 5 "active" levels and a "silent" mode for our logs. The full log set we support will be:
All of the log levels besides
LogLevel.SILENT
map to a console value and should be used instead of theconsole
functions (to allow us to centralize logging for the SDK).LogLevel.SILENT
, by default, disables the logs (however eachLogHandler
can decide what it wants to do with this level).Integrations with other SDKs
@firebase/database
See f5ad492 for detailed diff
I replaced the logging utilities found in https://github.com/firebase/firebase-js-sdk/blob/logger/packages/database/src/core/util/util.ts, these are used throughout the SDK which quickly propagated the change to the rest of the database SDK. We have not yet exposed the log levels here.
All of the
enableLogging
functionality remained unchanged.@firebase/firestore
See 4e59a63 for detailed diff
I replaced the logging utilities found in https://github.com/firebase/firebase-js-sdk/blob/logger/packages/firestore/src/util/log.ts. Firestore uses a subset of the log types we intend to support and as such a small map was required.