|
|
|
@ -13,11 +13,11 @@ type Logger interface { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type LoggerConfig struct { |
|
|
|
|
env string |
|
|
|
|
id string |
|
|
|
|
name string |
|
|
|
|
version string |
|
|
|
|
aliLogConfig AliLogConfig |
|
|
|
|
Env string |
|
|
|
|
Id string |
|
|
|
|
Name string |
|
|
|
|
Version string |
|
|
|
|
AliLogConfig AliLogConfig |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type AliLogConfig struct { |
|
|
|
@ -32,28 +32,28 @@ func NewLogger(c *LoggerConfig) (log.Logger, func()) { |
|
|
|
|
|
|
|
|
|
var l Logger |
|
|
|
|
|
|
|
|
|
switch c.env { |
|
|
|
|
switch c.Env { |
|
|
|
|
default: |
|
|
|
|
l = NewStdLogger(os.Stdout) |
|
|
|
|
case enum.EnvLocal: |
|
|
|
|
l = NewStdLogger(os.Stdout) |
|
|
|
|
case enum.EnvDevelop, enum.EnvPre, enum.EnvProduct: |
|
|
|
|
l = NewAliyunLog( |
|
|
|
|
WithAccessKey(c.aliLogConfig.AccessKey), |
|
|
|
|
WithAccessSecret(c.aliLogConfig.AccessSecret), |
|
|
|
|
WithEndpoint(c.aliLogConfig.Endpoint), |
|
|
|
|
WithProject(c.aliLogConfig.Project), |
|
|
|
|
WithLogstore(c.aliLogConfig.LogStore), |
|
|
|
|
WithAccessKey(c.AliLogConfig.AccessKey), |
|
|
|
|
WithAccessSecret(c.AliLogConfig.AccessSecret), |
|
|
|
|
WithEndpoint(c.AliLogConfig.Endpoint), |
|
|
|
|
WithProject(c.AliLogConfig.Project), |
|
|
|
|
WithLogstore(c.AliLogConfig.LogStore), |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
logger := log.With(l, |
|
|
|
|
"ts", log.DefaultTimestamp, |
|
|
|
|
"caller", log.DefaultCaller, |
|
|
|
|
"env", c.env, |
|
|
|
|
"service.id", "id", |
|
|
|
|
"service.name", "Name", |
|
|
|
|
"service.version", "Version", |
|
|
|
|
"env", c.Env, |
|
|
|
|
"service.id", c.Id, |
|
|
|
|
"service.name", c.Name, |
|
|
|
|
"service.version", c.Version, |
|
|
|
|
"trace.id", tracing.TraceID(), |
|
|
|
|
"span.id", tracing.SpanID(), |
|
|
|
|
) |
|
|
|
|