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()
|
|
|
|
}
|
|
|
|
|
|
|
|
var loggers = make([]Logger, 0)
|
|
|
|
|
2017-06-13 00:21:19 +02:00
|
|
|
// bind logger to handle saving/output of a Log entry
|
2017-06-12 22:32:27 +02:00
|
|
|
func AddLogger(logger Logger) {
|
|
|
|
loggers = append(loggers, logger)
|
|
|
|
}
|
|
|
|
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|