Пример #1
0
// all logging functions call this `log` function
func (console *Logger) log(d logDetails, colorAttr color.Attribute, isBold bool, format string, args ...interface{}) {
	// Only print out, logs that are the selected level or higher
	if console.level >= d.level {
		newlog := color.Set(colorAttr)
		defer color.Unset()

		// if the request is to log bold text
		if isBold {
			newlog.Add(color.Bold)
		}

		// Check to see if we are to add background color
		// Alert and Fatal have background colors
		switch d.level {
		case 1: // for Fatal
			color.Set(color.BgRed)
			break
		case 2: // for Alerts
			color.Set(color.BgMagenta)
			break
		}

		// I want it log both into the file and on the console
		console.LogFile.Printf(format, args...)
		log.Printf(format, args...)
	}
}
Пример #2
0
// Critical can be used to log system wide Critical information that needs to be fixed immediately (Red background and white text)
func (console *Logger) Critical(format string, args ...interface{}) {
	color.Set(color.BgRed, color.FgWhite, color.Bold)
	defer color.Unset()
	console.log(logLevel["Fatal"], color.FgRed, true, format, args...)
}
Пример #3
0
// Alert can be used to log Alerts, maybe on certain events (Magenta background, white text).
func (console *Logger) Alert(format string, args ...interface{}) {
	color.Set(color.BgMagenta, color.FgBlack, color.Bold)
	defer color.Unset()
	console.log(logLevel["Alert"], color.FgBlack, true, format, args...)
}