mirror of
https://github.com/rancher/os.git
synced 2025-09-16 15:09:27 +00:00
make ros log to dmesg
Signed-off-by: Sven Dowideit <SvenDowideit@home.org.au>
This commit is contained in:
40
log/showuserlog.go
Normal file
40
log/showuserlog.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Sirupsen/logrus"
|
||||
"os"
|
||||
)
|
||||
|
||||
// ShowuserlogHook writes all levels of logrus entries to a file for later analysis
|
||||
type ShowuserlogHook struct {
|
||||
Level logrus.Level
|
||||
}
|
||||
|
||||
func NewShowuserlogHook(l logrus.Level) (*ShowuserlogHook, error) {
|
||||
return &ShowuserlogHook{l}, nil
|
||||
}
|
||||
|
||||
func (hook *ShowuserlogHook) Fire(entry *logrus.Entry) error {
|
||||
line, err := entry.String()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Unable to read entry, %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
if entry.Level <= hook.Level {
|
||||
fmt.Printf("> %s", line)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (hook *ShowuserlogHook) Levels() []logrus.Level {
|
||||
return []logrus.Level{
|
||||
logrus.DebugLevel,
|
||||
logrus.InfoLevel,
|
||||
logrus.WarnLevel,
|
||||
logrus.ErrorLevel,
|
||||
logrus.FatalLevel,
|
||||
logrus.PanicLevel,
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user