-
Notifications
You must be signed in to change notification settings - Fork 0
/
writer.go
63 lines (53 loc) · 2.66 KB
/
writer.go
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package cog
import (
"github.com/thehungry-dev/cog/handler"
"github.com/thehungry-dev/cog/level"
"github.com/thehungry-dev/cog/message"
"github.com/thehungry-dev/cog/message/field"
)
type Writer struct {
builder message.Builder
hndl handler.Handler
}
func With(hndl handler.Handler) Writer { return Writer{hndl: hndl} }
func (writer Writer) Tags(tags ...string) Writer {
writer.builder = writer.builder.Tags(tags...)
return writer
}
func (writer Writer) Data(fields ...field.Field) Writer {
writer.builder = writer.builder.Data(fields...)
return writer
}
func (writer Writer) Put(lvl level.Level, body string) {
writer.builder = writer.builder.Put(lvl, body)
msg := writer.builder.Message()
writer.hndl.Handle(msg)
}
func (writer Writer) Putf(lvl level.Level, format string, a ...interface{}) {
writer.builder = writer.builder.Putf(lvl, format, a...)
msg := writer.builder.Message()
writer.hndl.Handle(msg)
}
func (writer Writer) PutLevel(lvl level.Level) {
writer.builder = writer.builder.PutLevel(lvl)
msg := writer.builder.Message()
writer.hndl.Handle(msg)
}
func (writer Writer) Traced() { writer.PutLevel(level.Trace) }
func (writer Writer) Trace(body string) { writer.Put(level.Trace, body) }
func (writer Writer) Tracef(f string, a ...interface{}) { writer.Putf(level.Trace, f, a...) }
func (writer Writer) Debugd() { writer.PutLevel(level.Debug) }
func (writer Writer) Debug(body string) { writer.Put(level.Debug, body) }
func (writer Writer) Debugf(f string, a ...interface{}) { writer.Putf(level.Debug, f, a...) }
func (writer Writer) Infod() { writer.PutLevel(level.Info) }
func (writer Writer) Info(body string) { writer.Put(level.Info, body) }
func (writer Writer) Infof(f string, a ...interface{}) { writer.Putf(level.Info, f, a...) }
func (writer Writer) Warnd() { writer.PutLevel(level.Warn) }
func (writer Writer) Warn(body string) { writer.Put(level.Warn, body) }
func (writer Writer) Warnf(f string, a ...interface{}) { writer.Putf(level.Warn, f, a...) }
func (writer Writer) Errord() { writer.PutLevel(level.Error) }
func (writer Writer) Error(body string) { writer.Put(level.Error, body) }
func (writer Writer) Errorf(f string, a ...interface{}) { writer.Putf(level.Error, f, a...) }
func (writer Writer) Fatald() { writer.PutLevel(level.Fatal) }
func (writer Writer) Fatal(body string) { writer.Put(level.Fatal, body) }
func (writer Writer) Fatalf(f string, a ...interface{}) { writer.Putf(level.Fatal, f, a...) }