@wdio/logger 9.0.0-alpha.9 → 9.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/{web.d.ts → browser.d.ts} +6 -1
- package/build/browser.d.ts.map +1 -0
- package/build/browser.js +22 -0
- package/build/index.d.ts +13 -4
- package/build/index.d.ts.map +1 -1
- package/build/index.js +168 -18
- package/package.json +10 -3
- package/build/node.d.ts +0 -14
- package/build/node.d.ts.map +0 -1
- package/build/node.js +0 -197
- package/build/web.d.ts.map +0 -1
- package/build/web.js +0 -21
- /package/{LICENSE-MIT → LICENSE} +0 -0
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
export type { Logger } from './index.js';
|
|
2
|
+
/**
|
|
3
|
+
* This implementation of the Logger package is a simple adptation to run it within
|
|
4
|
+
* a browser environment.
|
|
5
|
+
*/
|
|
1
6
|
declare function getLogger(component: string): Console;
|
|
2
7
|
declare namespace getLogger {
|
|
3
8
|
var setLevel: () => void;
|
|
@@ -6,4 +11,4 @@ declare namespace getLogger {
|
|
|
6
11
|
var clearLogger: () => void;
|
|
7
12
|
}
|
|
8
13
|
export default getLogger;
|
|
9
|
-
//# sourceMappingURL=
|
|
14
|
+
//# sourceMappingURL=browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAIA,YAAY,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAExC;;;GAGG;AACH,iBAAwB,SAAS,CAAE,SAAS,EAAE,MAAM,WAcnD;kBAduB,SAAS;;;;;;eAAT,SAAS"}
|
package/build/browser.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// src/browser.ts
|
|
2
|
+
var LOG_METHODS = ["error", "warn", "info", "debug", "trace", "silent"];
|
|
3
|
+
function getLogger(component) {
|
|
4
|
+
return LOG_METHODS.reduce((acc, cur) => {
|
|
5
|
+
const prop = cur;
|
|
6
|
+
if (console[prop]) {
|
|
7
|
+
acc[prop] = console[prop].bind(console, "".concat(component, ":"));
|
|
8
|
+
}
|
|
9
|
+
return acc;
|
|
10
|
+
}, {});
|
|
11
|
+
}
|
|
12
|
+
getLogger.setLevel = () => {
|
|
13
|
+
};
|
|
14
|
+
getLogger.setLogLevelsConfig = () => {
|
|
15
|
+
};
|
|
16
|
+
getLogger.waitForBuffer = () => {
|
|
17
|
+
};
|
|
18
|
+
getLogger.clearLogger = () => {
|
|
19
|
+
};
|
|
20
|
+
export {
|
|
21
|
+
getLogger as default
|
|
22
|
+
};
|
package/build/index.d.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import log from 'loglevel';
|
|
2
|
+
interface LoggerInterface extends log.Logger {
|
|
3
|
+
progress(...msg: any[]): void;
|
|
4
|
+
}
|
|
5
|
+
declare function getLogger(name: string): LoggerInterface;
|
|
6
|
+
declare namespace getLogger {
|
|
7
|
+
var waitForBuffer: () => Promise<void>;
|
|
8
|
+
var setLevel: (name: string, level: log.LogLevelDesc) => void;
|
|
9
|
+
var clearLogger: () => void;
|
|
10
|
+
var setLogLevelsConfig: (logLevels?: Record<string, log.LogLevelDesc>, wdioLogLevel?: log.LogLevelDesc) => void;
|
|
11
|
+
}
|
|
12
|
+
export default getLogger;
|
|
13
|
+
export type Logger = LoggerInterface;
|
|
5
14
|
//# sourceMappingURL=index.d.ts.map
|
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":"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;AA+ED,iBAAwB,SAAS,CAAE,IAAI,EAAE,MAAM,mBAyB9C;kBAzBuB,SAAS;;yBAwCL,MAAM,SAAS,GAAG,CAAC,YAAY;;yCAOhB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,YAAY,CAAC,iBAAqB,GAAG,CAAC,YAAY;;eA/CxF,SAAS;AAiFjC,MAAM,MAAM,MAAM,GAAG,eAAe,CAAA"}
|
package/build/index.js
CHANGED
|
@@ -1,19 +1,169 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import util from "node:util";
|
|
4
|
+
import log from "loglevel";
|
|
5
|
+
import chalk from "chalk";
|
|
6
|
+
import prefix from "loglevel-plugin-prefix";
|
|
7
|
+
import ansiStrip from "strip-ansi";
|
|
8
|
+
prefix.reg(log);
|
|
9
|
+
var DEFAULT_LEVEL = process.env.WDIO_DEBUG ? "trace" : "info";
|
|
10
|
+
var COLORS = {
|
|
11
|
+
error: "red",
|
|
12
|
+
warn: "yellow",
|
|
13
|
+
info: "cyanBright",
|
|
14
|
+
debug: "green",
|
|
15
|
+
trace: "cyan",
|
|
16
|
+
progress: "magenta"
|
|
17
|
+
};
|
|
18
|
+
var matches = {
|
|
19
|
+
COMMAND: "COMMAND",
|
|
20
|
+
BIDICOMMAND: "BIDI COMMAND",
|
|
21
|
+
DATA: "DATA",
|
|
22
|
+
RESULT: "RESULT",
|
|
23
|
+
BIDIRESULT: "BIDI RESULT"
|
|
24
|
+
};
|
|
25
|
+
var SERIALIZERS = [{
|
|
26
|
+
/**
|
|
27
|
+
* display error stack
|
|
28
|
+
*/
|
|
29
|
+
matches: (err) => err instanceof Error,
|
|
30
|
+
serialize: (err) => err.stack
|
|
31
|
+
}, {
|
|
32
|
+
/**
|
|
33
|
+
* color commands blue
|
|
34
|
+
*/
|
|
35
|
+
matches: (log2) => log2 === matches.COMMAND || log2 === matches.BIDICOMMAND,
|
|
36
|
+
serialize: (log2) => chalk.magenta(log2)
|
|
37
|
+
}, {
|
|
38
|
+
/**
|
|
39
|
+
* color data yellow
|
|
40
|
+
*/
|
|
41
|
+
matches: (log2) => log2 === matches.DATA,
|
|
42
|
+
serialize: (log2) => chalk.yellow(log2)
|
|
43
|
+
}, {
|
|
44
|
+
/**
|
|
45
|
+
* color result cyan
|
|
46
|
+
*/
|
|
47
|
+
matches: (log2) => log2 === matches.RESULT || log2 === matches.BIDIRESULT,
|
|
48
|
+
serialize: (log2) => chalk.cyan(log2)
|
|
49
|
+
}];
|
|
50
|
+
var loggers = log.getLoggers();
|
|
51
|
+
var logLevelsConfig = {};
|
|
52
|
+
var logCache = /* @__PURE__ */ new Set();
|
|
53
|
+
var logFile;
|
|
54
|
+
var originalFactory = log.methodFactory;
|
|
55
|
+
var wdioLoggerMethodFactory = function(methodName, logLevel, loggerName) {
|
|
56
|
+
const rawMethod = originalFactory(methodName, logLevel, loggerName);
|
|
57
|
+
return (...args) => {
|
|
58
|
+
if (!logFile && process.env.WDIO_LOG_PATH) {
|
|
59
|
+
logFile = fs.createWriteStream(process.env.WDIO_LOG_PATH);
|
|
60
|
+
}
|
|
61
|
+
const match = Object.values(matches).filter((x) => args[0].endsWith(`: ${x}`))[0];
|
|
62
|
+
if (match) {
|
|
63
|
+
const prefixStr = args.shift().slice(0, -match.length - 1);
|
|
64
|
+
args.unshift(prefixStr, match);
|
|
65
|
+
}
|
|
66
|
+
args = args.map((arg) => {
|
|
67
|
+
for (const s of SERIALIZERS) {
|
|
68
|
+
if (s.matches(arg)) {
|
|
69
|
+
return s.serialize(arg);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return arg;
|
|
73
|
+
});
|
|
74
|
+
const logText = ansiStrip(`${util.format.apply(this, args)}
|
|
75
|
+
`);
|
|
76
|
+
if (logFile && logFile.writable) {
|
|
77
|
+
if (logCache.size) {
|
|
78
|
+
logCache.forEach((log2) => {
|
|
79
|
+
if (logFile) {
|
|
80
|
+
logFile.write(log2);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
logCache.clear();
|
|
84
|
+
}
|
|
85
|
+
if (!logsContainInitPackageError(logText)) {
|
|
86
|
+
return logFile.write(logText);
|
|
87
|
+
}
|
|
88
|
+
logFile.write(logText);
|
|
89
|
+
}
|
|
90
|
+
logCache.add(logText);
|
|
91
|
+
rawMethod(...args);
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
var progress = function(data) {
|
|
95
|
+
if (process.stdout.isTTY && this.getLevel() <= log.levels.INFO) {
|
|
96
|
+
const level = "progress";
|
|
97
|
+
const timestampFormatter = chalk.gray((/* @__PURE__ */ new Date()).toISOString());
|
|
98
|
+
const levelFormatter = chalk[COLORS[level]](level.toUpperCase());
|
|
99
|
+
const nameFormatter = chalk.whiteBright(this.name);
|
|
100
|
+
const _data = data.length > 0 ? `${timestampFormatter} ${levelFormatter} ${nameFormatter}: ${data}` : "\r\x1B[K\x1B[?25h";
|
|
101
|
+
process.stdout.write("\x1B[?25l");
|
|
102
|
+
process.stdout.write(`${_data}\r`);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
function getLogger(name) {
|
|
106
|
+
if (loggers[name]) {
|
|
107
|
+
return loggers[name];
|
|
108
|
+
}
|
|
109
|
+
let logLevel = process.env.WDIO_LOG_LEVEL || DEFAULT_LEVEL;
|
|
110
|
+
const logLevelName = getLogLevelName(name);
|
|
111
|
+
if (logLevelsConfig[logLevelName]) {
|
|
112
|
+
logLevel = logLevelsConfig[logLevelName];
|
|
113
|
+
}
|
|
114
|
+
loggers[name] = log.getLogger(name);
|
|
115
|
+
loggers[name].setLevel(logLevel);
|
|
116
|
+
loggers[name].methodFactory = wdioLoggerMethodFactory;
|
|
117
|
+
loggers[name].progress = progress;
|
|
118
|
+
prefix.apply(loggers[name], {
|
|
119
|
+
template: "%t %l %n:",
|
|
120
|
+
timestampFormatter: (date) => chalk.gray(date.toISOString()),
|
|
121
|
+
levelFormatter: (level) => chalk[COLORS[level]](level.toUpperCase()),
|
|
122
|
+
nameFormatter: (name2) => chalk.whiteBright(name2)
|
|
123
|
+
});
|
|
124
|
+
return loggers[name];
|
|
14
125
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
126
|
+
getLogger.waitForBuffer = async () => new Promise((resolve) => {
|
|
127
|
+
if (logFile && Array.isArray(logFile.writableBuffer) && logFile.writableBuffer.length !== 0) {
|
|
128
|
+
return setTimeout(async () => {
|
|
129
|
+
await getLogger.waitForBuffer();
|
|
130
|
+
resolve();
|
|
131
|
+
}, 20);
|
|
132
|
+
}
|
|
133
|
+
resolve();
|
|
134
|
+
});
|
|
135
|
+
getLogger.setLevel = (name, level) => loggers[name].setLevel(level);
|
|
136
|
+
getLogger.clearLogger = () => {
|
|
137
|
+
if (logFile) {
|
|
138
|
+
logFile.end();
|
|
139
|
+
}
|
|
140
|
+
logFile = null;
|
|
141
|
+
};
|
|
142
|
+
getLogger.setLogLevelsConfig = (logLevels = {}, wdioLogLevel = DEFAULT_LEVEL) => {
|
|
143
|
+
if (process.env.WDIO_LOG_LEVEL === void 0) {
|
|
144
|
+
process.env.WDIO_LOG_LEVEL = wdioLogLevel;
|
|
145
|
+
}
|
|
146
|
+
logLevelsConfig = {};
|
|
147
|
+
Object.entries(logLevels).forEach(([logName, logLevel]) => {
|
|
148
|
+
const logLevelName = getLogLevelName(logName);
|
|
149
|
+
logLevelsConfig[logLevelName] = logLevel;
|
|
150
|
+
});
|
|
151
|
+
Object.keys(loggers).forEach((logName) => {
|
|
152
|
+
const logLevelName = getLogLevelName(logName);
|
|
153
|
+
const logLevel = typeof logLevelsConfig[logLevelName] !== "undefined" ? logLevelsConfig[logLevelName] : process.env.WDIO_LOG_LEVEL;
|
|
154
|
+
loggers[logName].setLevel(logLevel);
|
|
155
|
+
});
|
|
156
|
+
};
|
|
157
|
+
var getLogLevelName = (logName) => logName.split(":").shift();
|
|
158
|
+
function logsContainInitPackageError(logText) {
|
|
159
|
+
return ERROR_LOG_VALIDATOR.every((pattern) => logText.includes(pattern));
|
|
160
|
+
}
|
|
161
|
+
var ERROR_LOG_VALIDATOR = [
|
|
162
|
+
"Couldn't find plugin",
|
|
163
|
+
"neither as wdio scoped package",
|
|
164
|
+
"nor as community package",
|
|
165
|
+
"Please make sure you have it installed"
|
|
166
|
+
];
|
|
167
|
+
export {
|
|
168
|
+
getLogger as default
|
|
169
|
+
};
|
package/package.json
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wdio/logger",
|
|
3
|
-
"version": "9.0.0
|
|
3
|
+
"version": "9.0.0",
|
|
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",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"types": "./build/index.d.ts",
|
|
10
|
+
"main": "./build/index.cjs",
|
|
11
|
+
"browser": "./build/browser.js",
|
|
10
12
|
"exports": {
|
|
11
|
-
".":
|
|
13
|
+
".": {
|
|
14
|
+
"browser": "./build/browser.js",
|
|
15
|
+
"import": "./build/index.js",
|
|
16
|
+
"types": "./build/index.d.ts",
|
|
17
|
+
"browserSource": "./src/browser.ts"
|
|
18
|
+
},
|
|
12
19
|
"./package.json": "./package.json"
|
|
13
20
|
},
|
|
14
21
|
"typeScriptVersion": "3.8.3",
|
|
@@ -37,5 +44,5 @@
|
|
|
37
44
|
"publishConfig": {
|
|
38
45
|
"access": "public"
|
|
39
46
|
},
|
|
40
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "957693463371a4cb329395dcdbce8fb0c930ab93"
|
|
41
48
|
}
|
package/build/node.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import log from 'loglevel';
|
|
2
|
-
interface LoggerInterface extends log.Logger {
|
|
3
|
-
progress(...msg: any[]): void;
|
|
4
|
-
}
|
|
5
|
-
declare function getLogger(name: string): LoggerInterface;
|
|
6
|
-
declare namespace getLogger {
|
|
7
|
-
var waitForBuffer: () => Promise<void>;
|
|
8
|
-
var setLevel: (name: string, level: log.LogLevelDesc) => void;
|
|
9
|
-
var clearLogger: () => void;
|
|
10
|
-
var setLogLevelsConfig: (logLevels?: Record<string, log.LogLevelDesc>, wdioLogLevel?: log.LogLevelDesc) => void;
|
|
11
|
-
}
|
|
12
|
-
export default getLogger;
|
|
13
|
-
export type Logger = LoggerInterface;
|
|
14
|
-
//# sourceMappingURL=node.d.ts.map
|
package/build/node.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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;AA+ED,iBAAwB,SAAS,CAAE,IAAI,EAAE,MAAM,mBAyB9C;kBAzBuB,SAAS;;;;;;eAAT,SAAS;AAiFjC,MAAM,MAAM,MAAM,GAAG,eAAe,CAAA"}
|
package/build/node.js
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import util from 'node:util';
|
|
3
|
-
import log from 'loglevel';
|
|
4
|
-
import chalk from 'chalk';
|
|
5
|
-
import prefix from 'loglevel-plugin-prefix';
|
|
6
|
-
import ansiStrip from 'strip-ansi';
|
|
7
|
-
prefix.reg(log);
|
|
8
|
-
const DEFAULT_LEVEL = process.env.WDIO_DEBUG
|
|
9
|
-
? 'trace'
|
|
10
|
-
: 'info';
|
|
11
|
-
const COLORS = {
|
|
12
|
-
error: 'red',
|
|
13
|
-
warn: 'yellow',
|
|
14
|
-
info: 'cyanBright',
|
|
15
|
-
debug: 'green',
|
|
16
|
-
trace: 'cyan',
|
|
17
|
-
progress: 'magenta'
|
|
18
|
-
};
|
|
19
|
-
const matches = {
|
|
20
|
-
COMMAND: 'COMMAND',
|
|
21
|
-
BIDICOMMAND: 'BIDI COMMAND',
|
|
22
|
-
DATA: 'DATA',
|
|
23
|
-
RESULT: 'RESULT',
|
|
24
|
-
BIDIRESULT: 'BIDI RESULT'
|
|
25
|
-
};
|
|
26
|
-
const SERIALIZERS = [{
|
|
27
|
-
/**
|
|
28
|
-
* display error stack
|
|
29
|
-
*/
|
|
30
|
-
matches: (err) => err instanceof Error,
|
|
31
|
-
serialize: (err) => err.stack
|
|
32
|
-
}, {
|
|
33
|
-
/**
|
|
34
|
-
* color commands blue
|
|
35
|
-
*/
|
|
36
|
-
matches: (log) => log === matches.COMMAND || log === matches.BIDICOMMAND,
|
|
37
|
-
serialize: (log) => chalk.magenta(log)
|
|
38
|
-
}, {
|
|
39
|
-
/**
|
|
40
|
-
* color data yellow
|
|
41
|
-
*/
|
|
42
|
-
matches: (log) => log === matches.DATA,
|
|
43
|
-
serialize: (log) => chalk.yellow(log)
|
|
44
|
-
}, {
|
|
45
|
-
/**
|
|
46
|
-
* color result cyan
|
|
47
|
-
*/
|
|
48
|
-
matches: (log) => log === matches.RESULT || log === matches.BIDIRESULT,
|
|
49
|
-
serialize: (log) => chalk.cyan(log)
|
|
50
|
-
}];
|
|
51
|
-
const loggers = log.getLoggers();
|
|
52
|
-
let logLevelsConfig = {};
|
|
53
|
-
const logCache = new Set();
|
|
54
|
-
let logFile;
|
|
55
|
-
const originalFactory = log.methodFactory;
|
|
56
|
-
const wdioLoggerMethodFactory = function (methodName, logLevel, loggerName) {
|
|
57
|
-
const rawMethod = originalFactory(methodName, logLevel, loggerName);
|
|
58
|
-
return (...args) => {
|
|
59
|
-
/**
|
|
60
|
-
* create logFile lazily
|
|
61
|
-
*/
|
|
62
|
-
if (!logFile && process.env.WDIO_LOG_PATH) {
|
|
63
|
-
logFile = fs.createWriteStream(process.env.WDIO_LOG_PATH);
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* split `prefixer: value` sting to `prefixer: ` and `value`
|
|
67
|
-
* so that SERIALIZERS can match certain string
|
|
68
|
-
*/
|
|
69
|
-
const match = Object.values(matches).filter(x => args[0].endsWith(`: ${x}`))[0];
|
|
70
|
-
if (match) {
|
|
71
|
-
const prefixStr = args.shift().slice(0, -match.length - 1);
|
|
72
|
-
args.unshift(prefixStr, match);
|
|
73
|
-
}
|
|
74
|
-
args = args.map((arg) => {
|
|
75
|
-
for (const s of SERIALIZERS) {
|
|
76
|
-
if (s.matches(arg)) {
|
|
77
|
-
return s.serialize(arg);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return arg;
|
|
81
|
-
});
|
|
82
|
-
const logText = ansiStrip(`${util.format.apply(this, args)}\n`);
|
|
83
|
-
if (logFile && logFile.writable) {
|
|
84
|
-
/**
|
|
85
|
-
* empty logging cache if stuff got logged before
|
|
86
|
-
*/
|
|
87
|
-
if (logCache.size) {
|
|
88
|
-
logCache.forEach((log) => {
|
|
89
|
-
if (logFile) {
|
|
90
|
-
logFile.write(log);
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
logCache.clear();
|
|
94
|
-
}
|
|
95
|
-
if (!logsContainInitPackageError(logText)) {
|
|
96
|
-
return logFile.write(logText);
|
|
97
|
-
}
|
|
98
|
-
// If we get Error during init of integration packages, write logs to both "outputDir" and the terminal
|
|
99
|
-
logFile.write(logText);
|
|
100
|
-
}
|
|
101
|
-
logCache.add(logText);
|
|
102
|
-
rawMethod(...args);
|
|
103
|
-
};
|
|
104
|
-
};
|
|
105
|
-
const progress = function (data) {
|
|
106
|
-
if (process.stdout.isTTY && this.getLevel() <= log.levels.INFO) {
|
|
107
|
-
const level = 'progress';
|
|
108
|
-
const timestampFormatter = chalk.gray(new Date().toISOString());
|
|
109
|
-
const levelFormatter = chalk[COLORS[level]](level.toUpperCase());
|
|
110
|
-
const nameFormatter = chalk.whiteBright(this.name);
|
|
111
|
-
const _data = data.length > 0 ? `${timestampFormatter} ${levelFormatter} ${nameFormatter}: ${data}` : '\r\x1b[K';
|
|
112
|
-
process.stdout.write('\u001B[?25l'); // Disable cursor in terminal
|
|
113
|
-
process.stdout.write(`${_data}\r`);
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
export default function getLogger(name) {
|
|
117
|
-
/**
|
|
118
|
-
* check if logger was already initiated
|
|
119
|
-
*/
|
|
120
|
-
if (loggers[name]) {
|
|
121
|
-
return loggers[name];
|
|
122
|
-
}
|
|
123
|
-
let logLevel = (process.env.WDIO_LOG_LEVEL || DEFAULT_LEVEL);
|
|
124
|
-
const logLevelName = getLogLevelName(name);
|
|
125
|
-
if (logLevelsConfig[logLevelName]) {
|
|
126
|
-
logLevel = logLevelsConfig[logLevelName];
|
|
127
|
-
}
|
|
128
|
-
loggers[name] = log.getLogger(name);
|
|
129
|
-
loggers[name].setLevel(logLevel);
|
|
130
|
-
loggers[name].methodFactory = wdioLoggerMethodFactory;
|
|
131
|
-
loggers[name].progress = progress;
|
|
132
|
-
prefix.apply(loggers[name], {
|
|
133
|
-
template: '%t %l %n:',
|
|
134
|
-
timestampFormatter: (date) => chalk.gray(date.toISOString()),
|
|
135
|
-
levelFormatter: (level) => chalk[COLORS[level]](level.toUpperCase()),
|
|
136
|
-
nameFormatter: (name) => chalk.whiteBright(name)
|
|
137
|
-
});
|
|
138
|
-
return loggers[name];
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Wait for writable stream to be flushed.
|
|
142
|
-
* Calling this prevents part of the logs in the very env to be lost.
|
|
143
|
-
*/
|
|
144
|
-
getLogger.waitForBuffer = async () => new Promise(resolve => {
|
|
145
|
-
// @ts-ignore
|
|
146
|
-
if (logFile && Array.isArray(logFile.writableBuffer) && logFile.writableBuffer.length !== 0) {
|
|
147
|
-
return setTimeout(async () => {
|
|
148
|
-
await getLogger.waitForBuffer();
|
|
149
|
-
resolve();
|
|
150
|
-
}, 20);
|
|
151
|
-
}
|
|
152
|
-
resolve();
|
|
153
|
-
});
|
|
154
|
-
getLogger.setLevel = (name, level) => loggers[name].setLevel(level);
|
|
155
|
-
getLogger.clearLogger = () => {
|
|
156
|
-
if (logFile) {
|
|
157
|
-
logFile.end();
|
|
158
|
-
}
|
|
159
|
-
logFile = null;
|
|
160
|
-
};
|
|
161
|
-
getLogger.setLogLevelsConfig = (logLevels = {}, wdioLogLevel = DEFAULT_LEVEL) => {
|
|
162
|
-
/**
|
|
163
|
-
* set log level
|
|
164
|
-
*/
|
|
165
|
-
if (process.env.WDIO_LOG_LEVEL === undefined) {
|
|
166
|
-
process.env.WDIO_LOG_LEVEL = wdioLogLevel;
|
|
167
|
-
}
|
|
168
|
-
logLevelsConfig = {};
|
|
169
|
-
/**
|
|
170
|
-
* build logLevelsConfig object
|
|
171
|
-
*/
|
|
172
|
-
Object.entries(logLevels).forEach(([logName, logLevel]) => {
|
|
173
|
-
const logLevelName = getLogLevelName(logName);
|
|
174
|
-
logLevelsConfig[logLevelName] = logLevel;
|
|
175
|
-
});
|
|
176
|
-
/**
|
|
177
|
-
* set log level for each logger
|
|
178
|
-
*/
|
|
179
|
-
Object.keys(loggers).forEach(logName => {
|
|
180
|
-
const logLevelName = getLogLevelName(logName);
|
|
181
|
-
/**
|
|
182
|
-
* either apply log level from logLevels object or use global logLevel
|
|
183
|
-
*/
|
|
184
|
-
const logLevel = typeof logLevelsConfig[logLevelName] !== 'undefined' ? logLevelsConfig[logLevelName] : process.env.WDIO_LOG_LEVEL;
|
|
185
|
-
loggers[logName].setLevel(logLevel);
|
|
186
|
-
});
|
|
187
|
-
};
|
|
188
|
-
const getLogLevelName = (logName) => logName.split(':').shift();
|
|
189
|
-
function logsContainInitPackageError(logText) {
|
|
190
|
-
return ERROR_LOG_VALIDATOR.every(pattern => logText.includes(pattern));
|
|
191
|
-
}
|
|
192
|
-
const ERROR_LOG_VALIDATOR = [
|
|
193
|
-
'Couldn\'t find plugin',
|
|
194
|
-
'neither as wdio scoped package',
|
|
195
|
-
'nor as community package',
|
|
196
|
-
'Please make sure you have it installed'
|
|
197
|
-
];
|
package/build/web.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../src/web.ts"],"names":[],"mappings":"AAIA,iBAAwB,SAAS,CAAE,SAAS,EAAE,MAAM,WAcnD;kBAduB,SAAS;;;;;;eAAT,SAAS"}
|
package/build/web.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/* istanbul ignore file */
|
|
2
|
-
const LOG_METHODS = ['error', 'warn', 'info', 'debug', 'trace', 'silent'];
|
|
3
|
-
export default function getLogger(component) {
|
|
4
|
-
return LOG_METHODS.reduce((acc, cur) => {
|
|
5
|
-
const prop = cur;
|
|
6
|
-
// check if the method is available on console (web doesn't have
|
|
7
|
-
// 'silent', for example) before adding to acc
|
|
8
|
-
// eslint-disable-next-line no-console
|
|
9
|
-
if (console[prop]) {
|
|
10
|
-
// eslint-disable-next-line no-console
|
|
11
|
-
// @ts-ignore
|
|
12
|
-
acc[prop] = console[prop].bind(console, `${component}:`);
|
|
13
|
-
}
|
|
14
|
-
return acc;
|
|
15
|
-
}, {});
|
|
16
|
-
}
|
|
17
|
-
// logging interface expects a 'setLevel' method
|
|
18
|
-
getLogger.setLevel = () => { };
|
|
19
|
-
getLogger.setLogLevelsConfig = () => { };
|
|
20
|
-
getLogger.waitForBuffer = () => { };
|
|
21
|
-
getLogger.clearLogger = () => { };
|
/package/{LICENSE-MIT → LICENSE}
RENAMED
|
File without changes
|