2018-04-03 21:07:18 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"compress/zlib"
|
|
|
|
"flag"
|
|
|
|
"io"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
|
2022-03-20 19:19:42 +00:00
|
|
|
"git.tuxpa.in/a/zlog"
|
2018-04-03 21:07:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func writeLog(fname string, count int, useCompress bool) {
|
|
|
|
opFile := os.Stdout
|
|
|
|
if fname != "<stdout>" {
|
|
|
|
fil, _ := os.Create(fname)
|
|
|
|
opFile = fil
|
|
|
|
defer func() {
|
|
|
|
if err := fil.Close(); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
var f io.WriteCloser = opFile
|
|
|
|
if useCompress {
|
|
|
|
f = zlib.NewWriter(f)
|
|
|
|
defer func() {
|
|
|
|
if err := f.Close(); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-03-20 19:19:42 +00:00
|
|
|
zlog.TimestampFunc = func() time.Time { return time.Now().Round(time.Second) }
|
|
|
|
log := zlog.New(f).With().
|
2018-04-03 21:07:18 +00:00
|
|
|
Timestamp().
|
|
|
|
Logger()
|
|
|
|
for i := 0; i < count; i++ {
|
|
|
|
log.Error().
|
|
|
|
Int("Fault", 41650+i).Msg("Some Message")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
outFile := flag.String("out", "<stdout>", "Output File to which logs will be written to (WILL overwrite if already present).")
|
|
|
|
numLogs := flag.Int("num", 10, "Number of log messages to generate.")
|
|
|
|
doCompress := flag.Bool("compress", false, "Enable inline compressed writer")
|
|
|
|
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
writeLog(*outFile, *numLogs, *doCompress)
|
|
|
|
}
|