documentation
documentation copied to clipboard
[ Documentation request ] [Typo] Observability Testing with DefaultLogger unclear
Brief description
There is a typo on the Observability Typescript Guide ➡️
import { DefaultLogger, LogEntry } from '@temporalio/worker';
const logs: LogEntry[] = [];
const logger = new DefaultLogger('TRACE', (entry) => logs.push(entry));
log.debug('hey', { a: 1 });
log.info('ho');
log.warn('lets', { a: 1 });
log.error('go');
The code doesn't make sense as it is written. I think the intent was that the log
object referenced should be logger
. If it's not a typo, it isn't clear to me what the 'log' object is and it's relationship to logs
and logger
.
The context of this was for a section "Accumulate logs for testing and reporting" but, the code above doesn't show how it can be used in a test.
A testing question I think would be useful answered in the documentation is:
- How could you iterate through the
<LogEntry>
objects inlogs
to assert/expect an outcome?
- How do you access the
LEVEL
in a<LogEntry>
object? - How do you access the metadata object in a
<LogEntry>
object?Example:
log.debug('hey', { a: 1, foo: 'bar' })
➡️{ a: 1, foo: 'bar' }
Your recommended content
I'd be more than happy to fix the typo above and look up <LogEntry> so that a more useful code snippet for testing Observability can be made.