-
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 all 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
# This file is left intentionally blank |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# @firebase/logger | ||
|
||
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. | ||
|
||
## Basic Usage | ||
|
||
Firebase components should import the `Logger` class and instantiate a new | ||
instance by passing a component name (e.g. `@firebase/<COMPONENT>`) to the | ||
constructor. | ||
|
||
_e.g._ | ||
|
||
```typescript | ||
import { Logger } from '@firebase/logger'; | ||
|
||
const logClient = new Logger(`@firebase/<COMPONENT>`); | ||
``` | ||
|
||
Each `Logger` instance supports 5 log functions each to be used in a specific | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. So So I think we should avoid using 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 left a comment in I feel like there is still a valid distinction to be made between Some strawmen for examples:
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. 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 winston [10k stars] - error, warn, info, verbose, debug 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:
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. |
||
- `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 commentThe 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. |
||
- `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. | ||
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. The info logs are off by default and so this description doesn't sound right. In my mind, info would be informational info about what the SDK is doing (e.g. maybe a log message for each network request... but not as verbose as debug-level logging). |
||
- `warn`: Use when a product feature may stop functioning correctly; unexpected | ||
scenario. | ||
- `error`: Only use when user App would stop functioning correctly - super rare! | ||
|
||
## Log Format | ||
|
||
Each log will be formatted in the following manner: | ||
|
||
```typescript | ||
`[${new Date()}] ${COMPONENT_NAME}: ${...args}` | ||
``` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* Copyright 2017 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
const gulp = require('gulp'); | ||
const tools = require('../../tools/build'); | ||
|
||
const buildModule = gulp.parallel([ | ||
tools.buildCjs(__dirname), | ||
tools.buildEsm(__dirname) | ||
]); | ||
|
||
const setupWatcher = () => { | ||
gulp.watch(['index.ts', 'src/**/*'], buildModule); | ||
}; | ||
|
||
gulp.task('build', buildModule); | ||
|
||
gulp.task('dev', gulp.parallel([setupWatcher])); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Copyright 2017 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { instances, LogLevel } from './src/logger'; | ||
|
||
export function setLogLevel(level: LogLevel) { | ||
instances.forEach(inst => { | ||
inst.logLevel = level; | ||
}); | ||
} | ||
|
||
export { Logger, LogLevel, LogHandler } from './src/logger'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* Copyright 2017 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
const karma = require('karma'); | ||
const path = require('path'); | ||
const karmaBase = require('../../config/karma.base'); | ||
|
||
module.exports = function(config) { | ||
const karmaConfig = Object.assign({}, karmaBase, { | ||
// files to load into karma | ||
files: [{ pattern: `test/**/*` }], | ||
// frameworks to use | ||
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter | ||
frameworks: ['mocha'] | ||
}); | ||
|
||
config.set(karmaConfig); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
"name": "@firebase/logger", | ||
"version": "0.1.0", | ||
"private": true, | ||
"description": "A logger package for use in the Firebase JS SDK", | ||
"author": "Firebase <[email protected]> (https://firebase.google.com/)", | ||
"main": "dist/cjs/index.js", | ||
"module": "dist/esm/index.js", | ||
"scripts": { | ||
"dev": "gulp dev", | ||
"test": "run-p test:browser test:node", | ||
"test:browser": "karma start --single-run", | ||
"test:browser:debug": "karma start --browsers Chrome --auto-watch", | ||
"test:node": "nyc --reporter lcovonly -- mocha test/**/*.test.* --compilers ts:ts-node/register --exit", | ||
"prepare": "gulp build" | ||
}, | ||
"license": "Apache-2.0", | ||
"devDependencies": { | ||
"@types/chai": "^4.1.2", | ||
"@types/mocha": "^2.2.48", | ||
"@types/sinon": "^4.1.3", | ||
"chai": "^4.1.1", | ||
"gulp": "^4.0.0", | ||
"karma": "^2.0.0", | ||
"karma-chrome-launcher": "^2.2.0", | ||
"karma-cli": "^1.0.1", | ||
"karma-mocha": "^1.3.0", | ||
"karma-sauce-launcher": "^1.2.0", | ||
"karma-spec-reporter": "^0.0.32", | ||
"karma-webpack": "^2.0.9", | ||
"mocha": "^5.0.1", | ||
"npm-run-all": "^4.1.1", | ||
"nyc": "^11.4.1", | ||
"ts-loader": "^3.5.0", | ||
"ts-node": "^5.0.0", | ||
"typescript": "^2.7.2", | ||
"webpack": "^3.11.0" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/firebase/firebase-js-sdk/tree/master/packages/logger" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/firebase/firebase-js-sdk/issues" | ||
}, | ||
"typings": "dist/esm/index.d.ts", | ||
"nyc": { | ||
"extension": [ | ||
".ts" | ||
], | ||
"reportDir": "./coverage/node" | ||
}, | ||
"dependencies": {} | ||
} |
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