Skip to content

Loggable

Defined in: package/src/log.ts:117

Provides a lightweight, extensible logging mechanism with customizable formatting.

The Loggable class is designed to be extended and used for temporary logging purposes, avoiding the memory overhead of persistent logger instances. Each instance is created when needed and goes out of scope once used, improving performance.

(Class unmodified except for five original source functions).

Constructors

new Loggable()

new Loggable(): Loggable

Returns

Loggable

Methods

note()

note(header, ...messages): void

Defined in: package/src/log.ts:119

Logs the message to the console as a standard note.

Parameters

ParameterType

header

string

messages

string[]

Returns

void


trace()

trace(header, ...messages): void

Defined in: package/src/log.ts:124

Logs the message to the console with a debug level.

Parameters

ParameterType

header

string

messages

string[]

Returns

void


warn()

warn(header, ...messages): void

Defined in: package/src/log.ts:131

Logs the message to the console as a warning.

Parameters

ParameterType

header

string

messages

string[]

Returns

void


panic()

panic(header, ...messages): void

Defined in: package/src/log.ts:136

Logs the message to the console as an error.

Parameters

ParameterType

header

string

messages

string[]

Returns

void


format()

format(
header,
level,
codes, ...
message): string

Defined in: package/src/log.ts:150

Formats the log into a styled string suitable for console output.

The format includes the log header, timestamp, and a separator.

Modified to give the ansi codes of the background

Parameters

ParameterTypeDescription

header

string

level

string

codes

ANSICodes[]

Ansi codes for styling

message

string[]

Returns

string

A formatted log string


formatLines()

formatLines(lines): string

Defined in: package/src/log.ts:175

Formats the individual lines of the log with a consistent style.

Each line is prefixed with a vertical bar (|) for clarity.

Parameters

ParameterType

lines

string[]

Returns

string

A formatted string containing all log lines


toError()

toError(lines): Error

Defined in: package/src/log.ts:189

Converts the log entry into an Error object.

The resulting Error will contain the concatenated lines of the log as its message.

Parameters

ParameterType

lines

string[]

Returns

Error

An Error object representing the log entry