diff --git a/log.go b/log.go index 1376a13..4438edc 100644 --- a/log.go +++ b/log.go @@ -73,7 +73,7 @@ type Ldata struct { Color bool } -type logger struct { +type Logger struct { system string color bool @@ -88,8 +88,8 @@ type logger struct { info_tmpl *template.Template } -func Default() *logger { - l := &logger{ +func Default() *Logger { + l := &Logger{ err: os.Stderr, out: os.Stdout, color: true, @@ -99,8 +99,8 @@ func Default() *logger { return l } -func (l *logger) Sub(sys string) *logger { - ret := &logger{ +func (l *Logger) Sub(sys string) *Logger { + ret := &Logger{ system: sys, err: l.err, out: l.out, @@ -115,7 +115,7 @@ func (l *logger) Sub(sys string) *logger { return ret } -func (l *logger) guessColor() { +func (l *Logger) guessColor() { l.color = true if w, ok := l.out.(*os.File); !ok || os.Getenv("TERM") == "dumb" || (!isatty.IsTerminal(w.Fd()) && !isatty.IsCygwinTerminal(w.Fd())) { @@ -126,19 +126,19 @@ func (l *logger) guessColor() { l.color = false } } -func (l *logger) SetColor(c bool) { +func (l *Logger) SetColor(c bool) { l.color = c } -func (l *logger) SetErrOutput(err io.Writer) { +func (l *Logger) SetErrOutput(err io.Writer) { l.err = err } -func (l *logger) SetOutput(out io.Writer) { +func (l *Logger) SetOutput(out io.Writer) { l.out = out } -func (l *logger) Reload() error { +func (l *Logger) Reload() error { l.guessColor() return l.ParseTmpl() } @@ -152,7 +152,7 @@ func NewLogFormater() *LogFormater { } } -func (l *logger) DefaultFuncMap() template.FuncMap { +func (l *Logger) DefaultFuncMap() template.FuncMap { funcMap := template.FuncMap{ "Time": func() string { return time.Now().Format("2006/01/02 15:04:05") }, } @@ -160,7 +160,7 @@ func (l *logger) DefaultFuncMap() template.FuncMap { return funcMap } -func (l *logger) ParseTmpl() error { +func (l *Logger) ParseTmpl() error { if l.funcMap == nil { l.funcMap = l.DefaultFuncMap() } @@ -187,14 +187,14 @@ func (l *logger) ParseTmpl() error { return nil } -func (l *logger) SetTmpl(formatter *LogFormater, funcMap template.FuncMap) { +func (l *Logger) SetTmpl(formatter *LogFormater, funcMap template.FuncMap) { l.formatter = formatter if funcMap != nil { l.funcMap = funcMap } } -func (l *logger) output(t tout, depth int, stack string, fields H, v ...interface{}) { +func (l *Logger) output(t tout, depth int, stack string, fields H, v ...interface{}) { msg := fmt.Sprint(v...) data := Ldata{ Fields: fields, @@ -228,12 +228,12 @@ func (l *logger) output(t tout, depth int, stack string, fields H, v ...interfac err = l.info_tmpl.Execute(l.out, data) } if err != nil { - fmt.Fprintln(l.err, "[FATAL] logger error:", err) + fmt.Fprintln(l.err, "[FATAL] Logger error:", err) panic(err) } } -func (l *logger) ErrorF(fields H, v ...interface{}) { +func (l *Logger) ErrorF(fields H, v ...interface{}) { if PROD { l.output(terror, 3, "", fields, v...) } else { @@ -241,7 +241,7 @@ func (l *logger) ErrorF(fields H, v ...interface{}) { } } -func (l *logger) Error(v ...interface{}) { +func (l *Logger) Error(v ...interface{}) { if PROD { l.output(terror, 3, "", H{}, v...) } else { @@ -249,7 +249,7 @@ func (l *logger) Error(v ...interface{}) { } } -func (l *logger) DebugF(fields H, v ...interface{}) { +func (l *Logger) DebugF(fields H, v ...interface{}) { if PROD { l.output(tdebug, 3, "", fields, v...) } else { @@ -257,7 +257,7 @@ func (l *logger) DebugF(fields H, v ...interface{}) { } } -func (l *logger) Debug(v ...interface{}) { +func (l *Logger) Debug(v ...interface{}) { if PROD { l.output(tdebug, 3, "", H{}, v...) } else { @@ -265,18 +265,18 @@ func (l *logger) Debug(v ...interface{}) { } } -func (l *logger) WarnF(fields H, v ...interface{}) { +func (l *Logger) WarnF(fields H, v ...interface{}) { l.output(twarn, 3, "", fields, v...) } -func (l *logger) Warn(v ...interface{}) { +func (l *Logger) Warn(v ...interface{}) { l.output(twarn, 3, "", H{}, v...) } -func (l *logger) InfoF(fields H, v ...interface{}) { +func (l *Logger) InfoF(fields H, v ...interface{}) { l.output(tinfo, 3, "", fields, v...) } -func (l *logger) Info(v ...interface{}) { +func (l *Logger) Info(v ...interface{}) { l.output(tinfo, 3, "", H{}, v...) } diff --git a/std.go b/std.go index 68e836b..9631b95 100644 --- a/std.go +++ b/std.go @@ -2,7 +2,7 @@ package log var std = Default() -func Sub(sys string) *logger { +func Sub(sys string) *Logger { return std.Sub(sys) }