1.5.2 • Published 11 months ago

log-lv v1.5.2

Weekly downloads
318
License
MIT
Repository
github
Last release
11 months ago

Log LV

Log level for both client and server written in pure TypeScript

Usage

import { Logger } from "log-lv";
const loggerInstance = new Logger("debug", {
    prefix: () => new Date().toISOString(),
    suffix: () => "SUFFIX",
    leftSeparator: ">>>",
    rightSeparator: "<<<"
});
loggerInstance.debug("MY", "MESSAGE");

// Output:
// 2020-04-30T22:50:08.683Z >>> [DEBUG] MY MESSAGE <<< SUFFIX

Logger configuration

The first parameter is the initial log level. It can be changed also at runtime with the setLevel method.

TypeOptionsDefault Value
stringnone, error, warning, info, verbose, debuginfo

The second (optional) parameter to be passed to the Logger constructor has the following properties

PropertyTypeDescriptionDefault Value
prefix() => stringThe returned value of this function will be printed as prefix""
suffix() => stringThe returned value of this function will be printed as suffix""
leftSeparatorstringSeparator string between the prefix and the message. If prefix is not provided this value will be ignored""
leftSeparatorstringSeparator string between the message and the suffix. If suffix is not provided this value will be ignored""
beforeLogging(string[], string, number) => voidCallback function executed before logging to console. An array of string parts used for logging the message will be passed as argument""
leftSeparator(string[], string, number) => voidCallback function executed after logging to console. An array of string parts used for logging the message will be passed as argument""

API

MethodType DefinitionDescription
error(...args: any[]) => voidDisplay error message
warning(...args: any[]) => voidDisplay warning message
info(...args: any[]) => voidDisplay info message
verbose(...args: any[]) => voidDisplay verbose message
debug(...args: any[]) => voidDisplay debug message
setLevel(level: string) => voidChange log level
getLevel() => numberGet current log level
getLevelName() => LevelStringGet current log level name
disableLogging() => LoggerDisables logging
setLevelError() => LoggerSet log level to Error
setLevelWarning() => LoggerSet log level to Warning
setLevelInfo() => LoggerSet log level to Info
setLevelVerbose() => LoggerSet log level to Verbose
setLevelDebug() => LoggerSet log level to Debug
1.5.2

11 months ago

1.5.1

12 months ago

1.5.0

12 months ago

1.4.0

12 months ago

1.3.0

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago