github.com/zhongdalu/gf@v1.0.0/g/os/glog/glog_logger_api.go (about)

     1  // Copyright 2017 gf Author(https://github.com/zhongdalu/gf). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/zhongdalu/gf.
     6  
     7  package glog
     8  
     9  import (
    10  	"fmt"
    11  	"os"
    12  )
    13  
    14  // Print prints <v> with newline using fmt.Sprintln.
    15  // The parameter <v> can be multiple variables.
    16  func (l *Logger) Print(v ...interface{}) {
    17  	l.printStd("", v...)
    18  }
    19  
    20  // Printf prints <v> with format <format> using fmt.Sprintf.
    21  // The parameter <v> can be multiple variables.
    22  func (l *Logger) Printf(format string, v ...interface{}) {
    23  	l.printStd(l.format(format, v...))
    24  }
    25  
    26  // See Print.
    27  func (l *Logger) Println(v ...interface{}) {
    28  	l.Print(v...)
    29  }
    30  
    31  // Deprecated.
    32  // Use Printf instead.
    33  func (l *Logger) Printfln(format string, v ...interface{}) {
    34  	l.printStd(l.format(format, v...))
    35  }
    36  
    37  // Fatal prints the logging content with [FATA] header and newline, then exit the current process.
    38  func (l *Logger) Fatal(v ...interface{}) {
    39  	l.printErr("[FATA]", v...)
    40  	os.Exit(1)
    41  }
    42  
    43  // Fatalf prints the logging content with [FATA] header, custom format and newline, then exit the current process.
    44  func (l *Logger) Fatalf(format string, v ...interface{}) {
    45  	l.printErr("[FATA]", l.format(format, v...))
    46  	os.Exit(1)
    47  }
    48  
    49  // Deprecated.
    50  // Use Fatalf instead.
    51  func (l *Logger) Fatalfln(format string, v ...interface{}) {
    52  	l.Fatalf(format, v...)
    53  	os.Exit(1)
    54  }
    55  
    56  // Panic prints the logging content with [PANI] header and newline, then panics.
    57  func (l *Logger) Panic(v ...interface{}) {
    58  	l.printErr("[PANI]", v...)
    59  	panic(fmt.Sprint(v...))
    60  }
    61  
    62  // Panicf prints the logging content with [PANI] header, custom format and newline, then panics.
    63  func (l *Logger) Panicf(format string, v ...interface{}) {
    64  	l.printErr("[PANI]", l.format(format, v...))
    65  	panic(l.format(format, v...))
    66  }
    67  
    68  // Deprecated.
    69  // Use Panicf instead.
    70  func (l *Logger) Panicfln(format string, v ...interface{}) {
    71  	l.Panicf(format, v...)
    72  }
    73  
    74  // Info prints the logging content with [INFO] header and newline.
    75  func (l *Logger) Info(v ...interface{}) {
    76  	if l.checkLevel(LEVEL_INFO) {
    77  		l.printStd("[INFO]", v...)
    78  	}
    79  }
    80  
    81  // Infof prints the logging content with [INFO] header, custom format and newline.
    82  func (l *Logger) Infof(format string, v ...interface{}) {
    83  	if l.checkLevel(LEVEL_INFO) {
    84  		l.printStd("[INFO]", l.format(format, v...))
    85  	}
    86  }
    87  
    88  // Deprecated.
    89  // Use Infof instead.
    90  func (l *Logger) Infofln(format string, v ...interface{}) {
    91  	if l.checkLevel(LEVEL_INFO) {
    92  		l.Infof(format, v...)
    93  	}
    94  }
    95  
    96  // Debug prints the logging content with [DEBU] header and newline.
    97  func (l *Logger) Debug(v ...interface{}) {
    98  	if l.checkLevel(LEVEL_DEBU) {
    99  		l.printStd("[DEBU]", v...)
   100  	}
   101  }
   102  
   103  // Debugf prints the logging content with [DEBU] header, custom format and newline.
   104  func (l *Logger) Debugf(format string, v ...interface{}) {
   105  	if l.checkLevel(LEVEL_DEBU) {
   106  		l.printStd("[DEBU]", l.format(format, v...))
   107  	}
   108  }
   109  
   110  // Deprecated.
   111  // Use Debugf instead.
   112  func (l *Logger) Debugfln(format string, v ...interface{}) {
   113  	if l.checkLevel(LEVEL_DEBU) {
   114  		l.Debugf(format, v...)
   115  	}
   116  }
   117  
   118  // Notice prints the logging content with [NOTI] header and newline.
   119  // It also prints caller stack info if stack feature is enabled.
   120  func (l *Logger) Notice(v ...interface{}) {
   121  	if l.checkLevel(LEVEL_NOTI) {
   122  		l.printErr("[NOTI]", v...)
   123  	}
   124  }
   125  
   126  // Noticef prints the logging content with [NOTI] header, custom format and newline.
   127  // It also prints caller stack info if stack feature is enabled.
   128  func (l *Logger) Noticef(format string, v ...interface{}) {
   129  	if l.checkLevel(LEVEL_NOTI) {
   130  		l.printErr("[NOTI]", l.format(format, v...))
   131  	}
   132  }
   133  
   134  // Deprecated.
   135  // Use Noticef instead.
   136  func (l *Logger) Noticefln(format string, v ...interface{}) {
   137  	if l.checkLevel(LEVEL_NOTI) {
   138  		l.Noticef(format, v...)
   139  	}
   140  }
   141  
   142  // Warning prints the logging content with [WARN] header and newline.
   143  // It also prints caller stack info if stack feature is enabled.
   144  func (l *Logger) Warning(v ...interface{}) {
   145  	if l.checkLevel(LEVEL_WARN) {
   146  		l.printErr("[WARN]", v...)
   147  	}
   148  }
   149  
   150  // Warningf prints the logging content with [WARN] header, custom format and newline.
   151  // It also prints caller stack info if stack feature is enabled.
   152  func (l *Logger) Warningf(format string, v ...interface{}) {
   153  	if l.checkLevel(LEVEL_WARN) {
   154  		l.printErr("[WARN]", l.format(format, v...))
   155  	}
   156  }
   157  
   158  // Deprecated.
   159  // Use Warningf instead.
   160  func (l *Logger) Warningfln(format string, v ...interface{}) {
   161  	if l.checkLevel(LEVEL_WARN) {
   162  		l.Warningf(format, v...)
   163  	}
   164  }
   165  
   166  // Error prints the logging content with [ERRO] header and newline.
   167  // It also prints caller stack info if stack feature is enabled.
   168  func (l *Logger) Error(v ...interface{}) {
   169  	if l.checkLevel(LEVEL_ERRO) {
   170  		l.printErr("[ERRO]", v...)
   171  	}
   172  }
   173  
   174  // Errorf prints the logging content with [ERRO] header, custom format and newline.
   175  // It also prints caller stack info if stack feature is enabled.
   176  func (l *Logger) Errorf(format string, v ...interface{}) {
   177  	if l.checkLevel(LEVEL_ERRO) {
   178  		l.printErr("[ERRO]", l.format(format, v...))
   179  	}
   180  }
   181  
   182  // Deprecated.
   183  // Use Errorf instead.
   184  func (l *Logger) Errorfln(format string, v ...interface{}) {
   185  	if l.checkLevel(LEVEL_ERRO) {
   186  		l.Errorf(format, v...)
   187  	}
   188  }
   189  
   190  // Critical prints the logging content with [CRIT] header and newline.
   191  // It also prints caller stack info if stack feature is enabled.
   192  func (l *Logger) Critical(v ...interface{}) {
   193  	if l.checkLevel(LEVEL_CRIT) {
   194  		l.printErr("[CRIT]", v...)
   195  	}
   196  }
   197  
   198  // Criticalf prints the logging content with [CRIT] header, custom format and newline.
   199  // It also prints caller stack info if stack feature is enabled.
   200  func (l *Logger) Criticalf(format string, v ...interface{}) {
   201  	if l.checkLevel(LEVEL_CRIT) {
   202  		l.printErr("[CRIT]", l.format(format, v...))
   203  	}
   204  }
   205  
   206  // Deprecated.
   207  // Use Criticalf instead.
   208  func (l *Logger) Criticalfln(format string, v ...interface{}) {
   209  	if l.checkLevel(LEVEL_CRIT) {
   210  		l.Criticalf(format, v...)
   211  	}
   212  }
   213  
   214  // checkLevel checks whether the given <level> could be output.
   215  func (l *Logger) checkLevel(level int) bool {
   216  	return l.level&level > 0
   217  }