Ejemplo n.º 1
0
// WriteLog implements Appender
// output example: [INFO] mabetle: message.
func (a ConsoleAppender) WriteLog(level string, catalog string, callin int, v ...interface{}) {
	if !mterm.IsXterm() && isWindows() {
		// for win cmd
		winCmdOut(level, catalog, callin, v...)
		return
	}
	// xterm and others
	logMsg := fmt.Sprint(v...)
	msg := fmt.Sprintf("\n[%s] %s: %s", level, catalog, logMsg)
	msg = GetLevelColorMsg(level, msg)
	consoleLogger.Output(callin, msg)
}
Ejemplo n.º 2
0
func GetLevelColorMsg(level string, v ...interface{}) string {
	// default no color.
	msg := fmt.Sprint(v...)
	levelLevel := GetStringLevel(level)

	// xterm can show color.
	if mterm.IsXterm() {
		switch levelLevel {
		case LevelInfo:
			msg = i(msg)
		case LevelTrace:
			msg = t(msg)
		case LevelError:
			msg = e(msg)
		case LevelWarn:
			msg = w(msg)
		case LevelDebug:
			msg = d(msg)
		default:
			msg = i(msg)
		}
	}
	return msg
}
Ejemplo n.º 3
0
func GetColorPrinter() ColorPrinter {
	if mterm.IsXterm() {
		return xc
	}
	return c
}