Add config debugging helper
This commit is contained in:
parent
5f5b12a5be
commit
42d9cc101f
@ -1,17 +1,41 @@
|
||||
import {Singleton} from "@extollo/di";
|
||||
import {Singleton, Inject} from "@extollo/di";
|
||||
import {CanonicalRecursive} from "./CanonicalRecursive";
|
||||
import {Logging} from "./Logging";
|
||||
|
||||
@Singleton()
|
||||
export class Config extends CanonicalRecursive {
|
||||
@Inject()
|
||||
protected readonly logging!: Logging
|
||||
|
||||
protected appPath: string[] = ['configs']
|
||||
protected suffix: string = '.config.js'
|
||||
protected canonicalItem: string = 'config'
|
||||
protected recordConfigAccesses: boolean = false
|
||||
protected accessedKeys: string[] = []
|
||||
|
||||
public async up() {
|
||||
await super.up()
|
||||
|
||||
if ( this.get('server.debug', false) ) {
|
||||
Error.stackTraceLimit = Infinity
|
||||
this.recordConfigAccesses = true
|
||||
}
|
||||
}
|
||||
|
||||
public async down() {
|
||||
await super.down()
|
||||
|
||||
if ( this.recordConfigAccesses && this.accessedKeys.length ) {
|
||||
this.logging.debug(`The following configuration keys were accessed while this application was online:`)
|
||||
this.accessedKeys.forEach(key => this.logging.debug(` - ${key}`))
|
||||
}
|
||||
}
|
||||
|
||||
public get(key: string, fallback?: any): any {
|
||||
if ( this.recordConfigAccesses && !this.accessedKeys.includes(key) ) {
|
||||
this.accessedKeys.push(key)
|
||||
}
|
||||
|
||||
return super.get(key, fallback);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user