tslog icon indicating copy to clipboard operation
tslog copied to clipboard

Feature Request: Replaying Log Objects

Open WorldMaker opened this issue 3 years ago • 0 comments

Description / Use Case for a Feature

Let's say that I store a bunch of LogObj to a file as (stringified) JSON. At some point I need a quick and dirty "log viewer" to take a few of those records and pretty print them to a Node or Browser console, and it would be useful if there was a method on Logger<T> that can take an already built LogObj and pretty print it with the metadata it already has.

Another good use case for this is displaying test logs only if the test failed. Using an example somewhat like the "Simple Attach Transport" from the documentation and Jest tests here:

	const logs: any[] = []
	const logger = new Logger({ type: 'hidden' })
	logger.attachTransport((logObj) => logs.push(logObj))
	const prettyLogger = new Logger({ type: 'pretty' })

	afterEach(function () {
		if (this.currentTest?.state === 'failed') {
			for (const log of logs) {
				prettyLogger.output(log) // <= this function does not currently exist
			}
		}
		// clear logs
		logs.length = 0
	})

As far as I can tell, it looks like the only way to do this today would be import from deep inside runtime folder internals and recreate portions of BaseLogger.

WorldMaker avatar Dec 14 '22 09:12 WorldMaker