github.com/matrixorigin/matrixone@v1.2.0/pkg/logutil/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 logutil
    16  
    17  import (
    18  	"errors"
    19  	"fmt"
    20  	"io"
    21  
    22  	"go.uber.org/zap"
    23  )
    24  
    25  func ConnectionIdField(val uint32) zap.Field { return zap.Uint32("connection_id", val) }
    26  func QueryField(val string) zap.Field        { return zap.String("query", val) }
    27  func StatementField(val string) zap.Field    { return zap.String("statement", val) }
    28  func VarsField(val string) zap.Field         { return zap.String("vars", val) }
    29  func StatusField(val string) zap.Field       { return zap.String("status", val) }
    30  func TableField(val string) zap.Field        { return zap.String("table", val) } // table name
    31  func PathField(val string) zap.Field         { return zap.String("path", val) }
    32  
    33  func NoReportFiled() zap.Field { return zap.Bool(MOInternalFiledKeyNoopReport, true) }
    34  func Discardable() zap.Field   { return zap.Bool(MOInternalFiledKeyDiscardable, true) }
    35  
    36  func ErrorField(err error) zap.Field {
    37  	if isDisallowedError(err) {
    38  		panic(fmt.Sprintf("this error should not be logged: %v", err))
    39  	}
    40  	return zap.Error(err)
    41  }
    42  
    43  func isDisallowedError(err error) bool {
    44  	switch {
    45  	case errors.Is(err, io.EOF):
    46  		// io.EOF should be handled by the caller, should never be logged
    47  		return true
    48  	}
    49  	return false
    50  }