github.com/matrixorigin/matrixone@v1.2.0/pkg/common/log/types.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 log 16 17 import ( 18 "context" 19 "math" 20 21 "go.uber.org/zap" 22 "go.uber.org/zap/zapcore" 23 ) 24 25 // Module used to describe which component module the log belongs to 26 type Module string 27 28 var ( 29 // TxnClient txn client module 30 TxnClient = Module("txn-client") 31 ) 32 33 var ( 34 // FieldNameServiceUUID service uuid field name 35 FieldNameServiceUUID = "uuid" 36 // FieldNameProcess process of the mo, e.g. transaction 37 FieldNameProcess = "process" 38 // FieldNameProcessID the log of a processing process may be distributed in 39 // many places, we can search all the logs associated with the current process 40 // by process-id. For example, we can use the transaction ID as process-id to 41 // find all logs of this transaction in the cluster. 42 FieldNameProcessID = "process-id" 43 // FieldNameCost cost field name, this field is used to log how long a function, 44 // operation or other action takes 45 FieldNameCost = "cost" 46 ) 47 48 // Process used to describe which process the log belongs to. We can filter out all 49 // process-related logs by specifying the process field as the value to analyse the 50 // logs. 51 type Process string 52 53 var ( 54 // SystemInit system init process 55 SystemInit = Process("system-init") 56 // Txn transaction process 57 Txn = Process("txn") 58 // Close close serivce or components process. e.g. close cn/dn/log service 59 Close = Process("close") 60 ) 61 62 // SampleType there are some behaviours in the system that print debug logs frequently, 63 // such as the scheduling of HAKeeper, which may print hundreds of logs a second. What 64 // these logs do is that these behaviours are still happening at debug level. So we just 65 // need to sample the output. 66 type SampleType int 67 68 const ( 69 noneSample SampleType = iota 70 SystemInitSample 71 // ExampleSample used in examples 72 ExampleSample = math.MaxInt 73 ) 74 75 // MOLogger mo logger based zap.logger. To standardize and standardize the logging 76 // output of MO, the native zap.logger should not be used for logging in MO, but 77 // rather MOLogger. MOLogger is compatible with the zap.logger log printing method 78 // signature 79 type MOLogger struct { 80 logger *zap.Logger 81 ctx context.Context 82 m map[int]*zap.Logger 83 } 84 85 // LogOptions log options 86 type LogOptions struct { 87 ctx context.Context 88 level zapcore.Level 89 fields []zap.Field 90 sampleType SampleType 91 callerSkip int 92 } 93 94 // logFilter used to filter the print log, returns false to abort this print 95 type logFilter func(opts LogOptions) bool