Add Trace logging level; bump version
This commit is contained in:
parent
508d92f759
commit
ca348b2ff6
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@extollo/lib",
|
"name": "@extollo/lib",
|
||||||
"version": "0.9.9",
|
"version": "0.9.10",
|
||||||
"description": "The framework library that lifts up your code.",
|
"description": "The framework library that lifts up your code.",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"types": "lib/index.d.ts",
|
"types": "lib/index.d.ts",
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import {Logger, LoggingLevel, LogMessage} from '../util'
|
import {DebuggingTraceIsNotAnError, Logger, LoggingLevel, LogMessage} from '../util'
|
||||||
import {Singleton} from '../di'
|
import {Singleton} from '../di'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -109,6 +109,10 @@ export class Logging {
|
|||||||
this.writeLog(LoggingLevel.Verbose, output, force)
|
this.writeLog(LoggingLevel.Verbose, output, force)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public trace(output: unknown, force = false): void {
|
||||||
|
this.writeLog(LoggingLevel.Trace, output, force)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function to write the given output, at the given logging level, to
|
* Helper function to write the given output, at the given logging level, to
|
||||||
* all of the registered loggers.
|
* all of the registered loggers.
|
||||||
@ -119,10 +123,15 @@ export class Logging {
|
|||||||
*/
|
*/
|
||||||
protected writeLog(level: LoggingLevel, output: unknown, force = false): void {
|
protected writeLog(level: LoggingLevel, output: unknown, force = false): void {
|
||||||
const message = this.buildMessage(level, output)
|
const message = this.buildMessage(level, output)
|
||||||
|
const trace = DebuggingTraceIsNotAnError.getTrace()
|
||||||
|
const traceMessage = this.buildMessage(LoggingLevel.Trace, trace)
|
||||||
if ( this.currentLevel >= level || force ) {
|
if ( this.currentLevel >= level || force ) {
|
||||||
for ( const logger of this.registeredLoggers ) {
|
for ( const logger of this.registeredLoggers ) {
|
||||||
try {
|
try {
|
||||||
logger.write(message)
|
logger.write(message)
|
||||||
|
if ( this.currentLevel >= LoggingLevel.Trace ) {
|
||||||
|
logger.write(traceMessage)
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('logging error', e) // eslint-disable-line no-console
|
console.error('logging error', e) // eslint-disable-line no-console
|
||||||
}
|
}
|
||||||
|
@ -200,7 +200,6 @@ export class Bus<TEvent extends Event = Event> extends Unit implements EventBus<
|
|||||||
if ( Array.isArray(config.connectors) ) {
|
if ( Array.isArray(config.connectors) ) {
|
||||||
for ( const connector of (config.connectors as BusConnectorConfig[]) ) {
|
for ( const connector of (config.connectors as BusConnectorConfig[]) ) {
|
||||||
this.logging.verbose(`Creating bus connection of type: ${connector.type}`)
|
this.logging.verbose(`Creating bus connection of type: ${connector.type}`)
|
||||||
this.logging.verbose(new Error().stack)
|
|
||||||
if ( connector.type === 'redis' ) {
|
if ( connector.type === 'redis' ) {
|
||||||
await this.connect(this.make(RedisBus))
|
await this.connect(this.make(RedisBus))
|
||||||
}
|
}
|
||||||
|
15
src/util/error/DebuggingTraceIsNotAnError.ts
Normal file
15
src/util/error/DebuggingTraceIsNotAnError.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
/**
|
||||||
|
* Error class used to generate debug stack traces, not thrown.
|
||||||
|
*/
|
||||||
|
export class DebuggingTraceIsNotAnError extends Error {
|
||||||
|
static getTrace(): string {
|
||||||
|
const oldLimit = Error.stackTraceLimit
|
||||||
|
if ( oldLimit < 50 ) {
|
||||||
|
Error.stackTraceLimit = 50
|
||||||
|
}
|
||||||
|
|
||||||
|
const trace = (new this()).stack || String(new this())
|
||||||
|
Error.stackTraceLimit = oldLimit
|
||||||
|
return trace
|
||||||
|
}
|
||||||
|
}
|
@ -15,6 +15,7 @@ export * from './const/http'
|
|||||||
|
|
||||||
export * from './error/ErrorWithContext'
|
export * from './error/ErrorWithContext'
|
||||||
export * from './error/MethodNotSupportedError'
|
export * from './error/MethodNotSupportedError'
|
||||||
|
export * from './error/DebuggingTraceIsNotAnError'
|
||||||
|
|
||||||
export * from './logging/Logger'
|
export * from './logging/Logger'
|
||||||
export * from './logging/StandardLogger'
|
export * from './logging/StandardLogger'
|
||||||
|
@ -44,6 +44,8 @@ export abstract class Logger {
|
|||||||
return color.cyan(' debug')
|
return color.cyan(' debug')
|
||||||
case LoggingLevel.Verbose:
|
case LoggingLevel.Verbose:
|
||||||
return color.gray('verbose')
|
return color.gray('verbose')
|
||||||
|
case LoggingLevel.Trace:
|
||||||
|
return color.dim(' trace')
|
||||||
case LoggingLevel.Silent:
|
case LoggingLevel.Silent:
|
||||||
return color.gray(' silent')
|
return color.gray(' silent')
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ enum LoggingLevel {
|
|||||||
Info = 4,
|
Info = 4,
|
||||||
Debug = 5,
|
Debug = 5,
|
||||||
Verbose = 6,
|
Verbose = 6,
|
||||||
|
Trace = 7,
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user