0
# @wdio/logger
1
2
@wdio/logger is a comprehensive logging utility specifically designed for WebdriverIO packages and Node.js applications. Built on top of the loglevel package, it extends standard logging capabilities with a custom 'progress' level for dynamic terminal updates, masking patterns for secure logging of sensitive information, and colorized output using chalk. The library offers scoped logger instances, supports both browser and Node.js environments through multiple export formats, and includes advanced features like regex-based masking patterns that can obfuscate credentials and secrets from logs.
3
4
## Package Information
5
6
- **Package Name**: @wdio/logger
7
- **Package Type**: npm
8
- **Language**: TypeScript/JavaScript
9
- **Installation**: `npm install @wdio/logger`
10
11
## Core Imports
12
13
```typescript
14
import logger from '@wdio/logger';
15
import { SENSITIVE_DATA_REPLACER, parseMaskingPatterns, mask } from '@wdio/logger';
16
import type { Logger } from '@wdio/logger';
17
```
18
19
For CommonJS:
20
21
```javascript
22
const logger = require('@wdio/logger');
23
const { SENSITIVE_DATA_REPLACER, parseMaskingPatterns, mask } = require('@wdio/logger');
24
```
25
26
## Basic Usage
27
28
```typescript
29
import logger from '@wdio/logger';
30
31
// Create a logger instance for your component
32
const log = logger('myPackage');
33
34
// Use standard log levels
35
log.info('Application started');
36
log.warn('This is a warning');
37
log.error('An error occurred');
38
39
// Use the special progress logging for dynamic updates
40
log.progress('Processing... 50%');
41
log.progress('Processing... 100%');
42
log.progress(''); // Clear the progress line
43
44
// Set log level for a specific logger
45
logger.setLevel('myPackage', 'debug');
46
47
// Configure masking patterns for sensitive data
48
logger.setMaskingPatterns('/--key=([^ ]*)/i,/--secret=([^ ]*)/i');
49
```
50
51
## Architecture
52
53
@wdio/logger is built around several key components:
54
55
- **Logger Factory**: Main `getLogger()` function that creates or retrieves logger instances
56
- **Environment Support**: Dual implementation for Node.js (full features) and browser (console adapter)
57
- **Masking System**: Regex-based pattern matching for obfuscating sensitive data in logs
58
- **Progress Logging**: Special log level for dynamic terminal updates with cursor manipulation
59
- **File Logging**: Optional file output with environment variable configuration
60
- **Log Level Management**: Per-logger and global log level configuration
61
62
## Capabilities
63
64
### Core Logging
65
66
Standard logging functionality with enhanced WebdriverIO-specific features including colorized output, prefixed messages, and file logging support.
67
68
```typescript { .api }
69
function getLogger(name: string): Logger;
70
71
interface Logger {
72
trace(...args: any[]): void;
73
debug(...args: any[]): void;
74
info(...args: any[]): void;
75
warn(...args: any[]): void;
76
error(...args: any[]): void;
77
progress(...msg: string[]): void;
78
setLevel(level: LogLevelDesc): void;
79
getLevel(): LogLevelNumbers;
80
maskingPatterns: RegExp[] | undefined;
81
}
82
```
83
84
[Core Logging](./core-logging.md)
85
86
### Configuration Management
87
88
Global configuration for log levels, masking patterns, and file output with support for per-logger customization.
89
90
```typescript { .api }
91
function setLogLevelsConfig(
92
logLevels?: Record<string, LogLevelDesc>,
93
wdioLogLevel?: LogLevelDesc
94
): void;
95
96
function setMaskingPatterns(
97
pattern: string | Record<string, string>
98
): void;
99
100
function setLevel(name: string, level: LogLevelDesc): void;
101
```
102
103
[Configuration Management](./configuration.md)
104
105
### Masking Utilities
106
107
Security-focused utilities for parsing masking patterns and applying masks to sensitive data in log messages.
108
109
```typescript { .api }
110
function parseMaskingPatterns(
111
maskingRegexString: string | undefined
112
): RegExp[] | undefined;
113
114
function mask(
115
text: string,
116
maskingPatterns: RegExp[] | undefined
117
): string;
118
119
const SENSITIVE_DATA_REPLACER: "**MASKED**";
120
```
121
122
[Masking Utilities](./masking.md)
123
124
### Browser Support
125
126
Browser-compatible logger implementation that adapts console methods for consistent API across environments.
127
128
```typescript { .api }
129
function getLogger(component: string): Console;
130
```
131
132
[Browser Support](./browser.md)
133
134
## Types
135
136
```typescript { .api }
137
type LogLevelDesc = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'silent';
138
type LogLevelNumbers = 0 | 1 | 2 | 3 | 4 | 5;
139
140
interface Logger {
141
trace(...args: any[]): void;
142
debug(...args: any[]): void;
143
info(...args: any[]): void;
144
warn(...args: any[]): void;
145
error(...args: any[]): void;
146
progress(...msg: string[]): void;
147
setLevel(level: LogLevelDesc): void;
148
getLevel(): LogLevelNumbers;
149
maskingPatterns: RegExp[] | undefined;
150
}
151
152
// Static methods available on the main logger function
153
interface LoggerFactory {
154
(name: string): Logger;
155
waitForBuffer(): Promise<void>;
156
setLevel(name: string, level: LogLevelDesc): void;
157
clearLogger(): void;
158
setLogLevelsConfig(logLevels?: Record<string, LogLevelDesc>, wdioLogLevel?: LogLevelDesc): void;
159
setMaskingPatterns(pattern: string | Record<string, string>): void;
160
}
161
```