2
0
mirror of https://gitee.ltd/lxh/logger.git synced 2026-04-02 14:17:23 +08:00

支持初始化的时候从环境变量读取配置信息

This commit is contained in:
李寻欢
2021-12-29 14:33:48 +08:00
parent 3f6003edd7
commit 6253de5599
6 changed files with 31 additions and 12 deletions

View File

@@ -69,14 +69,13 @@ func (c lokiWriter) Write(p []byte) (int, error) {
return 0, err
}
label := model.LabelSet{"job": model.LabelValue(config.LokiName)}
label["source"] = model.LabelValue(config.LokiName)
label := model.LabelSet{"job": model.LabelValue(config.LokiJob)}
label["source"] = model.LabelValue(config.LokiSource)
label["level"] = model.LabelValue(li.Level)
label["caller"] = model.LabelValue(li.Caller)
// 异步推送消息到服务器
go func() {
err = lokiClient.Handle(label, time.Now().Local(), li.Msg)
if err != nil {
if err = lokiClient.Handle(label, time.Now().Local(), li.Msg); err != nil {
fmt.Printf("日志推送到Loki失败: %v\n", err.Error())
}
}()