-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy patherror_logger_impl.go
More file actions
42 lines (35 loc) · 955 Bytes
/
error_logger_impl.go
File metadata and controls
42 lines (35 loc) · 955 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package assert
import (
"fmt"
"io"
"os"
)
type location struct {
Test string
FileName string
Line int
}
type errorLogger interface {
Log(location *location, message string)
}
var theLogger errorLogger = &errorLoggerImpl{writer: os.Stdout}
type errorLoggerImpl struct {
writer io.Writer
prevTestName string
prevTestLine int
}
const (
formatHeaderFull = "\n--- FAIL: %s\n\t%s:%d\n"
formatHeaderShort = "\t%s:%d\n"
formatMessage = "\t\t%s\n"
)
func (logger *errorLoggerImpl) Log(location *location, message string) {
if logger.prevTestName != location.Test {
fmt.Fprintf(logger.writer, formatHeaderFull, location.Test, location.FileName, location.Line)
} else if logger.prevTestLine != location.Line {
fmt.Fprintf(logger.writer, formatHeaderShort, location.FileName, location.Line)
}
fmt.Fprintf(logger.writer, formatMessage, message)
logger.prevTestName = location.Test
logger.prevTestLine = location.Line
}