logger/config.go

26 lines
838 B
Go
Raw Permalink Normal View History

2021-12-14 10:53:50 +08:00
package logger
import "fmt"
2022-05-18 11:17:22 +08:00
type mode string
2021-12-14 10:53:50 +08:00
2022-05-18 11:17:22 +08:00
const (
Dev mode = "development"
Prod mode = "production"
2021-12-14 10:53:50 +08:00
)
// LogConfig 日志配置
type LogConfig struct {
2022-05-18 11:17:22 +08:00
Mode mode `env:"LOG_MODE" envDefault:"production"` // dev, prod
LokiEnable bool `env:"LOG_LOKI_ENABLE"` // 是否启用Loki
FileEnable bool `env:"LOG_FILE_ENABLE"` // 是否输出到文件
LokiHost string `env:"LOG_LOKI_HOST"` // Loki地址
LokiPort int `env:"LOG_LOKI_PORT"` // Loki端口
LokiSource string `env:"LOG_LOKI_SOURCE_NAME"` // Loki的source名称
LokiJob string `env:"LOG_LOKI_JOB_NAME"` // Loki的job名称
2021-12-14 10:53:50 +08:00
}
func (c LogConfig) getLokiPushURL() string {
return fmt.Sprintf("http://%v:%v/loki/api/v1/push", c.LokiHost, c.LokiPort)
}