A helper utility for logging of WebdriverIO packages with enhanced features like progress logging and masking patterns for secure logging
—
Standard logging functionality with enhanced WebdriverIO-specific features including colorized output, prefixed messages, file logging support, and custom progress logging.
Creates or retrieves a logger instance for a specified component name. Each logger instance maintains its own configuration and state.
/**
* Creates or retrieves a logger instance for a specified component name
* @param name - The name/identifier for the logger (e.g., 'myPackage', 'webdriver:chrome')
* @returns Logger instance with all standard and custom logging methods
*/
function getLogger(name: string): Logger;Usage Examples:
import logger from '@wdio/logger';
// Create loggers for different components
const mainLog = logger('myApp');
const dbLog = logger('database');
const apiLog = logger('api');
// Each logger can have different settings
logger.setLevel('database', 'debug');
logger.setLevel('api', 'warn');Each logger instance provides all standard log levels plus the custom progress method.
interface Logger {
/**
* Log trace-level messages (level 0)
* @param args - Messages and objects to log
*/
trace(...args: any[]): void;
/**
* Log debug-level messages (level 1)
* @param args - Messages and objects to log
*/
debug(...args: any[]): void;
/**
* Log info-level messages (level 2)
* @param args - Messages and objects to log
*/
info(...args: any[]): void;
/**
* Log warning messages (level 3)
* @param args - Messages and objects to log
*/
warn(...args: any[]): void;
/**
* Log error messages (level 4)
* @param args - Messages and objects to log
*/
error(...args: any[]): void;
/**
* Custom progress logging for dynamic terminal updates
* Writes directly to process.stdout with cursor manipulation
* @param msg - Progress message strings
*/
progress(...msg: string[]): void;
/**
* Set the minimum log level for this logger instance
* @param level - Log level descriptor
*/
setLevel(level: LogLevelDesc): void;
/**
* Get the current log level number for this logger
* @returns Current log level as number (0-5)
*/
getLevel(): LogLevelNumbers;
/** Array of regex patterns for masking sensitive data in this logger's output */
maskingPatterns: RegExp[] | undefined;
}Usage Examples:
import logger from '@wdio/logger';
const log = logger('myService');
// Standard logging
log.trace('Detailed execution trace');
log.debug('Debug information');
log.info('General information');
log.warn('Warning message');
log.error('Error occurred', { errorCode: 500 });
// Progress logging for dynamic updates
const total = 100;
for (let i = 0; i <= total; i += 10) {
log.progress(`Downloading... ${i}%`);
await new Promise(resolve => setTimeout(resolve, 100));
}
log.progress(''); // Clear progress line
// Error object logging (automatically displays stack trace)
try {
throw new Error('Something went wrong');
} catch (error) {
log.error('Operation failed:', error);
}Special logging method for dynamic terminal updates, particularly useful for showing download progress, processing status, or other real-time information.
/**
* Special logging method for dynamic terminal updates
* Equivalent to info level but writes directly to stdout with cursor manipulation
* Only displays in TTY environments and when log level <= info
* @param data - Progress message strings
*/
progress(...data: string[]): void;Key Features:
process.stdout (not captured in log files)Usage Examples:
import logger from '@wdio/logger';
const log = logger('downloader');
// Show download progress
let downloaded = 0;
const total = 1000;
const interval = setInterval(() => {
downloaded += 100;
const percent = Math.round((downloaded / total) * 100);
log.progress(`Downloading driver... ${percent}%`);
if (downloaded >= total) {
clearInterval(interval);
log.progress(''); // Clear the progress line
log.info('Download complete!');
}
}, 200);
// Processing with dynamic updates
const items = ['file1.txt', 'file2.txt', 'file3.txt'];
for (let i = 0; i < items.length; i++) {
log.progress(`Processing ${items[i]} (${i + 1}/${items.length})`);
await processFile(items[i]);
}
log.progress(''); // Clear when done
log.info('All files processed');Control the minimum log level for individual logger instances.
/**
* Set log level for a specific logger instance
* @param name - Logger name/identifier
* @param level - Log level descriptor
*/
logger.setLevel(name: string, level: LogLevelDesc): void;Usage Examples:
import logger from '@wdio/logger';
// Set different levels for different components
logger.setLevel('database', 'debug'); // Show all database logs
logger.setLevel('api', 'warn'); // Only show API warnings and errors
logger.setLevel('verbose-module', 'silent'); // Suppress all logs
const dbLog = logger('database');
const apiLog = logger('api');
dbLog.debug('Database query executed'); // Will show (level is debug)
apiLog.debug('API request details'); // Won't show (level is warn)
apiLog.warn('API rate limit warning'); // Will showtype LogLevelDesc = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'silent';
type LogLevelNumbers = 0 | 1 | 2 | 3 | 4 | 5;Install with Tessl CLI
npx tessl i tessl/npm-wdio--logger