Skip to content

Logger API

createLogger Logging

Creates an independent logger.

Signature

ts
export function createLogger(options: LoggerOptions = {}): Logger;

Example

ts
import { createLogger } from "@fast-china/utils";

const result = createLogger({ brand: "Admin", minimumLevel: "warn" });

Input

InputTypeRequired / defaultDescription
optionsLoggerOptionsOptional; defaults to {}Level, prefix, sink, and uni-app App-Plus argument-splitting options.

Returns

ValueTypeDescription
resultLoggerNew instance that does not modify the global console or other loggers.

configureLogger Logging

Replaces the default logger's entire configuration.

Signature

ts
export function configureLogger(options: LoggerOptions = {}): void;

Example

ts
import { configureLogger } from "@fast-china/utils";

configureLogger({ brand: "Admin", minimumLevel: "warn" });

Input

InputTypeRequired / defaultDescription
optionsLoggerOptionsOptional; defaults to {}Level, prefix, sink, and uni-app App-Plus argument-splitting options for the default logger.

Returns

ValueTypeDescription
resultvoidNo return value.

logger.debug / logger.log / logger.warn / logger.error Logging

Writes a scoped log to the current sink at the specified level. All four methods share the same input and void return contract.

Signature

ts
debug(scope: string, ...content: unknown[]): void;
log(scope: string, ...content: unknown[]): void;
warn(scope: string, ...content: unknown[]): void;
error(scope: string, ...content: unknown[]): void;

Example

ts
import { logger } from "@fast-china/utils";

logger.debug("startup", "initializing");
logger.log("api", "request completed", { status: 200 });
logger.warn("cache", "entry expired");
logger.error("api", "request failed", new Error("network"));

Input

InputTypeRequired / defaultDescription
scopestringRequiredNonempty module, component, or business-source name with no surrounding whitespace.
...contentunknown[]Optional; multiple arguments allowedMessage and additional values; nonstrings preserve their original types.

Returns

ValueTypeDescription
resultvoidNo return value; messages below the minimum level are not written.