1 Star 0 Fork 0

powerpaas/machine

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
fmt_machine_logger.go 1.91 KB
一键复制 编辑 原始数据 按行查看 历史
package log
import (
"fmt"
"io"
"os"
)
type FmtMachineLogger struct {
outWriter io.Writer
errWriter io.Writer
debug bool
history *HistoryRecorder
}
// NewFmtMachineLogger creates a MachineLogger implementation used by the drivers
func NewFmtMachineLogger() MachineLogger {
return &FmtMachineLogger{
outWriter: os.Stdout,
errWriter: os.Stderr,
debug: false,
history: NewHistoryRecorder(),
}
}
func (ml *FmtMachineLogger) SetDebug(debug bool) {
ml.debug = debug
}
func (ml *FmtMachineLogger) SetOutWriter(out io.Writer) {
ml.outWriter = out
}
func (ml *FmtMachineLogger) SetErrWriter(err io.Writer) {
ml.errWriter = err
}
func (ml *FmtMachineLogger) Debug(args ...interface{}) {
ml.history.Record(args...)
if ml.debug {
fmt.Fprintln(ml.errWriter, args...)
}
}
func (ml *FmtMachineLogger) Debugf(fmtString string, args ...interface{}) {
ml.history.Recordf(fmtString, args...)
if ml.debug {
fmt.Fprintf(ml.errWriter, fmtString+"\n", args...)
}
}
func (ml *FmtMachineLogger) Error(args ...interface{}) {
ml.history.Record(args...)
fmt.Fprintln(ml.errWriter, args...)
}
func (ml *FmtMachineLogger) Errorf(fmtString string, args ...interface{}) {
ml.history.Recordf(fmtString, args...)
fmt.Fprintf(ml.errWriter, fmtString+"\n", args...)
}
func (ml *FmtMachineLogger) Info(args ...interface{}) {
ml.history.Record(args...)
fmt.Fprintln(ml.outWriter, args...)
}
func (ml *FmtMachineLogger) Infof(fmtString string, args ...interface{}) {
ml.history.Recordf(fmtString, args...)
fmt.Fprintf(ml.outWriter, fmtString+"\n", args...)
}
func (ml *FmtMachineLogger) Warn(args ...interface{}) {
ml.history.Record(args...)
fmt.Fprintln(ml.outWriter, args...)
}
func (ml *FmtMachineLogger) Warnf(fmtString string, args ...interface{}) {
ml.history.Recordf(fmtString, args...)
fmt.Fprintf(ml.outWriter, fmtString+"\n", args...)
}
func (ml *FmtMachineLogger) History() []string {
return ml.history.records
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/powerpaas/machine.git
git@gitee.com:powerpaas/machine.git
powerpaas
machine
machine
v0.6.0-rc1

搜索帮助