Skip to content

Commit 6bf7e32

Browse files
committed
Setting hard limit on message/TextPayload to 100000B
Because GCP has a hard limit on 100KB (102400B) and I use the remaining 2400B on the other fields like timestamp and so on.
1 parent b8f5e43 commit 6bf7e32

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ func init() {
2424
func main() {
2525
log.Info("Hello", "world")
2626
log.Infof("Hello %s", "world")
27-
log.Infoj(struct{ Hello string }{"world"})
27+
log.Infoj("label", struct{ Hello string }{"world"})
2828
}
2929
```

main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ const (
2323
emergency_severety severety = "EMERGENCY" // One or more systems are unusable.)
2424
)
2525

26+
const trunkateMessage = "[message over 100Kb, truncating]..."
27+
2628
type Logger struct{}
2729

2830
// StructuredLogger is used to have structured logging in stackdriver (Google Cloud Platform)
@@ -162,6 +164,11 @@ func (l *Logger) writeJson(severety severety, message string, obj interface{}) {
162164
return
163165
}
164166

167+
// GCP has max 102400 bytes limit, so setting 100k for message and 2.4k for other fields
168+
if len(message) > 100000 {
169+
message = message[0:100000-len(trunkateMessage)] + trunkateMessage
170+
}
171+
165172
payload := &stackdriverLogStruct{
166173
JsonPayload: obj,
167174
TextPayload: message,

0 commit comments

Comments
 (0)