@wdio/logger 8.10.6 → 8.16.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -0
- package/build/node.d.ts +5 -2
- package/build/node.d.ts.map +1 -1
- package/build/node.js +19 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -31,3 +31,42 @@ log.info('some logs')
|
|
|
31
31
|
```
|
|
32
32
|
|
|
33
33
|
For more info see [`loglevel`](https://www.npmjs.com/package/loglevel) package on NPM.
|
|
34
|
+
|
|
35
|
+
## Custom Log Levels
|
|
36
|
+
|
|
37
|
+
This package extends the log levels available in [`loglevel`](https://www.npmjs.com/package/loglevel) by introducing a new level called `progress`.
|
|
38
|
+
|
|
39
|
+
The `progress` level is particularly useful when you need to dynamically update a specific line in the terminal. For example, it can be utilized to display the download progress of browsers or drivers.
|
|
40
|
+
|
|
41
|
+
Notably, the `progress` level is equivalent to the `info` level. Therefore, if you set the log level to `error` or `silent`, any `progress` logs will be suppressed.
|
|
42
|
+
|
|
43
|
+
It's important to mention that `progress` writes directly to `process.stdout`, and these logs won't be captured in any log files.
|
|
44
|
+
|
|
45
|
+
To ensure consistent formatting with subsequent logs while using `progress`, it's essential to clear it at the end. To do so, simply call `progress` with an empty string, which will clear the last line:
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
log.progress('')
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Illustrative Usage of Progress
|
|
52
|
+
|
|
53
|
+
```javascript
|
|
54
|
+
import logger from '@wdio/logger';
|
|
55
|
+
|
|
56
|
+
const log = logger('internal');
|
|
57
|
+
|
|
58
|
+
const totalSize = 100;
|
|
59
|
+
let uploadedSize = 0;
|
|
60
|
+
|
|
61
|
+
const uploadInterval = setInterval(() => {
|
|
62
|
+
const chunkSize = 10;
|
|
63
|
+
uploadedSize += chunkSize;
|
|
64
|
+
const data = `Progress: ${(uploadedSize * 100) / totalSize}%`;
|
|
65
|
+
log.progress(data);
|
|
66
|
+
if (uploadedSize >= totalSize) {
|
|
67
|
+
clearInterval(uploadInterval);
|
|
68
|
+
log.progress(''); // Called at the end to maintain the alignment of subsequent logs.
|
|
69
|
+
console.log('Upload complete.');
|
|
70
|
+
}
|
|
71
|
+
}, 100);
|
|
72
|
+
```
|
package/build/node.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import log from 'loglevel';
|
|
2
|
-
|
|
2
|
+
interface LoggerInterface extends log.Logger {
|
|
3
|
+
progress(...msg: any[]): void;
|
|
4
|
+
}
|
|
5
|
+
declare function getLogger(name: string): LoggerInterface;
|
|
3
6
|
declare namespace getLogger {
|
|
4
7
|
var waitForBuffer: () => Promise<void>;
|
|
5
8
|
var setLevel: (name: string, level: log.LogLevelDesc) => void;
|
|
@@ -7,5 +10,5 @@ declare namespace getLogger {
|
|
|
7
10
|
var setLogLevelsConfig: (logLevels?: Record<string, log.LogLevelDesc>, wdioLogLevel?: log.LogLevelDesc) => void;
|
|
8
11
|
}
|
|
9
12
|
export default getLogger;
|
|
10
|
-
export type Logger =
|
|
13
|
+
export type Logger = LoggerInterface;
|
|
11
14
|
//# sourceMappingURL=node.d.ts.map
|
package/build/node.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAGA,OAAO,GAAG,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAGA,OAAO,GAAG,MAAM,UAAU,CAAA;AAsD1B,UAAU,eAAgB,SAAQ,GAAG,CAAC,MAAM;IACxC,QAAQ,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;CACjC;AA2ED,iBAAwB,SAAS,CAAE,IAAI,EAAE,MAAM,mBAyB9C;kBAzBuB,SAAS;;;;;;eAAT,SAAS;AAiFjC,MAAM,MAAM,MAAM,GAAG,eAAe,CAAA"}
|
package/build/node.js
CHANGED
|
@@ -13,12 +13,15 @@ const COLORS = {
|
|
|
13
13
|
warn: 'yellow',
|
|
14
14
|
info: 'cyanBright',
|
|
15
15
|
debug: 'green',
|
|
16
|
-
trace: 'cyan'
|
|
16
|
+
trace: 'cyan',
|
|
17
|
+
progress: 'magenta'
|
|
17
18
|
};
|
|
18
19
|
const matches = {
|
|
19
20
|
COMMAND: 'COMMAND',
|
|
21
|
+
BIDICOMMAND: 'BIDI COMMAND',
|
|
20
22
|
DATA: 'DATA',
|
|
21
|
-
RESULT: 'RESULT'
|
|
23
|
+
RESULT: 'RESULT',
|
|
24
|
+
BIDIRESULT: 'BIDI RESULT'
|
|
22
25
|
};
|
|
23
26
|
const SERIALIZERS = [{
|
|
24
27
|
/**
|
|
@@ -30,7 +33,7 @@ const SERIALIZERS = [{
|
|
|
30
33
|
/**
|
|
31
34
|
* color commands blue
|
|
32
35
|
*/
|
|
33
|
-
matches: (log) => log === matches.COMMAND,
|
|
36
|
+
matches: (log) => log === matches.COMMAND || log === matches.BIDICOMMAND,
|
|
34
37
|
serialize: (log) => chalk.magenta(log)
|
|
35
38
|
}, {
|
|
36
39
|
/**
|
|
@@ -42,7 +45,7 @@ const SERIALIZERS = [{
|
|
|
42
45
|
/**
|
|
43
46
|
* color result cyan
|
|
44
47
|
*/
|
|
45
|
-
matches: (log) => log === matches.RESULT,
|
|
48
|
+
matches: (log) => log === matches.RESULT || log === matches.BIDIRESULT,
|
|
46
49
|
serialize: (log) => chalk.cyan(log)
|
|
47
50
|
}];
|
|
48
51
|
const loggers = log.getLoggers();
|
|
@@ -95,6 +98,17 @@ const wdioLoggerMethodFactory = function (methodName, logLevel, loggerName) {
|
|
|
95
98
|
rawMethod(...args);
|
|
96
99
|
};
|
|
97
100
|
};
|
|
101
|
+
const progress = function (data) {
|
|
102
|
+
if (process.stdout.isTTY && this.getLevel() <= log.levels.INFO) {
|
|
103
|
+
const level = 'progress';
|
|
104
|
+
const timestampFormatter = chalk.gray(new Date().toISOString());
|
|
105
|
+
const levelFormatter = chalk[COLORS[level]](level.toUpperCase());
|
|
106
|
+
const nameFormatter = chalk.whiteBright(this.name);
|
|
107
|
+
const _data = data.length > 0 ? `${timestampFormatter} ${levelFormatter} ${nameFormatter}: ${data}` : '\r\x1b[K';
|
|
108
|
+
process.stdout.write('\u001B[?25l'); // Disable cursor in terminal
|
|
109
|
+
process.stdout.write(`${_data}\r`);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
98
112
|
export default function getLogger(name) {
|
|
99
113
|
/**
|
|
100
114
|
* check if logger was already initiated
|
|
@@ -110,6 +124,7 @@ export default function getLogger(name) {
|
|
|
110
124
|
loggers[name] = log.getLogger(name);
|
|
111
125
|
loggers[name].setLevel(logLevel);
|
|
112
126
|
loggers[name].methodFactory = wdioLoggerMethodFactory;
|
|
127
|
+
loggers[name].progress = progress;
|
|
113
128
|
prefix.apply(loggers[name], {
|
|
114
129
|
template: '%t %l %n:',
|
|
115
130
|
timestampFormatter: (date) => chalk.gray(date.toISOString()),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wdio/logger",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.16.17",
|
|
4
4
|
"description": "A helper utility for logging of WebdriverIO packages",
|
|
5
5
|
"author": "Christian Bromann <mail@bromann.dev>",
|
|
6
6
|
"homepage": "https://github.com/webdriverio/webdriverio/tree/main/packages/wdio-logger",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "5bb4539c96e11a7ece83630b30c0a54903b55c0e"
|
|
41
41
|
}
|