2025-04-01 14:34:18 +08:00
|
|
|
# Simple Log
|
|
|
|
|
|
|
|
A very simple log system(golang).
|
2025-04-01 15:03:52 +08:00
|
|
|
|
|
|
|
## Install
|
|
|
|
|
|
|
|
```bash
|
|
|
|
go get github.com/lion187chen/simplelog
|
|
|
|
```
|
|
|
|
|
2025-04-01 15:15:01 +08:00
|
|
|
## Example
|
2025-04-01 15:03:52 +08:00
|
|
|
|
|
|
|
```go
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/lion187chen/simplelog"
|
|
|
|
)
|
|
|
|
|
2025-04-01 15:11:03 +08:00
|
|
|
func CreateLog(file string, level simplelog.Level) *simplelog.Log {
|
2025-04-01 15:03:52 +08:00
|
|
|
switch file {
|
|
|
|
case "":
|
2025-04-01 15:11:03 +08:00
|
|
|
return new(simplelog.Log).InitStd(level, simplelog.Ltime|simplelog.Lfile|simplelog.Llevel)
|
2025-04-01 15:03:52 +08:00
|
|
|
default:
|
2025-04-01 15:11:03 +08:00
|
|
|
return new(simplelog.Log).InitRotating(file, 1024*10, 10, level)
|
2025-04-01 15:03:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
log := CreateLog("./log/MS.log", simplelog.LevelInfo)
|
|
|
|
for i := 0; i < 10000000; i++ {
|
|
|
|
log.Trace("hello world")
|
|
|
|
log.Debug("hello world")
|
|
|
|
log.Info("hello world")
|
|
|
|
log.Warn("hello world")
|
|
|
|
log.Error("hello world")
|
|
|
|
log.Fatal("hello world")
|
|
|
|
time.Sleep(8 * time.Millisecond)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|