logmania/log/logger.go

31 lines
542 B
Go
Raw Normal View History

2017-06-12 22:32:27 +02:00
package log
2017-06-13 00:21:19 +02:00
// interface of a logger
2017-06-12 22:32:27 +02:00
type Logger interface {
Hook(*Entry)
Close()
}
2017-06-14 21:31:17 +02:00
var loggers = make(map[string]Logger)
2017-06-12 22:32:27 +02:00
2017-06-13 00:21:19 +02:00
// bind logger to handle saving/output of a Log entry
2017-06-14 21:31:17 +02:00
func AddLogger(name string, logger Logger) {
loggers[name] = logger
}
func RemoveLogger(name string) {
2017-06-14 23:52:38 +02:00
loggers[name].Close()
2017-06-14 21:31:17 +02:00
delete(loggers, name)
2017-06-12 22:32:27 +02:00
}
func save(e *Entry) {
for _, logger := range loggers {
logger.Hook(e)
}
if e.Level == PanicLevel {
for _, logger := range loggers {
logger.Close()
}
panic("panic see last log in logmania")
}
}