2019-12-27 11:55:15 -03:00
|
|
|
package logext
|
|
|
|
|
|
|
|
import "github.com/apex/log"
|
|
|
|
|
2020-05-26 00:48:10 -03:00
|
|
|
// Writer writes with log.Info.
|
2019-12-27 11:55:15 -03:00
|
|
|
type Writer struct {
|
|
|
|
ctx *log.Entry
|
|
|
|
}
|
|
|
|
|
2020-05-26 00:48:10 -03:00
|
|
|
// NewWriter creates a new log writer.
|
2019-12-27 11:55:15 -03:00
|
|
|
func NewWriter(ctx *log.Entry) Writer {
|
|
|
|
return Writer{ctx: ctx}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t Writer) Write(p []byte) (n int, err error) {
|
|
|
|
t.ctx.Info(string(p))
|
|
|
|
return len(p), nil
|
|
|
|
}
|
2020-05-10 17:03:49 +01:00
|
|
|
|
2020-05-26 00:48:10 -03:00
|
|
|
// Writer writes with log.Error.
|
2020-05-10 17:03:49 +01:00
|
|
|
type ErrorWriter struct {
|
|
|
|
ctx *log.Entry
|
|
|
|
}
|
|
|
|
|
2020-05-26 00:48:10 -03:00
|
|
|
// NewWriter creates a new log writer.
|
2020-05-10 17:03:49 +01:00
|
|
|
func NewErrWriter(ctx *log.Entry) ErrorWriter {
|
|
|
|
return ErrorWriter{ctx: ctx}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w ErrorWriter) Write(p []byte) (n int, err error) {
|
|
|
|
w.ctx.Error(string(p))
|
|
|
|
return len(p), nil
|
|
|
|
}
|