Example #1
0
func (l *Log) format(timestamp bool, level int, format string, args []interface{}) string {
	ts := ""
	if timestamp {
		f := l.Palette.Timestamp.SprintfFunc()
		ts = f(
			"%s", time.Now().Format(l.TimeFmt),
		)
	}
	var p *color.Color
	switch level {
	case say:
		p = l.Palette.Say
	case notice:
		p = l.Palette.Notice
	case warn:
		p = l.Palette.Warn
	case shout:
		p = l.Palette.Shout
	case header:
		p = l.Palette.Header
	default:
		panic("unknown log level")
	}
	return ts + p.SprintfFunc()(format, args...)
}
Example #2
0
func (f *Formatter) sprintfColor(c *color.Color, format string, args ...interface{}) string {
	if f.DisabledColor || c == nil {
		return fmt.Sprintf(format, args...)
	} else {
		return c.SprintfFunc()(format, args...)
	}
}