mirror of
https://github.com/zrepl/zrepl.git
synced 2025-08-12 00:09:09 +02:00
logging: first outlet receives logger error message
Abandons stderr special-casing: * looks weird on shell and IO redirection to same file because of interleaving of stdout and stderr * better than a separate dedicated outlet because it does not require additional configuration fixes #28 BREAK SEMANTICS CONFIG
This commit is contained in:
@ -78,28 +78,32 @@ type Outlet interface {
|
||||
WriteEntry(ctx context.Context, entry Entry) error
|
||||
}
|
||||
|
||||
type Outlets struct {
|
||||
reg map[Level][]Outlet
|
||||
e Outlet
|
||||
type Outlets map[Level][]Outlet
|
||||
|
||||
func NewOutlets() Outlets {
|
||||
return make(map[Level][]Outlet, len(AllLevels))
|
||||
}
|
||||
|
||||
func NewOutlets(loggerErrorOutlet Outlet) *Outlets {
|
||||
return &Outlets{
|
||||
make(map[Level][]Outlet, len(AllLevels)),
|
||||
loggerErrorOutlet,
|
||||
}
|
||||
}
|
||||
|
||||
func (os *Outlets) Add(outlet Outlet, minLevel Level) {
|
||||
func (os Outlets) Add(outlet Outlet, minLevel Level) {
|
||||
for _, l := range AllLevels[minLevel:] {
|
||||
os.reg[l] = append(os.reg[l], outlet)
|
||||
os[l] = append(os[l], outlet)
|
||||
}
|
||||
}
|
||||
|
||||
func (os *Outlets) Get(level Level) []Outlet {
|
||||
return os.reg[level]
|
||||
func (os Outlets) Get(level Level) []Outlet {
|
||||
return os[level]
|
||||
}
|
||||
|
||||
func (os *Outlets) GetLoggerErrorOutlet() Outlet {
|
||||
return os.e
|
||||
// Return the first outlet added to this Outlets list using Add()
|
||||
// with minLevel <= Error.
|
||||
// If no such outlet is in this Outlets list, a discarding outlet is returned.
|
||||
func (os Outlets) GetLoggerErrorOutlet() Outlet {
|
||||
if len(os[Error]) < 1 {
|
||||
return nullOutlet{}
|
||||
}
|
||||
return os[Error][0]
|
||||
}
|
||||
|
||||
type nullOutlet struct{}
|
||||
|
||||
func (nullOutlet) WriteEntry(ctx context.Context, entry Entry) error { return nil }
|
||||
|
Reference in New Issue
Block a user