@wdio/logger
TypeScript icon, indicating that this package has built-in type declarations

8.38.0 • Public • Published

WDIO Logger Utility

A helper utility for logging of WebdriverIO packages

This package is used across all WebdriverIO packages to log information using the loglevel package. It can also be used for any other arbitrary Node.js project.

Install

To install the package just call

npm install @wdio/logger

or when adding it to a WebdriverIO subpackage:

lerna add @wdio/logger --scope <subpackage>

Usage

The package exposes a logger function that you can use to register an instance for your scoped package:

import logger from '@wdio/logger'

const log = logger('myPackage')
log.info('some logs')

For more info see loglevel package on NPM.

Custom Log Levels

This package extends the log levels available in loglevel by introducing a new level called progress.

The progress level is particularly useful when you need to dynamically update a specific line in the terminal. For example, it can be utilized to display the download progress of browsers or drivers.

Notably, the progress level is equivalent to the info level. Therefore, if you set the log level to error or silent, any progress logs will be suppressed.

It's important to mention that progress writes directly to process.stdout, and these logs won't be captured in any log files.

To ensure consistent formatting with subsequent logs while using progress, it's essential to clear it at the end. To do so, simply call progress with an empty string, which will clear the last line:

log.progress('')

Illustrative Usage of Progress

import logger from '@wdio/logger';

const log = logger('internal');

const totalSize = 100;
let uploadedSize = 0;

const uploadInterval = setInterval(() => {
	const chunkSize = 10;
	uploadedSize += chunkSize;
	const data = `Progress: ${(uploadedSize * 100) / totalSize}%`;
	log.progress(data);
	if (uploadedSize >= totalSize) {
		clearInterval(uploadInterval);
		log.progress(''); // Called at the end to maintain the alignment of subsequent logs.
		console.log('Upload complete.');
	}
}, 100);

Package Sidebar

Install

npm i @wdio/logger

Weekly Downloads

2,236,200

Version

8.38.0

License

MIT

Unpacked Size

14.5 kB

Total Files

12

Last publish

Collaborators

  • christian-bromann
  • wdio-user
  • wswebcreation-nl