Skip to content

Commit

Permalink
fix(Emit): Remove first two callers in stack trace.
Browse files Browse the repository at this point in the history
Closes #3
  • Loading branch information
nokome committed Jun 18, 2019
1 parent 8aa6731 commit 7d58f12
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ function emitLogData(info: LogInfo | string, tag: string, level: LogLevel) {
stack = info.stack
} else {
const error = new Error()
stack = error.stack
// Remove the first three lines of the stack trace which
// are not useful (see issue #3)
const lines = error.stack.split('\n')
stack = [lines[0], ...lines.slice(3)].join('\n')
}

const data: LogData = { tag, level, message, stack }
Expand Down
4 changes: 4 additions & 0 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ test('logga', () => {
expect(events[0].level).toBe(LogLevel.debug)
expect(events[0].message).toBe('a debug message')
expect(events[0].stack).toMatch(/^Error:/)
// Second line (first call stack) in stack trace should be this file
expect(events[0].stack.split('\n')[1]).toMatch(
/logga\/tests\/index\.test\.ts/
)

log.info({
message: 'a info message',
Expand Down

0 comments on commit 7d58f12

Please sign in to comment.