This package is for logging messages to file. The log format can be in json or can be normal.
Its prettly simple to use.
Create the logger Instance - Use 'CreateLogger' function
There are 5 methods available to log, all of these linked to a log level.
- Debug(format string, a ...interface{})
- Info(format string, a ...interface{})
- Warn(format string, a ...interface{})
- Error(format string, a ...interface{})
- Fatal(format string, a ...interface{})
Each of the above functions are assoiated to 5 Loglevels.
- LDebug
- LInfo
- LWarn
- LError
- LFatal
Any of the log level functions can be called from any goroutine and the logging would not be affected.
go get github.com/r-pai/logger
import"github.com/r-pai/logger"log:=logger.CreateLogger("./", "Myapp", logger.LDebug)log.Debug("Starting Hello LDEBUG")
log.Info("Starting Hello LINFO")
log.Warn("Starting Hello LWARN")
log.Error("Starting Hello LERROR")
log.Fatal("Starting Hello LFATAL")package main
import ( "github.com/r-pai/logger"
)
//Create the logger instancevarlog=logger.CreateLogger("./", "Myapp", logger.LDebug)
funcmain() {
log.Debug("Starting Hello LDEBUG")
log.Info("Starting Hello LINFO")
log.Warn("Starting Hello LWARN")
log.Error("Starting Hello LERROR")
log.Fatal("Starting Hello LFATAL")
}package main
import (
"github.com/r-pai/logger""time"
)
funcnumber() int {
num:=15*5returnnum
}
funcgo1() {
fori:=0; i<1000; i++ {
log.Info("%s %d", "go1 Log message", i)
time.Sleep(400*time.Millisecond)
}
}
funcgo2() {
fori:=1000; i<3000; i++ {
log.Info("%s %d", "go2 Log message", i)
time.Sleep(100*time.Millisecond)
}
}
//Create the loggervarlog*logger.GLoggerfuncinit(){
log=logger.CreateLogger("./", "Myapp", logger.LDebug)
//constants from time packagelog.SetLogTimeFormat(time.RFC850) //set the time format//logout put can be in json formatlog.SetJSONLog(true)
}
//main entry pointfuncmain() {
gogo1()
gogo2()
for {
}
}
Sample output of file : MyApp_07-09-2019.log
Json Style output

