蓝眼网盘定制版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
879 B

8 years ago
package rest
import (
"fmt"
"log"
"os"
"time"
)
func Log(prefix string, content string) {
//日志输出到文件中
filePath := GetLogPath() + "/tank-" + time.Now().Local().Format("2006-01-02") + ".log"
f, err := os.OpenFile(filePath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
fmt.Errorf("error opening file: %v", err)
}
defer f.Close()
log.SetOutput(f)
log.SetPrefix(prefix)
log.Println(content)
//如果需要输出到控制台。
if CONFIG.LogToConsole {
fmt.Println(content)
}
}
func LogDebug(content string) {
go Log("[Debug]", content)
}
func LogInfo(content string) {
go Log("[Info]", content)
}
func LogWarning(content string) {
go Log("[Warning]", content)
}
func LogError(content string) {
go Log("[Error]", content)
}
func LogPanic(content interface{}) {
Log("[Panic]", fmt.Sprintf("%v", content))
panic(content)
}