This is a creation in Article, where the information may have evolved or changed.
Using Golang's basic log packet can satisfy the problem of the log, specifically to do an example as follows, but it is still not very good, such as the size of the log file control. Just use it like this.
Package Main
Import (
"Log"
"OS"
)
Func Main () {
filename:= "Log_debug.log"
Logfile,err: = os. Create (FileName)
Logfile,err: = os. OpenFile (Filename,os. O_rdwr|os. O_create|os. o_append,0644)
Defer Logfile.close ()
If err! = Nil {
Log. Fatalln ("Open File error!")
}
Debuglog: = log. New (LogFile, "[Debug]", log. Llongfile)
Debuglog.setflags (debuglog.flags () | log. Lstdflags)
Debuglog.println ("A debug Message Here")
Debuglog.setprefix ("[Info]")
Debuglog.println ("A Info Message Here")
Debuglog.setflags (debuglog.flags () | log. Lstdflags)
Debuglog.println ("A different prefix")
}
821 Reads