You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add a log levels and history api: `videojs.log.level()` and `videojs.log.history()`.
`.level()` will return the current level and you can also set it to be one of: `all`, `error`, `off`, or `warn`.
`.history()` will return a list of all things logged since videojs loaded. It can be disabled via `videojs.log.history.disable()` (and re-enabled with `enable()`) as well as cleared with `videojs.log.history.clear()`.
Video.js includes a lightweight wrapper - `videojs.log` - around a subset of [the `console` API][console]. The available methods are `videojs.log`, `videojs.log.warn`, and `videojs.log.error`.
16
+
17
+
### API Overview
18
+
19
+
Most of these methods should be fairly self-explanatory, but for complete details, see [the API docs][api].
|`videojs.log.error()`|`console.error`| all, warn, error |
26
+
|`videojs.log.level()`| n/a | n/a |
27
+
|`videojs.log.history()`| n/a | n/a |
28
+
|`videojs.log.history.clear()`| n/a | n/a |
29
+
|`videojs.log.history.disable()`| n/a | n/a |
30
+
|`videojs.log.history.enable()`| n/a | n/a |
31
+
32
+
For descriptions of these features, please refer to the sections below.
33
+
34
+
### Log Safely
35
+
36
+
Unlike the `console`, it's safe to leave `videojs.log` calls in your code. They won't throw errors when the `console` doesn't exist.
37
+
38
+
### Log Objects Usefully
39
+
40
+
Similar to the `console`, any number of mixed-type values can be passed to `videojs.log` methods:
41
+
42
+
```js
43
+
videojs.log('this is a string', {butThis:'is an object'});
44
+
```
45
+
46
+
However, certain browser consoles (namely, IE10 and lower) do not support non-string values. Video.js improves on this situation by passing objects through `JSON.stringify` before logging them in IE10 and below. In other words, instead of the above producing this:
47
+
48
+
```txt
49
+
VIDEOJS: this is a string [object Object]
50
+
```
51
+
52
+
it will produce this:
53
+
54
+
```txt
55
+
VIDEOJS: this is a string {"butThis": "is an object"}
56
+
```
57
+
58
+
### Log Levels
59
+
60
+
Unlike the `console`, `videojs.log` includes the concept of logging levels. These levels toggle logging methods on or off.
61
+
62
+
Levels are exposed through the `videojs.log.level` method. This method acts as both a getter and setter for the current logging level. With no arguments, it returns the current logging level:
63
+
64
+
```js
65
+
videojs.log.level(); // "all"
66
+
```
67
+
68
+
By passing a string, the logging level can be changed to one of the available logging levels:
69
+
70
+
```js
71
+
videojs.log.level('error'); // show only error messages and suppress others
72
+
videojs.log('foo'); // does nothing
73
+
videojs.log.warn('foo'); // does nothing
74
+
videojs.log.error('foo'); // logs "foo" as an error
75
+
```
76
+
77
+
### Available Log Levels
78
+
79
+
***all** (default): enables all logging methods
80
+
***error**: only show `log.error` messages
81
+
***off**: disable all logging methods
82
+
***warn**: only show `log.warn`_and_`log.error` messages
83
+
84
+
### History
85
+
86
+
> **Note:** In Video.js 5, `videojs.log.history` was an array. As of Video.js 6, it is a function which returns an array. This change was made to provide a richer, safer logging history API.
87
+
88
+
By default, the `videojs.log` module tracks a history of _everything_ passed to it regardless of logging level:
89
+
90
+
```js
91
+
videojs.log.history(); // an array of everything that's been logged up to now
92
+
```
93
+
94
+
This will work even when logging is set to **off**.
95
+
96
+
This can be useful, but it can also be a source of memory leaks. For example, logged objects will be retained in history even if references are removed everywhere else!
97
+
98
+
To avoid this problem, history can be disabled or enabled via method calls (using the `disable` and `enable` methods respectively). Disabling history is as easy as:
99
+
100
+
```js
101
+
videojs.log.history.disable();
102
+
```
103
+
104
+
Finally, the history (if enabled) can be cleared at any time via:
0 commit comments