Skip to content

API reference / @jsprismarine/logger

@jsprismarine/logger ​

Join the Discord Servernpm

Leveled logger with a console transport that buffers boot output until a console attaches, plus a plain-text file transport.

Call logger.isEnabled(level) before formatting an expensive message. It reports whether that level will be written, so hot paths can skip both the message and its arguments when the logger would suppress them.

Classes ​

Interfaces ​

LogRecord ​

Defined in: transport.ts:15

One log record as handed to transports: the raw parts plus the line the logger already formatted for terminal output.

Properties ​

formatted ​

formatted: string

Defined in: transport.ts:22

The colorized console line.

level ​

level: "error" | "warn" | "info" | "verbose" | "debug" | "silly"

Defined in: transport.ts:16

message ​

message: string

Defined in: transport.ts:17

namespace ​

namespace: string

Defined in: transport.ts:18

timestamp ​

timestamp: string

Defined in: transport.ts:20

Wall-clock time as HH:mm:ss.


LogTransport ​

Defined in: transport.ts:26

A destination for log records.

Methods ​

close()? ​

optional close(): void

Defined in: transport.ts:28

Returns ​

void

log() ​

log(record): void

Defined in: transport.ts:27

Parameters ​
record ​

LogRecord

Returns ​

void


PrismarineTransportOptions ​

Defined in: transport.ts:32

Options for PrismarineTransport.

Properties ​

capacity? ​

optional capacity?: number

Defined in: transport.ts:37

Most records kept for replay while no console is attached; defaults to 1000. When the buffer is full, the oldest record is dropped first.

Type Aliases ​

ConsoleLike ​

ConsoleLike = object

Defined in: transport.ts:7

The part of a console the transport needs: a sink for one formatted line.

Properties ​

write ​

write: (input) => void

Defined in: transport.ts:8

Parameters ​
input ​

string

Returns ​

void


LogLevel ​

LogLevel = typeof LOG_LEVELS[number]

Defined in: levels.ts:12

A log level.

Variables ​

LOG_LEVELS ​

const LOG_LEVELS: readonly ["error", "warn", "info", "verbose", "debug", "silly"]

Defined in: levels.ts:5

Every log level, most severe first. The position is the order a threshold applies: a logger or transport set to info emits error, warn, and info and skips the rest.

Functions ​

isAtLeastLevel() ​

isAtLeastLevel(level, threshold): boolean

Defined in: levels.ts:26

Whether level is at least as severe as threshold, so a logger or transport set to threshold emits a record at level. A level passes its own threshold.

Parameters ​

level ​

"error" | "warn" | "info" | "verbose" | "debug" | "silly"

threshold ​

"error" | "warn" | "info" | "verbose" | "debug" | "silly"

Returns ​

boolean


isLogLevel() ​

isLogLevel(value): value is "error" | "warn" | "info" | "verbose" | "debug" | "silly"

Defined in: levels.ts:18

Whether a value from a config file or a decoded message names one of LOG_LEVELS. Matching is exact; INFO is not a level.

Parameters ​

value ​

unknown

Returns ​

value is "error" | "warn" | "info" | "verbose" | "debug" | "silly"


terminalText() ​

terminalText(text): string

Defined in: terminalText.ts:30

Makes text that came from the network safe to print to a terminal or a line-oriented log. Removes escape sequences, which could move the cursor, clear the screen, retitle the window or write a hyperlink, and the control characters, such as carriage return and backspace, that could overwrite earlier output.

Use it on untrusted text, at the point it is printed; the caller's own formatting is written around it. The logger applies it to every message.

Parameters ​

text ​

string

Untrusted text, such as a chat line, a MOTD or a player name.

Returns ​

string

The text without escape sequences or control characters other than tab and line feed.