-
Notifications
You must be signed in to change notification settings - Fork 0
/
writer.go
60 lines (52 loc) · 1.7 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
package golog
import (
"context"
"time"
)
// Writer implementations write log messages
// in a certain message format to some underlying
// data stream.
// CommitMessage must be called before the Writer
// can be re-used for a new message.
type Writer interface {
// BeginMessage clones the Writer with its configuration for
// writing a new message that must be finished with CommitMessage.
// This method is only called for log levels that are active at the logger,
// so implementations don't have to check the passed logger to decide
// if they should log the passed level.
// The logger is passed to give access to other data that might be needed
// for message formatting like the prefix or level names.
BeginMessage(ctx context.Context, logger *Logger, t time.Time, level Level, text string) Writer
WriteKey(string)
WriteSliceKey(string)
WriteSliceEnd()
WriteNil()
WriteBool(bool)
WriteInt(int64)
WriteUint(uint64)
WriteFloat(float64)
WriteString(string)
WriteError(error)
WriteUUID([16]byte)
WriteJSON([]byte)
// WritePtr(uintptr)
// CommitMessage flushes the current log message
// to the underlying writer and frees any resources
// to make the Writer ready for a new message.
CommitMessage()
// FlushUnderlying flushes underlying log writing
// streams to make sure all messages have been
// saved or transmitted.
// This method is intended for special circumstances like
// before exiting the application, it's not necessary
// to call it for every message in addtion to CommitMessage.
FlushUnderlying()
// String is here only for debugging
String() string
}
func flushUnderlying(writer any) {
switch x := writer.(type) {
case interface{ Sync() error }:
x.Sync() //#nosec G104
}
}