Files
loggerx/example/main.go
T

46 lines
1.0 KiB
Go
Raw Normal View History

2024-07-09 15:36:11 +08:00
package main
import (
"context"
2024-07-09 16:35:14 +08:00
"time"
2024-07-09 15:36:11 +08:00
"github.com/yuninks/loggerx"
)
func main() {
ctx := context.Background()
log := loggerx.NewLogger(ctx,
// loggerx.SetPrintFile(false),
loggerx.SetToConsole(),
2024-07-09 16:35:14 +08:00
// loggerx.SetTimeZone(time.UTC),
loggerx.SetTimeZone(time.FixedZone("CST", 8*3600)),
2025-01-15 15:29:45 +08:00
loggerx.SetEscapeHTML(false),
2025-06-10 15:41:44 +08:00
// loggerx.SetExpandData("ddd", "dddd"),
2024-07-09 15:36:11 +08:00
)
2025-01-15 15:29:45 +08:00
log.WriteAsync().Info(ctx, "{ \"a\": 1, \"b\": 2 }")
2024-07-09 15:36:11 +08:00
log.Info(ctx, "哈哈哈2")
log.Info(ctx, "哈哈哈2")
2025-01-15 15:29:45 +08:00
log.Info(ctx, "哈哈哈2\r")
log.Info(ctx, "哈哈哈2\r\n")
log.Info(ctx, "哈哈哈2<b>")
log.Info(ctx, "哈哈哈2<")
log.Info(ctx, "哈哈哈2>")
2024-11-22 20:08:25 +08:00
2025-06-10 15:41:44 +08:00
for i := 0; i < 10000; i++ {
go func() {
log.WriteAsync().Infof(ctx, "异步1 %d", i)
}()
go log.WriteAsync().Infof(ctx, "异步2 %d", i)
log.WriteAsync().Infof(ctx, "异步2 %d", i)
}
for i := 0; i < 10000; i++ {
go func() {
log.Infof(ctx, "同步1 %d", i)
}()
go log.Infof(ctx, "同步2 %d", i)
log.Infof(ctx, "同步3 %d", i)
2024-11-22 20:08:25 +08:00
}
time.Sleep(time.Second)
2024-07-09 15:36:11 +08:00
}