Skip to content

Commit 5686559

Browse files
joeybloggsjoeybloggs
authored andcommitted
Add limit to the stack trace to ensure that handlers like hipchat don't exceed their max message size.
1 parent baceb2f commit 5686559

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## log
22
<img align="right" src="https://raw.githubusercontent.com/go-playground/log/master/logo.png">
3-
![Project status](https://img.shields.io/badge/version-3.1.0-green.svg)
3+
![Project status](https://img.shields.io/badge/version-3.1.1-green.svg)
44
[![Build Status](https://semaphoreci.com/api/v1/joeybloggs/log/branches/master/badge.svg)](https://semaphoreci.com/joeybloggs/log)
55
[![Coverage Status](https://coveralls.io/repos/github/go-playground/log/badge.svg?branch=master)](https://coveralls.io/github/go-playground/log?branch=master)
66
[![Go Report Card](https://goreportcard.com/badge/github.com/go-playground/log)](https://goreportcard.com/report/github.com/go-playground/log)

entry.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ func (e *Entry) WithFields(fields ...Field) LeveledLogger {
206206
func (e *Entry) StackTrace() LeveledLogger {
207207
trace := make([]byte, 1<<16)
208208
n := runtime.Stack(trace, true)
209+
if n > 7000 {
210+
n = 7000
211+
}
209212
e.Fields = append(e.Fields, F("stack trace", string(trace[:n])+"\n"))
210213
return e
211214
}

log.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ func (l *logger) WithFields(fields ...Field) LeveledLogger {
255255
func (l *logger) StackTrace() LeveledLogger {
256256
trace := make([]byte, 1<<16)
257257
n := runtime.Stack(trace, true)
258+
if n > 7000 {
259+
n = 7000
260+
}
258261
return newEntry(DebugLevel, "", []Field{F("stack trace", string(trace[:n])+"\n")}, skipLevel)
259262
}
260263

pkg.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ func WithFields(fields ...Field) LeveledLogger {
182182
func StackTrace() LeveledLogger {
183183
trace := make([]byte, 1<<16)
184184
n := runtime.Stack(trace, true)
185+
if n > 7000 {
186+
n = 7000
187+
}
185188
return newEntry(DebugLevel, "", []Field{F("stack trace", string(trace[:n])+"\n")}, skipLevel)
186189
}
187190

0 commit comments

Comments
 (0)