pkg.re/essentialkaos/ek.10@v12.41.0+incompatible/log/std.go (about)

     1  package log
     2  
     3  // ////////////////////////////////////////////////////////////////////////////////// //
     4  //                                                                                    //
     5  //                         Copyright (c) 2022 ESSENTIAL KAOS                          //
     6  //      Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0>     //
     7  //                                                                                    //
     8  // ////////////////////////////////////////////////////////////////////////////////// //
     9  
    10  import (
    11  	"fmt"
    12  	"os"
    13  )
    14  
    15  // ////////////////////////////////////////////////////////////////////////////////// //
    16  
    17  // StdLogger is logger wrapper compatible with stdlib logger
    18  type StdLogger struct {
    19  	Logger *Logger
    20  }
    21  
    22  // ////////////////////////////////////////////////////////////////////////////////// //
    23  
    24  var (
    25  	stdExitFunc  = func(code int) { os.Exit(code) }
    26  	stdPanicFunc = func(message string) { panic(message) }
    27  )
    28  
    29  // ////////////////////////////////////////////////////////////////////////////////// //
    30  
    31  // Fatal is analog of Fatal from stdlib
    32  func (l *StdLogger) Fatal(v ...interface{}) {
    33  	l.Logger.Print(CRIT, fmt.Sprint(v...))
    34  	stdExitFunc(1)
    35  }
    36  
    37  // Fatalf is analog of Fatalf from stdlib
    38  func (l *StdLogger) Fatalf(format string, v ...interface{}) {
    39  	l.Logger.Print(CRIT, fmt.Sprintf(format, v...))
    40  	stdExitFunc(1)
    41  }
    42  
    43  // Fatalln is analog of Fatalln from stdlib
    44  func (l *StdLogger) Fatalln(v ...interface{}) {
    45  	l.Logger.Print(CRIT, fmt.Sprintln(v...))
    46  	stdExitFunc(1)
    47  }
    48  
    49  // Output is analog of Output from stdlib
    50  func (l *StdLogger) Output(calldepth int, s string) error {
    51  	return l.Logger.Print(INFO, s)
    52  }
    53  
    54  // Panic is analog of Panic from stdlib
    55  func (l *StdLogger) Panic(v ...interface{}) {
    56  	s := fmt.Sprint(v...)
    57  	l.Logger.Print(CRIT, s)
    58  	stdPanicFunc(s)
    59  }
    60  
    61  // Panicf is analog of Panicf from stdlib
    62  func (l *StdLogger) Panicf(format string, v ...interface{}) {
    63  	s := fmt.Sprintf(format, v...)
    64  	l.Logger.Print(CRIT, s)
    65  	stdPanicFunc(s)
    66  }
    67  
    68  // Panicln is analog of Panicln from stdlib
    69  func (l *StdLogger) Panicln(v ...interface{}) {
    70  	s := fmt.Sprintln(v...)
    71  	l.Logger.Print(CRIT, s)
    72  	stdPanicFunc(s)
    73  }
    74  
    75  // Print is analog of Print from stdlib
    76  func (l *StdLogger) Print(v ...interface{}) {
    77  	l.Logger.Print(INFO, fmt.Sprint(v...))
    78  }
    79  
    80  // Printf is analog of Printf from stdlib
    81  func (l *StdLogger) Printf(format string, v ...interface{}) {
    82  	l.Logger.Print(INFO, fmt.Sprintf(format, v...))
    83  }
    84  
    85  // Println is analog of Println from stdlib
    86  func (l *StdLogger) Println(v ...interface{}) {
    87  	l.Logger.Print(INFO, fmt.Sprintln(v...))
    88  }