vitess.io/vitess@v0.16.2/go/vt/logutil/console_logger.go (about) 1 /* 2 Copyright 2019 The Vitess Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package logutil 18 19 import ( 20 "fmt" 21 22 "vitess.io/vitess/go/vt/log" 23 ) 24 25 // ConsoleLogger is a Logger that uses glog directly to log, at the right level. 26 // 27 // Note that methods on ConsoleLogger must use pointer receivers, 28 // because otherwise an autogenerated conversion method will be inserted in the 29 // call stack when ConsoleLogger is used via TeeLogger, making the log depth 30 // incorrect. 31 type ConsoleLogger struct{} 32 33 // NewConsoleLogger returns a simple ConsoleLogger. 34 func NewConsoleLogger() *ConsoleLogger { 35 return &ConsoleLogger{} 36 } 37 38 // Infof is part of the Logger interface 39 func (cl *ConsoleLogger) Infof(format string, v ...any) { 40 cl.InfoDepth(1, fmt.Sprintf(format, v...)) 41 } 42 43 // Warningf is part of the Logger interface 44 func (cl *ConsoleLogger) Warningf(format string, v ...any) { 45 cl.WarningDepth(1, fmt.Sprintf(format, v...)) 46 } 47 48 // Errorf is part of the Logger interface 49 func (cl *ConsoleLogger) Errorf(format string, v ...any) { 50 cl.ErrorDepth(1, fmt.Sprintf(format, v...)) 51 } 52 53 // Errorf2 is part of the Logger interface 54 func (cl *ConsoleLogger) Errorf2(err error, format string, v ...any) { 55 cl.ErrorDepth(1, fmt.Sprintf(format+": %+v", append(v, err))) 56 } 57 58 // Error is part of the Logger interface 59 func (cl *ConsoleLogger) Error(err error) { 60 cl.ErrorDepth(1, fmt.Sprintf("%+v", err)) 61 } 62 63 // Printf is part of the Logger interface 64 func (cl *ConsoleLogger) Printf(format string, v ...any) { 65 fmt.Printf(format, v...) 66 } 67 68 // InfoDepth is part of the Logger interface. 69 func (cl *ConsoleLogger) InfoDepth(depth int, s string) { 70 log.InfoDepth(1+depth, s) 71 } 72 73 // WarningDepth is part of the Logger interface. 74 func (cl *ConsoleLogger) WarningDepth(depth int, s string) { 75 log.WarningDepth(1+depth, s) 76 } 77 78 // ErrorDepth is part of the Logger interface. 79 func (cl *ConsoleLogger) ErrorDepth(depth int, s string) { 80 log.ErrorDepth(1+depth, s) 81 }