Skip to main content

Logger.error() method

Log an error message, if the log level is error or higher.

Signature​

error(message?: unknown, ...args: unknown[]): void;

Parameters​

Parameter

Type

Description

message

unknown

(Optional) Message to log, as accepted by util.format() (see Empty messages in the description of the class).

args

unknown[]

The variable arguments.

Returns​

void

Remarks​

The message is prefixed with error: and passed via console.error(). If the logger was created with the timestamp option, it starts with a timestamp, and the prefix is replaced by [error], also for an Error that comes first (see below).

The prefix of an Error. Only error() omits its prefix, and only when the first argument is an Error: the first line of the expanded error already starts with its name (like Error: boom), which tells the severity. This is deliberate. The other methods keep their prefix, and an Error that is not the first argument of error() keeps the prefix too (error: failed: Error: boom).

To show only the message, on a single line, pass err.message instead of the object; see the section "Logging errors" of the User's Guide.

Example​

log.error('Not good...')

Generated via tsdoc2docusaurus 1.3.2 by API Extractor/Documenter 7.60.1.