-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfileholder.go
62 lines (51 loc) · 1.19 KB
/
fileholder.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
package goolog2
import (
"io"
"os"
)
// Color constants
type Color int
const (
NONE Color = iota
RED
YELLOW
BLUE
)
// Generic file writer
//
// This interface is a classic io.Writer interface extended
// by possibility to change colors of the output.
type FileWriter interface {
// If writter is not closable, the method Close returns nil.
io.WriteCloser
// If it is unable to read file info, it returns nil
Stat() os.FileInfo
// Flush the output
Sync()
// Change output color
ChangeColor(
color Color)
// Reset the output color
ResetColor()
}
// Holder of a file
//
// This interface wraps a logging file. The file can be just one physical
// file. Or it can be a pattern defining a rotating logs.
type FileHolder interface {
// Access and log the log writer for writing of one item
AccessWriter(
functor func(writer FileWriter))
// Increase reference counter - there is new owner of the holder
//
// Returns: itself
Ref() FileHolder
// Decrease reference counter
//
// If the counter reaches zero the object is destroyed (files
// closed etc.)
//
// Expectation: there are no other threads accessing the holder
// if the reference counter reaches zero!
Unref()
}