Class: Logger#

Constructors#

constructor#

+ new Logger(options?: LoggerConstructorOptions): Logger

Creates a new Logger instance

example

const logger = new Logger({ logsPath: __dirname + "/logs.json" });

Parameters:#

NameType
options?LoggerConstructorOptions

Returns: Logger

Defined in: index.ts:165

Properties#

COLORS#

â–ª Readonly Static COLORS: object

ANSI Escape Sequences

example

console.log(Logger.COLORS.Dim + "Dim log" + Logger.COLORS.Reset);

Type declaration:#

NameType
BgBlackstring
BgBluestring
BgCyanstring
BgGreenstring
BgMagentastring
BgRedstring
BgWhitestring
BgYellowstring
Blinkstring
Brightstring
Dimstring
FgBlackstring
FgBluestring
FgCyanstring
FgGreenstring
FgMagentastring
FgRedstring
FgWhitestring
FgYellowstring
Hiddenstring
Resetstring
Reversestring
Underscorestring

Defined in: index.ts:152

Accessors#

logs#

• get logs(): Log[]

All logs that have been output by this Logger instance

example

const logs = logger.logs;

Returns: Log[]

Defined in: index.ts:191


logsPath#

• get logsPath(): undefined | string

The output file path

example

const logsPath = logger.logsPath;

Returns: undefined | string

Defined in: index.ts:204

• set logsPath(logsPath: undefined | string): void

The output file path

example

logger.logsPath = __dirname + "/logs.json";

Parameters:#

NameType
logsPathundefined | string

Returns: void

Defined in: index.ts:217

Methods#

error#

â–¸ error(message: unknown): Promise<Log>

Logs a success message to the console and writes to the output file path

example

await logger.error("Hello");

example

await logger.error(2);

example

await logger.error(["hi!", 4, ["nested string"]]);

Parameters:#

NameTypeDescription
messageunknownThe error message to log

Returns: Promise<Log>

Defined in: index.ts:556

â–¸ error(message: unknown, logOptions: Pick<LogOptionsWithoutWrite, writeToFile>): Log

Logs an error message to the console and DOES NOT write to the output file path

example

await logger.error("Hello", {
writeToFile: false,
});

Parameters:#

NameTypeDescription
messageunknownThe error message to log
logOptionsPick<LogOptionsWithoutWrite, writeToFile>Logging options

Returns: Log

Defined in: index.ts:570

â–¸ error(message: unknown, logOptions: Pick<LogOptionsWithWrite, writeToFile | extra>): Promise<Log>

Logs an error message to the console and writes to the output file path

example

await logger.error("Hello", {
writeToFile: true,
});

example

await logger.error(32, {
extra: "this part is not logged"
});

Parameters:#

NameTypeDescription
messageunknownThe error message to log
logOptionsPick<LogOptionsWithWrite, writeToFile | extra>Logging options

Returns: Promise<Log>

Defined in: index.ts:593


info#

â–¸ info(message: unknown): Promise<Log>

Logs a success message to the console and writes to the output file path

example

await logger.info("Hello");

example

await logger.info(2);

example

await logger.info(["hi!", 4, ["nested string"]]);

Parameters:#

NameTypeDescription
messageunknownThe info message to log

Returns: Promise<Log>

Defined in: index.ts:410

â–¸ info(message: unknown, logOptions: Pick<LogOptionsWithoutWrite, writeToFile>): Log

Logs an info message to the console and DOES NOT write to the output file path

example

await logger.info("Hello", {
writeToFile: false,
});

Parameters:#

NameTypeDescription
messageunknownThe info message to log
logOptionsPick<LogOptionsWithoutWrite, writeToFile>Logging options

Returns: Log

Defined in: index.ts:424

â–¸ info(message: unknown, logOptions: Pick<LogOptionsWithWrite, writeToFile | extra>): Promise<Log>

Logs an info message to the console and writes to the output file path

example

await logger.info("Hello", {
writeToFile: true,
});

example

await logger.info(32, {
extra: "this part is not logged"
});

Parameters:#

NameTypeDescription
messageunknownThe info message to log
logOptionsPick<LogOptionsWithWrite, writeToFile | extra>Logging options

Returns: Promise<Log>

Defined in: index.ts:447


log#

â–¸ log(message: unknown): Promise<Log>

Logs a message to the console and writes to the output file path

example

await logger.log("Hello");

example

await logger.log(2);

example

await logger.log(["hi!", 4, ["nested string"]]);

Parameters:#

NameTypeDescription
messageunknownThe message to log

Returns: Promise<Log>

Defined in: index.ts:239

â–¸ log(message: unknown, logOptions: LogOptionsWithoutWrite): Log

Logs a message to the console and DOES NOT write to the output file path

example

await logger.log(31, {
writeToFile: false,
});

example

await logger.log("Hello", {
writeToFile: false,
type: "error",
});

Parameters:#

NameTypeDescription
messageunknownThe message to log
logOptionsLogOptionsWithoutWriteLogging options

Returns: Log

Defined in: index.ts:260

â–¸ log(message: unknown, logOptions: LogOptionsWithWrite): Promise<Log>

Logs a message to the console and writes to the output file path

example

await logger.log("Hello", {
writeToFile: true,
});

example

await logger.log(["hi", "hello"], {
writeToFile: true,
type: "success",
});

example

await logger.log(32, {
type: "info",
extra: "this part is not logged"
});

Parameters:#

NameTypeDescription
messageunknownThe message to log
logOptionsLogOptionsWithWriteLogging options

Returns: Promise<Log>

Defined in: index.ts:288


success#

â–¸ success(message: unknown): Promise<Log>

Logs a success message to the console and writes to the output file path

example

await logger.success("Hello");

example

await logger.success(2);

example

await logger.success(["hi!", 4, ["nested string"]]);

Parameters:#

NameTypeDescription
messageunknownThe success message to log

Returns: Promise<Log>

Defined in: index.ts:337

â–¸ success(message: unknown, logOptions: Pick<LogOptionsWithoutWrite, writeToFile>): Log

Logs a success message to the console and DOES NOT write to the output file path

example

await logger.success("Hello", {
writeToFile: false,
});

Parameters:#

NameTypeDescription
messageunknownThe success message to log
logOptionsPick<LogOptionsWithoutWrite, writeToFile>Logging options

Returns: Log

Defined in: index.ts:351

â–¸ success(message: unknown, logOptions: Pick<LogOptionsWithWrite, writeToFile | extra>): Promise<Log>

Logs a success message to the console and writes to the output file path

example

await logger.success("Hello", {
writeToFile: true,
});

example

await logger.success(32, {
extra: "this part is not logged"
});

Parameters:#

NameTypeDescription
messageunknownThe success message to log
logOptionsPick<LogOptionsWithWrite, writeToFile | extra>Logging options

Returns: Promise<Log>

Defined in: index.ts:374


warn#

â–¸ warn(message: unknown): Promise<Log>

Logs a success message to the console and writes to the output file path

example

await logger.warn("Hello");

example

await logger.warn(2);

example

await logger.warn(["hi!", 4, ["nested string"]]);

Parameters:#

NameTypeDescription
messageunknownThe warn message to log

Returns: Promise<Log>

Defined in: index.ts:483

â–¸ warn(message: unknown, logOptions: Pick<LogOptionsWithoutWrite, writeToFile>): Log

Logs a warning message to the console and DOES NOT write to the output file path

example

await logger.warn("Hello", {
writeToFile: false,
});

Parameters:#

NameTypeDescription
messageunknownThe warning message to log
logOptionsPick<LogOptionsWithoutWrite, writeToFile>Logging options

Returns: Log

Defined in: index.ts:497

â–¸ warn(message: unknown, logOptions: Pick<LogOptionsWithWrite, writeToFile | extra>): Promise<Log>

Logs a warning message to the console and writes to the output file path

example

await logger.warn("Hello", {
writeToFile: true,
});

example

await logger.warn(32, {
extra: "this part is not logged"
});

Parameters:#

NameTypeDescription
messageunknownThe warning message to log
logOptionsPick<LogOptionsWithWrite, writeToFile | extra>Logging options

Returns: Promise<Log>

Defined in: index.ts:520


writeLogs#

â–¸ writeLogs(): Promise<void>

Writes the logs stored in this.logs to the output file

example

await logger.writeLogs();

Returns: Promise<void>

Defined in: index.ts:620


bold#

â–¸ Staticbold(message: unknown, afterColored?: string): void

Logs a bold message

example

Logger.bold("BOLD!");

example

Logger.bold("BOLD!", "this part is not bold");

Parameters:#

NameTypeDefault valueDescription
messageunknown-The bold message to log
afterColoredstring""The optional message after the bold message (on the same line)

Returns: void

Defined in: index.ts:705


coloredLog#

â–¸ StaticcoloredLog(color: Reset | Bright | Dim | Underscore | Blink | Reverse | Hidden | FgBlack | FgRed | FgGreen | FgYellow | FgBlue | FgMagenta | FgCyan | FgWhite | BgBlack | BgRed | BgGreen | BgYellow | BgBlue | BgMagenta | BgCyan | BgWhite, message: unknown, afterColored?: string, consoleLevel?: log | warn | error): void

Logs a colored message to the console

example

Logger.coloredLog("BgBlue", "hi");

example

Logger.coloredLog("FgYellow", "hi", "this string will not be colored");

example

Logger.coloredLog("FgRed", "error!!!", "not colored", "error");

Parameters:#

NameTypeDefault valueDescription
colorReset | Bright | Dim | Underscore | Blink | Reverse | Hidden | FgBlack | FgRed | FgGreen | FgYellow | FgBlue | FgMagenta | FgCyan | FgWhite | BgBlack | BgRed | BgGreen | BgYellow | BgBlue | BgMagenta | BgCyan | BgWhite-The color to log in
messageunknown-The message to log
afterColoredstring""The optional message after the colored message (on the same line)
consoleLevellog | warn | error"log"The console level to use (log, warn, or error)

Returns: void

Defined in: index.ts:679


error#

â–¸ Staticerror(message: unknown, afterColored?: string): void

Logs an error message in red

example

Logger.error("ERROR!");

example

Logger.error("ERROR!", "this part is not red");

Parameters:#

NameTypeDefault valueDescription
messageunknown-The error message to log
afterColoredstring""The optional message after the error message (on the same line)

Returns: void

Defined in: index.ts:781


info#

â–¸ Staticinfo(message: unknown, afterColored?: string): void

Logs an info message in blue

example

Logger.info("information...");

example

Logger.info("information...", "this part is not blue");

Parameters:#

NameTypeDefault valueDescription
messageunknown-The info message to log
afterColoredstring""The optional message after the info message (on the same line)

Returns: void

Defined in: index.ts:743


line#

â–¸ Staticline(): void

Logs an empty line to the console

example

Logger.line();

Returns: void

Defined in: index.ts:654


log#

â–¸ Staticlog(message?: unknown, ...optionalParams: any[]): void

Logs to the console

example

Logger.log("hi");

example

Logger.log("hi %s", "Bill");

Parameters:#

NameTypeDescription
message?unknownThe message to log
...optionalParamsany[]Substitution strings

Returns: void

Defined in: index.ts:641


success#

â–¸ Staticsuccess(message: unknown, afterColored?: string): void

Logs a success message in green

example

Logger.success("SUCCESS!");

example

Logger.success("SUCCESS!", "this part is not green");

Parameters:#

NameTypeDefault valueDescription
messageunknown-The success message to log
afterColoredstring""The optional message after the success message (on the same line)

Returns: void

Defined in: index.ts:724


warn#

â–¸ Staticwarn(message: unknown, afterColored?: string): void

Logs a warning message in yellow

example

Logger.warn("WARNING!");

example

Logger.warn("WARNING!", "this part is not yellow");

Parameters:#

NameTypeDefault valueDescription
messageunknown-The warning message to log
afterColoredstring""The optional message after the warning message (on the same line)

Returns: void

Defined in: index.ts:762