Add Trace logging level; bump version

This commit is contained in:
Garrett Mills 2022-03-30 18:15:56 -05:00
parent 508d92f759
commit ca348b2ff6
7 changed files with 30 additions and 3 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@extollo/lib",
"version": "0.9.9",
"version": "0.9.10",
"description": "The framework library that lifts up your code.",
"main": "lib/index.js",
"types": "lib/index.d.ts",

View File

@ -1,4 +1,4 @@
import {Logger, LoggingLevel, LogMessage} from '../util'
import {DebuggingTraceIsNotAnError, Logger, LoggingLevel, LogMessage} from '../util'
import {Singleton} from '../di'
/**
@ -109,6 +109,10 @@ export class Logging {
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
* all of the registered loggers.
@ -119,10 +123,15 @@ export class Logging {
*/
protected writeLog(level: LoggingLevel, output: unknown, force = false): void {
const message = this.buildMessage(level, output)
const trace = DebuggingTraceIsNotAnError.getTrace()
const traceMessage = this.buildMessage(LoggingLevel.Trace, trace)
if ( this.currentLevel >= level || force ) {
for ( const logger of this.registeredLoggers ) {
try {
logger.write(message)
if ( this.currentLevel >= LoggingLevel.Trace ) {
logger.write(traceMessage)
}
} catch (e) {
console.error('logging error', e) // eslint-disable-line no-console
}

View File

@ -200,7 +200,6 @@ export class Bus<TEvent extends Event = Event> extends Unit implements EventBus<
if ( Array.isArray(config.connectors) ) {
for ( const connector of (config.connectors as BusConnectorConfig[]) ) {
this.logging.verbose(`Creating bus connection of type: ${connector.type}`)
this.logging.verbose(new Error().stack)
if ( connector.type === 'redis' ) {
await this.connect(this.make(RedisBus))
}

View 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
}
}

View File

@ -15,6 +15,7 @@ export * from './const/http'
export * from './error/ErrorWithContext'
export * from './error/MethodNotSupportedError'
export * from './error/DebuggingTraceIsNotAnError'
export * from './logging/Logger'
export * from './logging/StandardLogger'

View File

@ -44,6 +44,8 @@ export abstract class Logger {
return color.cyan(' debug')
case LoggingLevel.Verbose:
return color.gray('verbose')
case LoggingLevel.Trace:
return color.dim(' trace')
case LoggingLevel.Silent:
return color.gray(' silent')
}

View File

@ -9,6 +9,7 @@ enum LoggingLevel {
Info = 4,
Debug = 5,
Verbose = 6,
Trace = 7,
}
/**