@wdio/logger 6.10.4 → 7.0.0
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/build/index.d.ts +3 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +13 -0
- package/build/node.d.ts.map +1 -1
- package/build/node.js +45 -1
- package/build/web.js +6 -0
- package/package.json +5 -5
package/build/index.d.ts
CHANGED
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA;;GAEG;AAGH,QAAA,IAAI,IAAI,KAA2B,CAAA;AAcnC,eAAe,IAAI,CAAA"}
|
package/build/index.js
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/* istanbul ignore file */
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
/**
|
|
5
|
+
* environment check to allow to use this package in a web context
|
|
6
|
+
*/
|
|
7
|
+
// By default, import the web code using a literal require, so that in webpack
|
|
8
|
+
// contexts, it will always be bundled
|
|
3
9
|
let mode = require('./web').default;
|
|
10
|
+
// Then, if we're in a Node.js context, require the node version of this module
|
|
11
|
+
// using a variable, so that it will _not_ be included in a bundle, either
|
|
12
|
+
// during compilation or execution
|
|
4
13
|
if (typeof process !== 'undefined' && typeof process.release !== 'undefined' && process.release.name === 'node') {
|
|
5
14
|
const nodeMode = './node';
|
|
6
15
|
mode = require(nodeMode).default;
|
|
7
16
|
}
|
|
17
|
+
// The net result will be that in a Node context, we'll have required both
|
|
18
|
+
// files but will use the correct one, and in the web context, we'll have only
|
|
19
|
+
// required the web file, thus ensuring that the Node file and related
|
|
20
|
+
// dependencies will not be bundled inadvertently.
|
|
8
21
|
exports.default = mode;
|
package/build/node.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AACA,OAAO,GAAG,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AACA,OAAO,GAAG,MAAM,UAAU,CAAA;AA4G1B,iBAAwB,SAAS,CAAE,IAAI,EAAE,MAAM,cAwB9C;kBAxBuB,SAAS;;;;;;eAAT,SAAS;AAgFjC,oBAAY,MAAM,GAAG,GAAG,CAAC,MAAM,CAAA"}
|
package/build/node.js
CHANGED
|
@@ -10,7 +10,9 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
10
10
|
const loglevel_plugin_prefix_1 = __importDefault(require("loglevel-plugin-prefix"));
|
|
11
11
|
const strip_ansi_1 = __importDefault(require("strip-ansi"));
|
|
12
12
|
loglevel_plugin_prefix_1.default.reg(loglevel_1.default);
|
|
13
|
-
const DEFAULT_LEVEL =
|
|
13
|
+
const DEFAULT_LEVEL = process.env.WDIO_DEBUG
|
|
14
|
+
? 'trace'
|
|
15
|
+
: 'info';
|
|
14
16
|
const COLORS = {
|
|
15
17
|
error: 'red',
|
|
16
18
|
warn: 'yellow',
|
|
@@ -24,15 +26,27 @@ const matches = {
|
|
|
24
26
|
RESULT: 'RESULT'
|
|
25
27
|
};
|
|
26
28
|
const SERIALIZERS = [{
|
|
29
|
+
/**
|
|
30
|
+
* display error stack
|
|
31
|
+
*/
|
|
27
32
|
matches: (err) => err instanceof Error,
|
|
28
33
|
serialize: (err) => err.stack
|
|
29
34
|
}, {
|
|
35
|
+
/**
|
|
36
|
+
* color commands blue
|
|
37
|
+
*/
|
|
30
38
|
matches: (log) => log === matches.COMMAND,
|
|
31
39
|
serialize: (log) => chalk_1.default.magenta(log)
|
|
32
40
|
}, {
|
|
41
|
+
/**
|
|
42
|
+
* color data yellow
|
|
43
|
+
*/
|
|
33
44
|
matches: (log) => log === matches.DATA,
|
|
34
45
|
serialize: (log) => chalk_1.default.yellow(log)
|
|
35
46
|
}, {
|
|
47
|
+
/**
|
|
48
|
+
* color result cyan
|
|
49
|
+
*/
|
|
36
50
|
matches: (log) => log === matches.RESULT,
|
|
37
51
|
serialize: (log) => chalk_1.default.cyan(log)
|
|
38
52
|
}];
|
|
@@ -44,9 +58,16 @@ const originalFactory = loglevel_1.default.methodFactory;
|
|
|
44
58
|
const wdioLoggerMethodFactory = function (methodName, logLevel, loggerName) {
|
|
45
59
|
const rawMethod = originalFactory(methodName, logLevel, loggerName);
|
|
46
60
|
return (...args) => {
|
|
61
|
+
/**
|
|
62
|
+
* create logFile lazily
|
|
63
|
+
*/
|
|
47
64
|
if (!logFile && process.env.WDIO_LOG_PATH) {
|
|
48
65
|
logFile = fs_1.default.createWriteStream(process.env.WDIO_LOG_PATH);
|
|
49
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* split `prefixer: value` sting to `prefixer: ` and `value`
|
|
69
|
+
* so that SERIALIZERS can match certain string
|
|
70
|
+
*/
|
|
50
71
|
const match = Object.values(matches).filter(x => args[0].endsWith(`: ${x}`))[0];
|
|
51
72
|
if (match) {
|
|
52
73
|
const prefixStr = args.shift().slice(0, -match.length - 1);
|
|
@@ -62,6 +83,9 @@ const wdioLoggerMethodFactory = function (methodName, logLevel, loggerName) {
|
|
|
62
83
|
});
|
|
63
84
|
const logText = strip_ansi_1.default(`${util_1.default.format.apply(this, args)}\n`);
|
|
64
85
|
if (logFile && logFile.writable) {
|
|
86
|
+
/**
|
|
87
|
+
* empty logging cache if stuff got logged before
|
|
88
|
+
*/
|
|
65
89
|
if (logCache.size) {
|
|
66
90
|
logCache.forEach((log) => {
|
|
67
91
|
if (logFile) {
|
|
@@ -77,6 +101,9 @@ const wdioLoggerMethodFactory = function (methodName, logLevel, loggerName) {
|
|
|
77
101
|
};
|
|
78
102
|
};
|
|
79
103
|
function getLogger(name) {
|
|
104
|
+
/**
|
|
105
|
+
* check if logger was already initiated
|
|
106
|
+
*/
|
|
80
107
|
if (loggers[name]) {
|
|
81
108
|
return loggers[name];
|
|
82
109
|
}
|
|
@@ -97,7 +124,12 @@ function getLogger(name) {
|
|
|
97
124
|
return loggers[name];
|
|
98
125
|
}
|
|
99
126
|
exports.default = getLogger;
|
|
127
|
+
/**
|
|
128
|
+
* Wait for writable stream to be flushed.
|
|
129
|
+
* Calling this prevents part of the logs in the very env to be lost.
|
|
130
|
+
*/
|
|
100
131
|
getLogger.waitForBuffer = async () => new Promise(resolve => {
|
|
132
|
+
// @ts-ignore
|
|
101
133
|
if (logFile && Array.isArray(logFile.writableBuffer) && logFile.writableBuffer.length !== 0) {
|
|
102
134
|
return setTimeout(async () => {
|
|
103
135
|
await getLogger.waitForBuffer();
|
|
@@ -114,16 +146,28 @@ getLogger.clearLogger = () => {
|
|
|
114
146
|
logFile = null;
|
|
115
147
|
};
|
|
116
148
|
getLogger.setLogLevelsConfig = (logLevels = {}, wdioLogLevel = DEFAULT_LEVEL) => {
|
|
149
|
+
/**
|
|
150
|
+
* set log level
|
|
151
|
+
*/
|
|
117
152
|
if (process.env.WDIO_LOG_LEVEL === undefined) {
|
|
118
153
|
process.env.WDIO_LOG_LEVEL = wdioLogLevel;
|
|
119
154
|
}
|
|
120
155
|
logLevelsConfig = {};
|
|
156
|
+
/**
|
|
157
|
+
* build logLevelsConfig object
|
|
158
|
+
*/
|
|
121
159
|
Object.entries(logLevels).forEach(([logName, logLevel]) => {
|
|
122
160
|
const logLevelName = getLogLevelName(logName);
|
|
123
161
|
logLevelsConfig[logLevelName] = logLevel;
|
|
124
162
|
});
|
|
163
|
+
/**
|
|
164
|
+
* set log level for each logger
|
|
165
|
+
*/
|
|
125
166
|
Object.keys(loggers).forEach(logName => {
|
|
126
167
|
const logLevelName = getLogLevelName(logName);
|
|
168
|
+
/**
|
|
169
|
+
* either apply log level from logLevels object or use global logLevel
|
|
170
|
+
*/
|
|
127
171
|
const logLevel = typeof logLevelsConfig[logLevelName] !== 'undefined' ? logLevelsConfig[logLevelName] : process.env.WDIO_LOG_LEVEL;
|
|
128
172
|
loggers[logName].setLevel(logLevel);
|
|
129
173
|
});
|
package/build/web.js
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/* istanbul ignore file */
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
const LOG_METHODS = ['error', 'warn', 'info', 'debug', 'trace', 'silent'];
|
|
4
5
|
function getLogger(component) {
|
|
5
6
|
return LOG_METHODS.reduce((acc, cur) => {
|
|
6
7
|
const prop = cur;
|
|
8
|
+
// check if the method is available on console (web doesn't have
|
|
9
|
+
// 'silent', for example) before adding to acc
|
|
10
|
+
// eslint-disable-next-line no-console
|
|
7
11
|
if (console[prop]) {
|
|
12
|
+
// eslint-disable-next-line no-console
|
|
8
13
|
acc[prop] = console[prop].bind(console, `${component}:`);
|
|
9
14
|
}
|
|
10
15
|
return acc;
|
|
11
16
|
}, {});
|
|
12
17
|
}
|
|
13
18
|
exports.default = getLogger;
|
|
19
|
+
// logging interface expects a 'setLevel' method
|
|
14
20
|
getLogger.setLevel = () => { };
|
|
15
21
|
getLogger.setLogLevelsConfig = () => { };
|
|
16
22
|
getLogger.waitForBuffer = () => { };
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wdio/logger",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "A helper utility for logging of WebdriverIO packages",
|
|
5
5
|
"author": "Christian Bromann <christian@saucelabs.com>",
|
|
6
|
-
"homepage": "https://github.com/webdriverio/webdriverio/tree/
|
|
6
|
+
"homepage": "https://github.com/webdriverio/webdriverio/tree/main/packages/wdio-logger",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"main": "./build/node",
|
|
9
9
|
"engines": {
|
|
10
|
-
"node": ">=
|
|
10
|
+
"node": ">=12.0.0"
|
|
11
11
|
},
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"url": "https://github.com/webdriverio/webdriverio/issues"
|
|
23
23
|
},
|
|
24
24
|
"types": "./build/node.d.ts",
|
|
25
|
-
"typeScriptVersion": "3.
|
|
25
|
+
"typeScriptVersion": "3.8.3",
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"chalk": "^4.0.0",
|
|
28
28
|
"loglevel": "^1.6.0",
|
|
@@ -32,5 +32,5 @@
|
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "b03188f55479f936d9ca899967883d929cde191c"
|
|
36
36
|
}
|