github.com/matrixorigin/matrixone@v1.2.0/pkg/vm/engine/tae/common/fields.go (about)

     1  // Copyright 2022 Matrix Origin
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  // http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package common
    16  
    17  import (
    18  	"fmt"
    19  	"time"
    20  
    21  	"go.uber.org/zap"
    22  )
    23  
    24  type Reprer interface {
    25  	Repr() string
    26  }
    27  
    28  var StringerField = zap.Stringer
    29  var AnyField = zap.Any
    30  
    31  func TimestampField(val any) zap.Field               { return zap.Any("timestamp", val) }
    32  func ReasonField(val string) zap.Field               { return zap.String("reason", val) }
    33  func DurationField(val time.Duration) zap.Field      { return zap.Duration("duration", val) }
    34  func OperationField(val string) zap.Field            { return zap.String("operation", val) }
    35  func CountField(val int) zap.Field                   { return zap.Int("count", val) }
    36  func IDField(val int) zap.Field                      { return zap.Int("id", val) }
    37  func ContextField(format string, a ...any) zap.Field { return FormatFiled("ctx", format, a...) }
    38  func EntityField(val any) zap.Field                  { return zap.Any("entity", val) }
    39  func ExceptionField(val any) zap.Field               { return zap.Any("exception", val) }
    40  func ErrorField(val error) zap.Field                 { return zap.Error(val) }
    41  func NameSpaceField(val string) zap.Field            { return zap.Namespace(val) }
    42  func OperandNameSpace() zap.Field                    { return zap.Namespace("operand") }
    43  func ReprerField(key string, val Reprer) zap.Field   { return zap.String(key, val.Repr()) }
    44  func OperandField(val any) zap.Field                 { return zap.Any("operand", val) }
    45  func FormatFiled(key string, format string, a ...any) zap.Field {
    46  	return zap.String(key, fmt.Sprintf(format, a...))
    47  }
    48  
    49  // func ObjectField(val any) zap.Field {
    50  // 	return zap.Object(val.(zapcore.ObjectMarshaler))
    51  // }