Skip to content

Commit

Permalink
Adds new logger function and info struct for logging infos
Browse files Browse the repository at this point in the history
  • Loading branch information
apsdehal committed Sep 28, 2014
1 parent 3793c86 commit b01fb89
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions logger.go
Expand Up @@ -27,6 +27,23 @@ type Worker struct {
Color bool
}

type Info struct {
Time time.Time
module string
level string
message string
format string
}

type Logger {
Module string
worker *Worker
}
func (r *Info) Output() string {
msg := fmt.Sprintf(r.format, r.Time, r.level, r.message )
return msg
}

func NewWorker(prefix string, flag int, color bool) *Worker{
return &Worker{Minion: log.New(os.Stderr, prefix, flag), Color: color}
}
Expand All @@ -35,11 +52,11 @@ func (l *Worker) Log(level Level, calldepth int, info *Info) error {
if b.Color {
buf := &bytes.Buffer{}
buf.Write([]byte(colors[level]))
buf.Write([]byte(info.Formatted()))
buf.Write([]byte(info.Output())
buf.Write([]byte("\033[0m"))
return b.Minion.Output(calldepth+1, buf.String())
} else {
return b.Minion.Output(calldepth+1, info.Formatted())
return b.Minion.Output(calldepth+1, info)
}
}

Expand All @@ -55,4 +72,9 @@ func initColors() {
NOTICE: colorString(Green),
DEBUG: colorString(Cyan)
}
}

func (*l Logger) New(module string, color bool) (*Logger, error) {
newWorker := NewWorker("", 0, color)
return &Logger{Module: module, worker: newWorker}, nil
}

0 comments on commit b01fb89

Please sign in to comment.