Livelogs is a library to stream logs to multiple watchers.
The logs could also be save into database with gorm.
package main
import (
"context"
"fmt"
"time"
"github.com/blueworrybear/livelogs"
"github.com/blueworrybear/livelogs/core"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/sqlite"
)
func main() {
db, _ := gorm.Open("sqlite3", "core.db")
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
m := livelogs.NewLogManager(db)
log, _ := m.Create()
go func() {
tail, _ := log.Tail(ctx)
for {
select {
case line := <-tail:
fmt.Println(line.Text)
}
}
}()
for {
log.Write(ctx, &core.LogLine{Text: "log"})
time.Sleep(1 * time.Second)
}
}
Above code will keep print out log
.
© Benno, 2020
Released under the MIT License