gf/g/os/glog/glog_logger_api.go

217 lines
6.2 KiB
Go
Raw Normal View History

2019-05-22 09:19:21 +08:00
// Copyright 2017 gf Author(https://github.com/gogf/gf). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
package glog
import (
"fmt"
"os"
)
// Print prints <v> with newline using fmt.Sprintln.
2019-06-11 20:57:43 +08:00
// The parameter <v> can be multiple variables.
2019-06-01 11:01:57 +08:00
func (l *Logger) Print(v...interface{}) {
2019-06-01 22:36:12 +08:00
l.printStd("", v...)
2019-05-22 09:19:21 +08:00
}
// Printf prints <v> with format <format> using fmt.Sprintf.
2019-06-11 20:57:43 +08:00
// The parameter <v> can be multiple variables.
2019-06-01 11:01:57 +08:00
func (l *Logger) Printf(format string, v...interface{}) {
2019-06-01 22:36:12 +08:00
l.printStd(l.format(format, v...))
2019-05-22 09:19:21 +08:00
}
// See Print.
2019-06-01 11:01:57 +08:00
func (l *Logger) Println(v...interface{}) {
2019-05-22 09:19:21 +08:00
l.Print(v...)
}
// Deprecated.
// Use Printf instead.
2019-06-01 11:01:57 +08:00
func (l *Logger) Printfln(format string, v...interface{}) {
2019-06-01 22:36:12 +08:00
l.printStd(l.format(format, v...))
2019-05-22 09:19:21 +08:00
}
// Fatal prints the logging content with [FATA] header and newline, then exit the current process.
2019-06-01 11:01:57 +08:00
func (l *Logger) Fatal(v...interface{}) {
2019-06-01 22:36:12 +08:00
l.printErr("[FATA]", v...)
2019-05-22 09:19:21 +08:00
os.Exit(1)
}
// Fatalf prints the logging content with [FATA] header, custom format and newline, then exit the current process.
2019-06-01 11:01:57 +08:00
func (l *Logger) Fatalf(format string, v...interface{}) {
2019-06-01 22:36:12 +08:00
l.printErr("[FATA]", l.format(format, v...))
2019-05-22 09:19:21 +08:00
os.Exit(1)
}
// Deprecated.
// Use Fatalf instead.
2019-06-01 11:01:57 +08:00
func (l *Logger) Fatalfln(format string, v...interface{}) {
l.Fatalf(format, v...)
2019-05-22 09:19:21 +08:00
os.Exit(1)
}
// Panic prints the logging content with [PANI] header and newline, then panics.
2019-06-01 11:01:57 +08:00
func (l *Logger) Panic(v...interface{}) {
2019-06-01 22:36:12 +08:00
l.printErr("[PANI]", v...)
2019-06-01 11:01:57 +08:00
panic(fmt.Sprint(v...))
2019-05-22 09:19:21 +08:00
}
// Panicf prints the logging content with [PANI] header, custom format and newline, then panics.
2019-06-01 11:01:57 +08:00
func (l *Logger) Panicf(format string, v...interface{}) {
2019-06-01 22:36:12 +08:00
l.printErr("[PANI]", l.format(format, v...))
panic(l.format(format, v...))
2019-05-22 09:19:21 +08:00
}
// Deprecated.
// Use Panicf instead.
2019-06-01 11:01:57 +08:00
func (l *Logger) Panicfln(format string, v...interface{}) {
l.Panicf(format, v...)
2019-05-22 09:19:21 +08:00
}
// Info prints the logging content with [INFO] header and newline.
2019-06-01 11:01:57 +08:00
func (l *Logger) Info(v...interface{}) {
2019-05-22 09:19:21 +08:00
if l.checkLevel(LEVEL_INFO) {
2019-06-01 22:36:12 +08:00
l.printStd("[INFO]", v...)
2019-05-22 09:19:21 +08:00
}
}
// Infof prints the logging content with [INFO] header, custom format and newline.
2019-06-01 11:01:57 +08:00
func (l *Logger) Infof(format string, v...interface{}) {
2019-05-22 09:19:21 +08:00
if l.checkLevel(LEVEL_INFO) {
2019-06-01 22:36:12 +08:00
l.printStd("[INFO]", l.format(format, v...))
2019-05-22 09:19:21 +08:00
}
}
// Deprecated.
// Use Infof instead.
2019-06-01 11:01:57 +08:00
func (l *Logger) Infofln(format string, v...interface{}) {
2019-05-22 09:19:21 +08:00
if l.checkLevel(LEVEL_INFO) {
2019-06-01 11:01:57 +08:00
l.Infof(format, v...)
2019-05-22 09:19:21 +08:00
}
}
// Debug prints the logging content with [DEBU] header and newline.
2019-06-01 11:01:57 +08:00
func (l *Logger) Debug(v...interface{}) {
2019-05-22 09:19:21 +08:00
if l.checkLevel(LEVEL_DEBU) {
2019-06-01 22:36:12 +08:00
l.printStd("[DEBU]", v...)
2019-05-22 09:19:21 +08:00
}
}
// Debugf prints the logging content with [DEBU] header, custom format and newline.
2019-06-01 11:01:57 +08:00
func (l *Logger) Debugf(format string, v...interface{}) {
2019-05-22 09:19:21 +08:00
if l.checkLevel(LEVEL_DEBU) {
2019-06-01 22:36:12 +08:00
l.printStd("[DEBU]", l.format(format, v...))
2019-05-22 09:19:21 +08:00
}
}
// Deprecated.
// Use Debugf instead.
2019-06-01 11:01:57 +08:00
func (l *Logger) Debugfln(format string, v...interface{}) {
2019-05-22 09:19:21 +08:00
if l.checkLevel(LEVEL_DEBU) {
2019-06-01 11:01:57 +08:00
l.Debugf(format, v...)
2019-05-22 09:19:21 +08:00
}
}
// Notice prints the logging content with [NOTI] header and newline.
// It also prints caller backtrace info if backtrace feature is enabled.
2019-06-01 11:01:57 +08:00
func (l *Logger) Notice(v...interface{}) {
2019-05-22 09:19:21 +08:00
if l.checkLevel(LEVEL_NOTI) {
2019-06-01 22:36:12 +08:00
l.printErr("[NOTI]", v...)
2019-05-22 09:19:21 +08:00
}
}
// Noticef prints the logging content with [NOTI] header, custom format and newline.
2019-05-22 09:19:21 +08:00
// It also prints caller backtrace info if backtrace feature is enabled.
2019-06-01 11:01:57 +08:00
func (l *Logger) Noticef(format string, v...interface{}) {
2019-05-22 09:19:21 +08:00
if l.checkLevel(LEVEL_NOTI) {
2019-06-01 22:36:12 +08:00
l.printErr("[NOTI]", l.format(format, v...))
2019-05-22 09:19:21 +08:00
}
}
// Deprecated.
// Use Noticef instead.
2019-06-01 11:01:57 +08:00
func (l *Logger) Noticefln(format string, v...interface{}) {
2019-05-22 09:19:21 +08:00
if l.checkLevel(LEVEL_NOTI) {
2019-06-01 11:01:57 +08:00
l.Noticef(format, v...)
2019-05-22 09:19:21 +08:00
}
}
// Warning prints the logging content with [WARN] header and newline.
// It also prints caller backtrace info if backtrace feature is enabled.
2019-06-01 11:01:57 +08:00
func (l *Logger) Warning(v...interface{}) {
2019-05-22 09:19:21 +08:00
if l.checkLevel(LEVEL_WARN) {
2019-06-01 22:36:12 +08:00
l.printErr("[WARN]", v...)
2019-05-22 09:19:21 +08:00
}
}
// Warningf prints the logging content with [WARN] header, custom format and newline.
2019-05-22 09:19:21 +08:00
// It also prints caller backtrace info if backtrace feature is enabled.
2019-06-01 11:01:57 +08:00
func (l *Logger) Warningf(format string, v...interface{}) {
2019-05-22 09:19:21 +08:00
if l.checkLevel(LEVEL_WARN) {
2019-06-01 22:36:12 +08:00
l.printErr("[WARN]", l.format(format, v...))
2019-05-22 09:19:21 +08:00
}
}
// Deprecated.
// Use Warningf instead.
2019-06-01 11:01:57 +08:00
func (l *Logger) Warningfln(format string, v...interface{}) {
2019-05-22 09:19:21 +08:00
if l.checkLevel(LEVEL_WARN) {
2019-06-01 11:01:57 +08:00
l.Warningf(format, v...)
2019-05-22 09:19:21 +08:00
}
}
// Error prints the logging content with [ERRO] header and newline.
// It also prints caller backtrace info if backtrace feature is enabled.
2019-06-01 11:01:57 +08:00
func (l *Logger) Error(v...interface{}) {
2019-05-22 09:19:21 +08:00
if l.checkLevel(LEVEL_ERRO) {
2019-06-01 22:36:12 +08:00
l.printErr("[ERRO]", v...)
2019-05-22 09:19:21 +08:00
}
}
// Errorf prints the logging content with [ERRO] header, custom format and newline.
2019-05-22 09:19:21 +08:00
// It also prints caller backtrace info if backtrace feature is enabled.
2019-06-01 11:01:57 +08:00
func (l *Logger) Errorf(format string, v...interface{}) {
2019-05-22 09:19:21 +08:00
if l.checkLevel(LEVEL_ERRO) {
2019-06-01 22:36:12 +08:00
l.printErr("[ERRO]", l.format(format, v...))
2019-05-22 09:19:21 +08:00
}
}
// Deprecated.
// Use Errorf instead.
2019-06-01 11:01:57 +08:00
func (l *Logger) Errorfln(format string, v...interface{}) {
2019-05-22 09:19:21 +08:00
if l.checkLevel(LEVEL_ERRO) {
2019-06-01 11:01:57 +08:00
l.Errorf(format, v...)
2019-05-22 09:19:21 +08:00
}
}
// Critical prints the logging content with [CRIT] header and newline.
// It also prints caller backtrace info if backtrace feature is enabled.
2019-06-01 11:01:57 +08:00
func (l *Logger) Critical(v...interface{}) {
2019-05-22 09:19:21 +08:00
if l.checkLevel(LEVEL_CRIT) {
2019-06-01 22:36:12 +08:00
l.printErr("[CRIT]", v...)
2019-05-22 09:19:21 +08:00
}
}
// Criticalf prints the logging content with [CRIT] header, custom format and newline.
2019-05-22 09:19:21 +08:00
// It also prints caller backtrace info if backtrace feature is enabled.
2019-06-01 11:01:57 +08:00
func (l *Logger) Criticalf(format string, v...interface{}) {
2019-05-22 09:19:21 +08:00
if l.checkLevel(LEVEL_CRIT) {
2019-06-01 22:36:12 +08:00
l.printErr("[CRIT]", l.format(format, v...))
2019-05-22 09:19:21 +08:00
}
}
// Deprecated.
// Use Criticalf instead.
2019-06-01 11:01:57 +08:00
func (l *Logger) Criticalfln(format string, v...interface{}) {
2019-05-22 09:19:21 +08:00
if l.checkLevel(LEVEL_CRIT) {
2019-06-01 11:01:57 +08:00
l.Criticalf(format, v...)
2019-05-22 09:19:21 +08:00
}
}
// checkLevel checks whether the given <level> could be output.
func (l *Logger) checkLevel(level int) bool {
return l.level & level > 0
}