feat: add logc package, support AddGlobalFields for both logc and logx. (#2463)
* feat: add logc package * feat: add logc, add AddGlobalFields for both logc and logx * chore: add benchmarks * chore: add more tests * chore: simplify globalFields in logx * chore: remove outdated comments
This commit is contained in:
@@ -263,7 +263,18 @@ func buildFields(fields ...LogField) []string {
|
||||
return items
|
||||
}
|
||||
|
||||
func combineGlobalFields(fields []LogField) []LogField {
|
||||
globals := globalFields.Load()
|
||||
if globals == nil {
|
||||
return fields
|
||||
}
|
||||
|
||||
return append(globals.([]LogField), fields...)
|
||||
}
|
||||
|
||||
func output(writer io.Writer, level string, val interface{}, fields ...LogField) {
|
||||
fields = combineGlobalFields(fields)
|
||||
|
||||
switch atomic.LoadUint32(&encoding) {
|
||||
case plainEncodingType:
|
||||
writePlainAny(writer, level, val, buildFields(fields...)...)
|
||||
|
||||
Reference in New Issue
Block a user