-
-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathlogger.js
103 lines (80 loc) · 1.91 KB
/
logger.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
* Module dependencies.
*/
import { format } from 'node:util';
import ora from 'ora';
// Map Playwright log levels to custom logger levels.
const PLAYWRIGHT_LOG_LEVELS = {
error: 'error',
info: 'info',
verbose: 'debug',
warning: 'warn'
};
const ORA_LOG_LEVELS = {
info: 'info',
warn: 'warn',
debug: 'info',
error: 'fail',
succeed: 'succeed'
}
export { PLAYWRIGHT_LOG_LEVELS };
/**
* Logger with support for TTY detection.
*/
export class Logger {
constructor(verbosity, isTTY, stream) {
this.verbosity = verbosity;
this.isTTY = isTTY;
this.ora = ora({ isEnabled: this.isTTY });
this.stream = stream;
}
log(level, ...args) {
if (!this.isTTY) {
this.stream.write(`${new Date().toISOString()} ${level.toUpperCase()} gsts: ${format(...args)}`);
return;
}
return this.ora[ORA_LOG_LEVELS[level]](format(...args));
}
start(...args) {
if (!this.isTTY) {
return;
}
return this.ora.start(...args);
}
stop(...args) {
if (!this.isTTY) {
return;
}
return this.ora.stop(...args);
}
debug(...args) {
// For security reasons, do not log debug messages which can contain credentials secrets
// when in non-interactive mode, since other third-party tools could capture this content
// as part of their error processing logic.
if (!this.isTTY) {
return;
}
if (this.verbosity < 2) {
return;
}
return this.log('debug', ...args);
}
info(...args) {
if (this.verbosity < 1) {
return;
}
return this.log('info', ...args);
}
warn(...args) {
return this.log('warn', ...args);
}
error(...args) {
return this.log('error', ...args);
}
succeed(...args) {
if (!this.isTTY) {
return;
}
return this.log('succeed', ...args);
}
}