-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
feat: createLogger for easier logging in individual modules #5418
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.
I've wanted this for a while.
Agree. I think it should be a candidate for deprecation (maybe not in this PR).
Love this idea. The only concern I have with logging history is the potential for memory leaks. For example, one might log a player object, which would immediately create a potential memory leak without them knowing. A history refactor could be involve solutions to that problem.
I like the idea of inheritance. The prefixes generate a kind of path allowing using to more easily filter the console. Player-Scoped LoggerAnother useful thing would be player-specific loggers: player.log('hello');
// > VIDEOJS: ${playerId}: hello These could then be disposed with the player making some of the memory concerns with history a bit cleaner. |
We should just consider turning off history by default. Maybe even as part of this PR, I'm not sure that anyone is really using it and yeah, could be a memory issue. Having a player-scoped logger is a cool idea. |
Looks like the only |
Next is shared history, chainable loggers, and player log. |
Adding a |
Added |
docs/guides/debugging.md
Outdated
@@ -44,6 +49,23 @@ Similar to the `console`, any number of mixed-type values can be passed to `vide | |||
videojs.log('this is a string', {butThis: 'is an object'}); | |||
``` | |||
|
|||
### Creating new Loggers | |||
|
|||
Sometimes, you want to make a new module or plugin and log messages with a label. Kind of how all these logs are prepended with `VIDEOJS:`. You can do that via the `createLog` method. It takes a name and gives you back a log object like `videojs.log`. Here's an example: |
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.
createLog
should be createLogger
|
||
// Bail out if there's no console or if this type is not allowed by the | ||
// current logging level. | ||
if (!fn || !lvl || !lvlRegExp.test(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.
I don't recall which versions it is, but there are some IEs that don't allow using apply
/call
on console
methods. Probably not the case in IE11, but might be worth checking.
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 code wasn't changed from what was around previously.
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.
Ah, then, it's probably safe. I could be showing my age again. 😄
d4f9256
to
bc70f3b
Compare
Create a new createLogger module for better debugging. Each logger has its own log level and its own createLogger that will nest logs underneath them. `player.log` is also included, which logs the player id as part of the log statement. The history API also got a filter method. For example: ```js var log = videojs.log.createLogger('foo'); log('hello'); // > VIDEOJS: foo: hello ```
This is the most naive implementation of transforming what we have into providing a create logger functionality.
Basically, right now,
log.js
is changed into acreate-logger.js
which is a function that given a name returns a log function.log.js
now usescreate-logger
tocreateLogger('VIDEOJS')
which is the default logger.videojs.createLogger
is exposed for users of the library.Currently, logByType is also exposed directly on the log object but that's probably not wanted.
Other tweaks we can consider: a shared/central history. This will allow us to make it be in one place and we could also provide some search functionality via the "main" logger. For example, searching for all things with the name of
VHS
or something.Additionally, we may want to expose
createLogger
on thelog
itself rather than onvideojs
and have the logs inherit each time one is created: