月关宝盒
您可以使用不同的日志库,如logrus或修改标准日志库,如下所示:日志包:// Info writes logs in the color blue with "INFO: " as prefixvar Info = log.New(os.Stdout, "\u001b[34mINFO: \u001B[0m", log.LstdFlags|log.Lshortfile)// Warning writes logs in the color yellow with "WARNING: " as prefixvar Warning = log.New(os.Stdout, "\u001b[33mWARNING: \u001B[0m", log.LstdFlags|log.Lshortfile)// Error writes logs in the color red with "ERROR: " as prefixvar Error = log.New(os.Stdout, "\u001b[31mERROR: \u001b[0m", log.LstdFlags|log.Lshortfile)// Debug writes logs in the color cyan with "DEBUG: " as prefixvar Debug = log.New(os.Stdout, "\u001b[36mDEBUG: \u001B[0m", log.LstdFlags|log.Lshortfile)用法:Error.Println("this is an error")结果将是: