github.com/gogf/gf@v1.16.9/os/glog/glog_logger_api.go (about) 1 // Copyright GoFrame Author(https://goframe.org). 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/gogf/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(LEVEL_NONE, 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(LEVEL_NONE, l.format(format, v...)) 24 } 25 26 // Println is alias of Print. 27 // See Print. 28 func (l *Logger) Println(v ...interface{}) { 29 l.Print(v...) 30 } 31 32 // Fatal prints the logging content with [FATA] header and newline, then exit the current process. 33 func (l *Logger) Fatal(v ...interface{}) { 34 l.printErr(LEVEL_FATA, v...) 35 os.Exit(1) 36 } 37 38 // Fatalf prints the logging content with [FATA] header, custom format and newline, then exit the current process. 39 func (l *Logger) Fatalf(format string, v ...interface{}) { 40 l.printErr(LEVEL_FATA, l.format(format, v...)) 41 os.Exit(1) 42 } 43 44 // Panic prints the logging content with [PANI] header and newline, then panics. 45 func (l *Logger) Panic(v ...interface{}) { 46 l.printErr(LEVEL_PANI, v...) 47 panic(fmt.Sprint(v...)) 48 } 49 50 // Panicf prints the logging content with [PANI] header, custom format and newline, then panics. 51 func (l *Logger) Panicf(format string, v ...interface{}) { 52 l.printErr(LEVEL_PANI, l.format(format, v...)) 53 panic(l.format(format, v...)) 54 } 55 56 // Info prints the logging content with [INFO] header and newline. 57 func (l *Logger) Info(v ...interface{}) { 58 if l.checkLevel(LEVEL_INFO) { 59 l.printStd(LEVEL_INFO, v...) 60 } 61 } 62 63 // Infof prints the logging content with [INFO] header, custom format and newline. 64 func (l *Logger) Infof(format string, v ...interface{}) { 65 if l.checkLevel(LEVEL_INFO) { 66 l.printStd(LEVEL_INFO, l.format(format, v...)) 67 } 68 } 69 70 // Debug prints the logging content with [DEBU] header and newline. 71 func (l *Logger) Debug(v ...interface{}) { 72 if l.checkLevel(LEVEL_DEBU) { 73 l.printStd(LEVEL_DEBU, v...) 74 } 75 } 76 77 // Debugf prints the logging content with [DEBU] header, custom format and newline. 78 func (l *Logger) Debugf(format string, v ...interface{}) { 79 if l.checkLevel(LEVEL_DEBU) { 80 l.printStd(LEVEL_DEBU, l.format(format, v...)) 81 } 82 } 83 84 // Notice prints the logging content with [NOTI] header and newline. 85 // It also prints caller stack info if stack feature is enabled. 86 func (l *Logger) Notice(v ...interface{}) { 87 if l.checkLevel(LEVEL_NOTI) { 88 l.printStd(LEVEL_NOTI, v...) 89 } 90 } 91 92 // Noticef prints the logging content with [NOTI] header, custom format and newline. 93 // It also prints caller stack info if stack feature is enabled. 94 func (l *Logger) Noticef(format string, v ...interface{}) { 95 if l.checkLevel(LEVEL_NOTI) { 96 l.printStd(LEVEL_NOTI, l.format(format, v...)) 97 } 98 } 99 100 // Warning prints the logging content with [WARN] header and newline. 101 // It also prints caller stack info if stack feature is enabled. 102 func (l *Logger) Warning(v ...interface{}) { 103 if l.checkLevel(LEVEL_WARN) { 104 l.printStd(LEVEL_WARN, v...) 105 } 106 } 107 108 // Warningf prints the logging content with [WARN] header, custom format and newline. 109 // It also prints caller stack info if stack feature is enabled. 110 func (l *Logger) Warningf(format string, v ...interface{}) { 111 if l.checkLevel(LEVEL_WARN) { 112 l.printStd(LEVEL_WARN, l.format(format, v...)) 113 } 114 } 115 116 // Error prints the logging content with [ERRO] header and newline. 117 // It also prints caller stack info if stack feature is enabled. 118 func (l *Logger) Error(v ...interface{}) { 119 if l.checkLevel(LEVEL_ERRO) { 120 l.printErr(LEVEL_ERRO, v...) 121 } 122 } 123 124 // Errorf prints the logging content with [ERRO] header, custom format and newline. 125 // It also prints caller stack info if stack feature is enabled. 126 func (l *Logger) Errorf(format string, v ...interface{}) { 127 if l.checkLevel(LEVEL_ERRO) { 128 l.printErr(LEVEL_ERRO, l.format(format, v...)) 129 } 130 } 131 132 // Critical prints the logging content with [CRIT] header and newline. 133 // It also prints caller stack info if stack feature is enabled. 134 func (l *Logger) Critical(v ...interface{}) { 135 if l.checkLevel(LEVEL_CRIT) { 136 l.printErr(LEVEL_CRIT, v...) 137 } 138 } 139 140 // Criticalf prints the logging content with [CRIT] header, custom format and newline. 141 // It also prints caller stack info if stack feature is enabled. 142 func (l *Logger) Criticalf(format string, v ...interface{}) { 143 if l.checkLevel(LEVEL_CRIT) { 144 l.printErr(LEVEL_CRIT, l.format(format, v...)) 145 } 146 } 147 148 // checkLevel checks whether the given `level` could be output. 149 func (l *Logger) checkLevel(level int) bool { 150 return l.config.Level&level > 0 151 }