-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugins.go
34 lines (25 loc) · 884 Bytes
/
plugins.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
package soba
import (
"sync"
"github.com/pkg/errors"
)
// These global variables are only used to provide extensibility with external appenders.
// If you think of a better solution, please submit a pull request, because I hate global variables.
var (
// plMutex is a mutex to manage concurrent access when registering an appender.
plMutex = sync.Mutex{}
// plAppenders is a list of external appenders identified by their name.
plAppenders = map[string]Appender{}
)
// RegisterAppenders registers given external appenders to be accessible for loggers.
func RegisterAppenders(appenders ...Appender) error {
plMutex.Lock()
defer plMutex.Unlock()
for _, appender := range appenders {
if !IsAppenderNameValid(appender.Name()) {
return errors.Errorf("name is invalid for appender: %s", appender.Name())
}
plAppenders[appender.Name()] = appender
}
return nil
}