gitee.com/zhaochuninhefei/gmgo@v0.0.31-0.20240209061119-069254a02979/go-control-plane/internal/example/logger.go (about)

     1  // Copyright 2020 Envoyproxy Authors
     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 example
    16  
    17  import (
    18  	"log"
    19  )
    20  
    21  // Logger An example of a logger that implements `pkg/log/Logger`.  Logs to
    22  // stdout.  If Debug == false then Debugf() and Infof() won't output
    23  // anything.
    24  type Logger struct {
    25  	Debug bool
    26  }
    27  
    28  // Debugf Log to stdout only if Debug is true.
    29  func (logger Logger) Debugf(format string, args ...interface{}) {
    30  	if logger.Debug {
    31  		log.Printf(format+"\n", args...)
    32  	}
    33  }
    34  
    35  // Infof Log to stdout only if Debug is true.
    36  func (logger Logger) Infof(format string, args ...interface{}) {
    37  	if logger.Debug {
    38  		log.Printf(format+"\n", args...)
    39  	}
    40  }
    41  
    42  // Warnf Log to stdout always.
    43  func (logger Logger) Warnf(format string, args ...interface{}) {
    44  	log.Printf(format+"\n", args...)
    45  }
    46  
    47  // Errorf Log to stdout always.
    48  func (logger Logger) Errorf(format string, args ...interface{}) {
    49  	log.Printf(format+"\n", args...)
    50  }