예제 #1
0
func main() {
	// log.SetFlags(log.LstdFlags | log.Lshortfile)
	colog.Register()
	log.Print("register colog")

	colog.SetDefaultLevel(colog.LWarning)
	log.Print("set default level LWarning")

	colog.SetFlags(log.Ldate)
	log.Print("Only date")
	printLogs()

	colog.SetDefaultLevel(colog.LInfo)
	log.Print("set default level LInfo")
	colog.SetFlags(log.LstdFlags | log.Lshortfile)
	log.Print("Date, time, filename")
	printLogs()

	colog.ParseFields(true)
	log.Print("Parse fileds like key=value")
	printLogs()

	colog.SetMinLevel(colog.LWarning)
	log.Print("warn: set minimal level LWarning")
	printLogs()

}
예제 #2
0
// InitEnv configures logging settings based on environment parameter
func InitEnv(env string, errorlog string) {
	colog.SetFlags(log.LstdFlags | log.Lshortfile)
	colog.ParseFields(true)
	if env == "dev" {
		InitLogToStdout(env)
	} else if env == "stage" {
		InitLogToStdout(env)
	} else if env == "prod" {
		fmt.Println("Warning level or above outputted to", errorlog)
		InitLogToFile(errorlog)
	} else {
		log.Panic("Invalid environment argument!")
	}
}