Skip to content

LogScriptHelper

This file defines the LogScriptHelper class, which provides helper methods for sending various types of log messages from scripts. It abstracts the logging mechanism by sending commands with log types and messages through a provided send function.


Features

  • Log Levels: Supports logging at different levels: info, error, success, message, step, warning, and warn.
  • Command-based Logging: Sends log messages using a command pattern, allowing integration with custom logging or IPC systems.

Usage

typescript
const logger = new LogScriptHelper((command, context) => {
	// Custom send implementation
	console.log(command, context);
});

logger.info('This is an info message');
logger.error('This is an error message');
logger.success('Operation was successful');
logger.message('A generic message');
logger.step('Step 1 completed');
logger.warning('This is a warning');
logger.warn('This is also a warning');

API

Constructor

typescript
constructor(
	private send: (command: string, context?: Record<string, any>) => void,
)
  • send: A function that handles sending the log command and context.

Methods

info(message: string): void

Sends an info-level log message.

error(message: string): void

Sends an error-level log message.

success(message: string): void

Sends a success-level log message.

message(message: string): void

Sends a generic log message.

step(message: string): void

Sends a step-level log message.

warning(message: string): void

Sends a warning-level log message.

warn(message: string): void

Sends a warning-level log message (alias for warning).


Notes

  • The send function should handle the actual delivery or processing of the log messages, such as forwarding them to a logger, UI, or IPC channel.
  • All log messages are sent with the command _:log and a context object containing the type and message.

Released under the Apache-2.0 License.