Skip to content

Commit 7d58f12

Browse files
committed
fix(Emit): Remove first two callers in stack trace.
Closes #3
1 parent 8aa6731 commit 7d58f12

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ function emitLogData(info: LogInfo | string, tag: string, level: LogLevel) {
4848
stack = info.stack
4949
} else {
5050
const error = new Error()
51-
stack = error.stack
51+
// Remove the first three lines of the stack trace which
52+
// are not useful (see issue #3)
53+
const lines = error.stack.split('\n')
54+
stack = [lines[0], ...lines.slice(3)].join('\n')
5255
}
5356

5457
const data: LogData = { tag, level, message, stack }

tests/index.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ test('logga', () => {
2222
expect(events[0].level).toBe(LogLevel.debug)
2323
expect(events[0].message).toBe('a debug message')
2424
expect(events[0].stack).toMatch(/^Error:/)
25+
// Second line (first call stack) in stack trace should be this file
26+
expect(events[0].stack.split('\n')[1]).toMatch(
27+
/logga\/tests\/index\.test\.ts/
28+
)
2529

2630
log.info({
2731
message: 'a info message',

0 commit comments

Comments
 (0)