mirror of
https://github.com/volatiletech/authboss.git
synced 2024-11-30 09:06:45 +02:00
27010d9fe4
- Replace the old logging mechanisms with a leveled one. This is important as authboss needs to start saying a lot more about what's happening in the Info log, which will end up like Debug but that's okay. - Replace the error handling mechanisms with something different. This allows people to define their own error handlers.
30 lines
693 B
Go
30 lines
693 B
Go
package defaults
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"time"
|
|
)
|
|
|
|
// Logger writes exactly once for each log line to underlying io.Writer
|
|
// that's passed in and ends each message with a newline.
|
|
// It has RFC3339 as a date format, and emits a log level.
|
|
type Logger struct {
|
|
Writer io.Writer
|
|
}
|
|
|
|
// NewLogger creates a new logger from an io.Writer
|
|
func NewLogger(writer io.Writer) Logger {
|
|
return Logger{Writer: writer}
|
|
}
|
|
|
|
// Info logs go here
|
|
func (l Logger) Info(s string) {
|
|
fmt.Fprintf(l.Writer, "%s [INFO]: %s\n", time.Now().UTC().Format(time.RFC3339), s)
|
|
}
|
|
|
|
// Error logs go here
|
|
func (l Logger) Error(s string) {
|
|
fmt.Fprintf(l.Writer, "%s [EROR]: %s\n", time.Now().UTC().Format(time.RFC3339), s)
|
|
}
|