github.com/aristanetworks/goarista@v0.0.0-20240514173732-cca2755bbd44/logger/logger.go (about)

     1  // Copyright (c) 2021 Arista Networks, Inc.
     2  // Use of this source code is governed by the Apache License 2.0
     3  // that can be found in the COPYING file.
     4  
     5  package logger
     6  
     7  import (
     8  	"fmt"
     9  	"log"
    10  )
    11  
    12  // Logger is an interface to pass a generic logger without depending on either golang/glog or
    13  // aristanetworks/glog
    14  type Logger interface {
    15  	// Info logs at the info level
    16  	Info(args ...interface{})
    17  	// Infof logs at the info level, with format
    18  	Infof(format string, args ...interface{})
    19  	// Error logs at the error level
    20  	Error(args ...interface{})
    21  	// Errorf logs at the error level, with format
    22  	Errorf(format string, args ...interface{})
    23  	// Fatal logs at the fatal level
    24  	Fatal(args ...interface{})
    25  	// Fatalf logs at the fatal level, with format
    26  	Fatalf(format string, args ...interface{})
    27  }
    28  
    29  // Std implements the logger interface using the stdlib "log" package.
    30  var Std Logger = std{log.Default()}
    31  
    32  type std struct {
    33  	*log.Logger
    34  }
    35  
    36  func (l std) Info(args ...interface{}) {
    37  	l.Output(2, fmt.Sprint(args...))
    38  }
    39  
    40  func (l std) Infof(format string, args ...interface{}) {
    41  	l.Output(2, fmt.Sprintf(format, args...))
    42  }
    43  
    44  func (l std) Error(args ...interface{}) {
    45  	l.Output(2, fmt.Sprint(args...))
    46  }
    47  
    48  func (l std) Errorf(format string, args ...interface{}) {
    49  	l.Output(2, fmt.Sprintf(format, args...))
    50  }