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