Skip to content

Commit 98eb993

Browse files
joeybloggsjoeybloggs
authored andcommitted
expanded on pull request 7 by @sm3142 and made same changes to all handlers.
1 parent f936955 commit 98eb993

File tree

6 files changed

+31
-5
lines changed

6 files changed

+31
-5
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-4.0.0-green.svg)
3+
![Project status](https://img.shields.io/badge/version-4.0.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)

handlers/console/console.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
stdlog "log"
88
"os"
99
"strconv"
10+
"strings"
1011

1112
"github.com/go-playground/log"
1213
)
@@ -358,7 +359,12 @@ func defaultFormatFunc(c *Console) Formatter {
358359
}
359360
}
360361
} else {
361-
file = file[len(gopath):]
362+
363+
// additional check, just in case user does
364+
// have a $GOPATH but code isnt under it.
365+
if strings.HasPrefix(file, gopath) {
366+
file = file[len(gopath):]
367+
}
362368
}
363369

364370
b = append(b, e.Timestamp.Format(tsFormat)...)

handlers/email/email.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"html/template"
66
stdlog "log"
77
"os"
8+
"strings"
89
"sync"
910
"time"
1011

@@ -171,7 +172,12 @@ func (email *Email) Run() chan<- *log.Entry {
171172
}
172173
}
173174
} else {
174-
file = file[len(email.gopath):]
175+
176+
// additional check, just in case user does
177+
// have a $GOPATH but code isnt under it.
178+
if strings.HasPrefix(file, email.gopath) {
179+
file = file[len(email.gopath):]
180+
}
175181
}
176182

177183
return

handlers/http/hipchat/hipchat.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,12 @@ func (hc *HipChat) Run() chan<- *log.Entry {
209209
}
210210
}
211211
} else {
212-
file = file[len(hc.GOPATH()):]
212+
213+
// additional check, just in case user does
214+
// have a $GOPATH but code isnt under it.
215+
if strings.HasPrefix(file, hc.GOPATH()) {
216+
file = file[len(hc.GOPATH()):]
217+
}
213218
}
214219

215220
return

handlers/http/http.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"net/url"
1010
"os"
1111
"strconv"
12+
"strings"
1213

1314
"github.com/go-playground/log"
1415
)
@@ -221,7 +222,12 @@ func defaultFormatFunc(h HTTP) Formatter {
221222
}
222223
}
223224
} else {
224-
file = file[len(gopath):]
225+
226+
// additional check, just in case user does
227+
// have a $GOPATH but code isnt under it.
228+
if strings.HasPrefix(file, gopath) {
229+
file = file[len(gopath):]
230+
}
225231
}
226232

227233
b = append(b, e.Timestamp.Format(tsFormat)...)

handlers/syslog/syslog.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,9 @@ func defaultFormatFunc(s *Syslog) Formatter {
350350
}
351351
}
352352
} else {
353+
354+
// additional check, just in case user does
355+
// have a $GOPATH but code isnt under it.
353356
if strings.HasPrefix(file, gopath) {
354357
file = file[len(gopath):]
355358
}

0 commit comments

Comments
 (0)