This is a simple logging library for Golang that handles the output log in files, you can rotate the logs and apply different levels of logging.
go get github.com/cperez08/golang-logger
import gologger "github.com/cperez08/golang-logger"
// Basic Usage with Dev Configuration
log := gologger.NewLogger("./tmp/testfile.log", gologger.DEV, 0)
log.Info.Println("Print Hello World for develop")
// Basic Usage with Prod Configuration
log := gologger.NewLogger("./tmp/testfile.log", gologger.PROD, 0)
log.Error.Println("Print Hello World Prod")
// Basic Usage with custom Configuration
log := gologger.NewLogger("./tmp/testfile.log", gologger.CUSTOM, gologger.TRACE|gologger.DEBUG|gologger.WARN|gologger.ERROR)
log.Trace.Print("Print Hello World Custom")
import gologger "github.com/cperez08/golang-logger"
log := gologger.NewLoggerWithRotation("./tmp/testfile.log", gologger.CUSTOM, gologger.TRACE|gologger.INFO, 100)
log.Info.Println("Printing log with rotation at 100KB")
log.RotateLogByWeight()
// Also can be rotated without waiting for the weight
log.RotateLog()
import gologger "github.com/cperez08/golang-logger"
file, err := os.OpenFile("./tmp/logger_opefile.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
if err != nil {
t.Fail()
return
}
defer file.Close()
log = gologger.NewLoggerWithOpenFile(file, gologger.PROD, 0)
log.Error.Println("Print log with an open file")
- Create automatic rotation logs
- Improve tests
- Create MultiWriting log std.Out and Files at the same time
- MIT LICENSE, see LICENSE file