@xylabs/logger
v5.0.90
Published
XYLabs Logger Library
Readme
@xylabs/logger
XYLabs Logger Library
Reference
@xylabs/logger
Classes
| Class | Description |
| ------ | ------ |
| ConsoleLogger | A LevelLogger that delegates to the global console object. |
| IdLogger | A logger wrapper that prefixes every log message with a bracketed identifier. Useful for distinguishing log output from different components or instances. |
| LevelLogger | A logger that filters messages based on a configured log level. Methods for levels above the configured threshold return a no-op function. |
| SilentLogger | A logger that does not log anything. This is useful when you want to disable logging like when running unit tests or in silent mode. It implements the Logger interface but all methods are no-op functions. |
Interfaces
| Interface | Description |
| ------ | ------ |
| Logger | Interface to handle overlap between Winston & console with as much congruency as possible. |
Type Aliases
| Type Alias | Description | | ------ | ------ | | LogFunction | A generic logging function that accepts any number of arguments. | | LogLevelKey | String key for a log level (e.g. 'error', 'warn', 'info'). | | LogVerbosity | Alias for LogLevelKey, representing the verbosity setting as a string. | | LogLevelValue | Numeric value of a log level (1 through 6). |
Variables
| Variable | Description | | ------ | ------ | | LogLevel | Numeric log level values, from least verbose (error=1) to most verbose (trace=6). |
Functions
| Function | Description | | ------ | ------ | | NoOpLogFunction | A log function that silently discards all arguments. | | getFunctionName | Retrieves the name of the calling function by inspecting the stack trace. |
classes
ConsoleLogger
A LevelLogger that delegates to the global console object.
Extends
Constructors
Constructor
new ConsoleLogger(level?: LogLevelValue): ConsoleLogger;Parameters
| Parameter | Type | Default value |
| ------ | ------ | ------ |
| level | LogLevelValue | LogLevel.warn |
Returns
ConsoleLogger
Overrides
Properties
| Property | Modifier | Type | Inherited from |
| ------ | ------ | ------ | ------ |
| level | readonly | LogLevelValue | LevelLogger.level |
| logger | readonly | Logger | LevelLogger.logger |
Accessors
debug
Get Signature
get debug(): LogFunction;Returns
Inherited from
error
Get Signature
get error(): LogFunction;Returns
Inherited from
info
Get Signature
get info(): LogFunction;Returns
Inherited from
log
Get Signature
get log(): LogFunction;Returns
Inherited from
trace
Get Signature
get trace(): LogFunction;Returns
Inherited from
warn
Get Signature
get warn(): LogFunction;Returns
Inherited from
IdLogger
A logger wrapper that prefixes every log message with a bracketed identifier. Useful for distinguishing log output from different components or instances.
Implements
Constructors
Constructor
new IdLogger(logger: Logger, id?: () => string): IdLogger;Parameters
| Parameter | Type |
| ------ | ------ |
| logger | Logger |
| id? | () => string |
Returns
IdLogger
Accessors
id
Set Signature
set id(id: string): void;Parameters
| Parameter | Type |
| ------ | ------ |
| id | string |
Returns
void
Methods
debug()
debug(...data: unknown[]): void;Parameters
| Parameter | Type |
| ------ | ------ |
| ...data | unknown[] |
Returns
void
Implementation of
Logger.debugerror()
error(...data: unknown[]): void;Parameters
| Parameter | Type |
| ------ | ------ |
| ...data | unknown[] |
Returns
void
Implementation of
Logger.errorinfo()
info(...data: unknown[]): void;Parameters
| Parameter | Type |
| ------ | ------ |
| ...data | unknown[] |
Returns
void
Implementation of
Logger.infolog()
log(...data: unknown[]): void;Parameters
| Parameter | Type |
| ------ | ------ |
| ...data | unknown[] |
Returns
void
Implementation of
Logger.logtrace()
trace(...data: unknown[]): void;Parameters
| Parameter | Type |
| ------ | ------ |
| ...data | unknown[] |
Returns
void
Implementation of
Logger.tracewarn()
warn(...data: unknown[]): void;Parameters
| Parameter | Type |
| ------ | ------ |
| ...data | unknown[] |
Returns
void
Implementation of
Logger.warnLevelLogger
A logger that filters messages based on a configured log level. Methods for levels above the configured threshold return a no-op function.
Extended by
Implements
Constructors
Constructor
new LevelLogger(logger: Logger, level?: LogLevelValue): LevelLogger;Parameters
| Parameter | Type | Default value |
| ------ | ------ | ------ |
| logger | Logger | undefined |
| level | LogLevelValue | LogLevel.warn |
Returns
LevelLogger
Properties
| Property | Modifier | Type |
| ------ | ------ | ------ |
| level | readonly | LogLevelValue |
| logger | readonly | Logger |
Accessors
debug
Get Signature
get debug(): LogFunction;Returns
Implementation of
error
Get Signature
get error(): LogFunction;Returns
Implementation of
info
Get Signature
get info(): LogFunction;Returns
Implementation of
log
Get Signature
get log(): LogFunction;Returns
Implementation of
trace
Get Signature
get trace(): LogFunction;Returns
Implementation of
warn
Get Signature
get warn(): LogFunction;Returns
Implementation of
SilentLogger
A logger that does not log anything.
This is useful when you want to disable logging
like when running unit tests or in silent mode.
It implements the Logger interface but all methods
are no-op functions.
Implements
Constructors
Constructor
new SilentLogger(): SilentLogger;Returns
SilentLogger
Properties
| Property | Modifier | Type | Default value |
| ------ | ------ | ------ | ------ |
| debug | readonly | (..._data: unknown[]) => undefined | NoOpLogFunction |
| error | readonly | (..._data: unknown[]) => undefined | NoOpLogFunction |
| info | readonly | (..._data: unknown[]) => undefined | NoOpLogFunction |
| log | readonly | (..._data: unknown[]) => undefined | NoOpLogFunction |
| trace | readonly | (..._data: unknown[]) => undefined | NoOpLogFunction |
| warn | readonly | (..._data: unknown[]) => undefined | NoOpLogFunction |
functions
NoOpLogFunction
function NoOpLogFunction(..._data: unknown[]): undefined;A log function that silently discards all arguments.
Parameters
| Parameter | Type |
| ------ | ------ |
| ..._data | unknown[] |
Returns
undefined
getFunctionName
function getFunctionName(depth?: number): string;Retrieves the name of the calling function by inspecting the stack trace.
Parameters
| Parameter | Type | Default value | Description |
| ------ | ------ | ------ | ------ |
| depth | number | 2 | The stack frame depth to inspect (default: 2, the caller's caller). |
Returns
string
The function name, or '' if it cannot be determined.
interfaces
Logger
Interface to handle overlap between Winston &
console with as much congruency as possible.
Properties
| Property | Type |
| ------ | ------ |
| debug | LogFunction |
| error | LogFunction |
| info | LogFunction |
| log | LogFunction |
| trace | LogFunction |
| warn | LogFunction |
type-aliases
LogFunction
type LogFunction = (...data: unknown[]) => void;A generic logging function that accepts any number of arguments.
Parameters
| Parameter | Type |
| ------ | ------ |
| ...data | unknown[] |
Returns
void
LogLevelKey
type LogLevelKey = EnumKey<typeof LogLevel>;String key for a log level (e.g. 'error', 'warn', 'info').
LogLevelValue
type LogLevelValue = EnumValue<typeof LogLevel>;Numeric value of a log level (1 through 6).
LogVerbosity
type LogVerbosity = LogLevelKey;Alias for LogLevelKey, representing the verbosity setting as a string.
variables
LogLevel
const LogLevel: Enum<{
error: 1;
warn: 2;
info: 3;
log: 4;
debug: 5;
trace: 6;
}>;Numeric log level values, from least verbose (error=1) to most verbose (trace=6).
Part of sdk-js
Maintainers
License
See the LICENSE file for license details
