import (
"log"
"syscall"
)
file, _ = os.OpenFile("app.log",
syscall.O_APPEND|syscall.O_CREATE|syscall.O_WRONLY, 0644)
defer file.Close()
log.SetOutput(file)
log.Println()
log.Printf()
log.SetOutput(stdout)
// get flag value and save it before change flags value using SetFlags()
log.Flags()
// date, time, microseconds, filename
// usually filename is not necessary
log.SetFlags(log.Ldate | log.Ltime | log.Lmicrosecons | log.Llongfile)
// in most cases, prefix is not necessary.
log.SetPrefix("App:")
// without log header
log.SetFlags(0)
func LPrintf(fmtText string, args ...interface{}) {
fmt.Printf(fmtText, args...)
}
import ("time")
import ("fmt")
now := time.Now()
fmt.Println(now.Format("20060102 15:04:05"))
fmt.Println(now.Format("2006-01-02 150405"))
fmt.Println(now.Format("20060102 150405"))