Log level for both client and server written in pure TypeScript
npm install log-lvLog level for both client and server written in pure TypeScript
``typescript
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
`
The first parameter is the initial log level. It can be changed also at runtime with the setLevel method.
| Type | Options | Default Value |
| ------ | ------------------------------------------------------ | ------------- |
| string | none, error, warning, info, verbose, debug | info |
The second (optional) parameter to be passed to the Logger constructor has the following properties
| Property | Type | Description | Default Value |
| ------------- | -------------- | --------------------------------------------------------------------------------------------------------- | ------------- |
| prefix | () => string | The returned value of this function will be printed as prefix | "" |() => string
| suffix | | The returned value of this function will be printed as suffix | "" |string
| leftSeparator | | Separator string between the prefix and the message. If prefix is not provided this value will be ignored | "" |string
| leftSeparator | | Separator string between the message and the suffix. If suffix is not provided this value will be ignored | "" |(string[], string, number) => void
| beforeLogging | | Callback function executed before logging to console. An array of string parts used for logging the message will be passed as argument| "" |(string[], string, number) => void
| leftSeparator | | Callback function executed after logging to console. An array of string parts used for logging the message will be passed as argument| "" |
| Method | Type Definition | Description |
| --------------- | -------------------------- | -------------------------- |
| error | (...args: any[]) => void | Display error message |(...args: any[]) => void
| warning | | Display warning message |(...args: any[]) => void
| info | | Display info message |(...args: any[]) => void
| verbose | | Display verbose message |(...args: any[]) => void
| debug | | Display debug message |(level: string) => void
| setLevel | | Change log level |() => number
| getLevel | | Get current log level |() => LevelString
| getLevelName | | Get current log level name |() => Logger
| disableLogging | | Disables logging |() => Logger
| setLevelError | | Set log level to Error |() => Logger
| setLevelWarning | | Set log level to Warning |() => Logger
| setLevelInfo | | Set log level to Info |() => Logger
| setLevelVerbose | | Set log level to Verbose |() => Logger` | Set log level to Debug |
| setLevelDebug |