LogPrintln.go 627 B

1234567891011121314151617181920212223242526272829
  1. package logs
  2. import (
  3. "fmt"
  4. "log"
  5. "os"
  6. )
  7. func init() {
  8. logFile, err := os.OpenFile("logs/logs.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
  9. if err != nil {
  10. fmt.Println("open log file failed, err:", err)
  11. return
  12. }
  13. log.SetOutput(logFile)
  14. //log.SetFlags(log.Lshortfile | log.Lmicroseconds | log.Ldate)
  15. //
  16. //log.Println("这是一条很普通的日志。")
  17. //v := "很普通的"
  18. //log.Printf("这是一条%s日志。\n", v)
  19. //log.Fatalln("这是一条会触发fatal的日志。")
  20. //log.Panicln("这是一条会触发panic的日志。")
  21. }
  22. func Println(a ...interface{}) {
  23. log.Println(a)
  24. //fmt.Println(a)
  25. }