Files
gf/os/glog/glog_logger_api.go

152 lines
5.1 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-19 09:06:52 +08:00
func (l *Logger) Print(v ...interface{}) {
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-19 09:06:52 +08:00
func (l *Logger) Printf(format string, v ...interface{}) {
2019-07-26 22:33:49 +08:00
l.printStd("", l.format(format, v...))
2019-05-22 09:19:21 +08:00
}
2020-02-26 23:26:24 +08:00
// Println is alias of Print.
2019-05-22 09:19:21 +08:00
// See Print.
2019-06-19 09:06:52 +08:00
func (l *Logger) Println(v ...interface{}) {
l.Print(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-19 09:06:52 +08:00
func (l *Logger) Fatal(v ...interface{}) {
2020-02-26 23:26:24 +08:00
l.printErr(l.getLevelPrefixWithBrackets(LEVEL_FATA), v...)
2019-06-19 09:06:52 +08:00
os.Exit(1)
2019-05-22 09:19:21 +08:00
}
// Fatalf prints the logging content with [FATA] header, custom format and newline, then exit the current process.
2019-06-19 09:06:52 +08:00
func (l *Logger) Fatalf(format string, v ...interface{}) {
2020-02-26 23:26:24 +08:00
l.printErr(l.getLevelPrefixWithBrackets(LEVEL_FATA), l.format(format, v...))
2019-06-19 09:06:52 +08:00
os.Exit(1)
2019-05-22 09:19:21 +08:00
}
// Panic prints the logging content with [PANI] header and newline, then panics.
2019-06-19 09:06:52 +08:00
func (l *Logger) Panic(v ...interface{}) {
2020-02-26 23:26:24 +08:00
l.printErr(l.getLevelPrefixWithBrackets(LEVEL_PANI), v...)
2019-06-19 09:06:52 +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-19 09:06:52 +08:00
func (l *Logger) Panicf(format string, v ...interface{}) {
2020-02-26 23:26:24 +08:00
l.printErr(l.getLevelPrefixWithBrackets(LEVEL_PANI), l.format(format, v...))
2019-06-19 09:06:52 +08:00
panic(l.format(format, v...))
2019-05-22 09:19:21 +08:00
}
// Info prints the logging content with [INFO] header and newline.
2019-06-19 09:06:52 +08:00
func (l *Logger) Info(v ...interface{}) {
if l.checkLevel(LEVEL_INFO) {
2020-02-26 23:26:24 +08:00
l.printStd(l.getLevelPrefixWithBrackets(LEVEL_INFO), v...)
2019-06-19 09:06:52 +08:00
}
2019-05-22 09:19:21 +08:00
}
// Infof prints the logging content with [INFO] header, custom format and newline.
2019-06-19 09:06:52 +08:00
func (l *Logger) Infof(format string, v ...interface{}) {
if l.checkLevel(LEVEL_INFO) {
2020-02-26 23:26:24 +08:00
l.printStd(l.getLevelPrefixWithBrackets(LEVEL_INFO), l.format(format, v...))
2019-06-19 09:06:52 +08:00
}
2019-05-22 09:19:21 +08:00
}
// Debug prints the logging content with [DEBU] header and newline.
2019-06-19 09:06:52 +08:00
func (l *Logger) Debug(v ...interface{}) {
if l.checkLevel(LEVEL_DEBU) {
2020-02-26 23:26:24 +08:00
l.printStd(l.getLevelPrefixWithBrackets(LEVEL_DEBU), v...)
2019-06-19 09:06:52 +08:00
}
2019-05-22 09:19:21 +08:00
}
// Debugf prints the logging content with [DEBU] header, custom format and newline.
2019-06-19 09:06:52 +08:00
func (l *Logger) Debugf(format string, v ...interface{}) {
if l.checkLevel(LEVEL_DEBU) {
2020-02-26 23:26:24 +08:00
l.printStd(l.getLevelPrefixWithBrackets(LEVEL_DEBU), l.format(format, v...))
2019-06-19 09:06:52 +08:00
}
2019-05-22 09:19:21 +08:00
}
// Notice prints the logging content with [NOTI] header and newline.
// It also prints caller stack info if stack feature is enabled.
2019-06-19 09:06:52 +08:00
func (l *Logger) Notice(v ...interface{}) {
if l.checkLevel(LEVEL_NOTI) {
2020-02-26 23:26:24 +08:00
l.printStd(l.getLevelPrefixWithBrackets(LEVEL_NOTI), v...)
2019-06-19 09:06:52 +08:00
}
2019-05-22 09:19:21 +08:00
}
// Noticef prints the logging content with [NOTI] header, custom format and newline.
// It also prints caller stack info if stack feature is enabled.
2019-06-19 09:06:52 +08:00
func (l *Logger) Noticef(format string, v ...interface{}) {
if l.checkLevel(LEVEL_NOTI) {
2020-02-26 23:26:24 +08:00
l.printStd(l.getLevelPrefixWithBrackets(LEVEL_NOTI), l.format(format, v...))
2019-06-19 09:06:52 +08:00
}
2019-05-22 09:19:21 +08:00
}
// Warning prints the logging content with [WARN] header and newline.
// It also prints caller stack info if stack feature is enabled.
2019-06-19 09:06:52 +08:00
func (l *Logger) Warning(v ...interface{}) {
if l.checkLevel(LEVEL_WARN) {
2020-02-26 23:26:24 +08:00
l.printStd(l.getLevelPrefixWithBrackets(LEVEL_WARN), v...)
2019-06-19 09:06:52 +08:00
}
2019-05-22 09:19:21 +08:00
}
// Warningf prints the logging content with [WARN] header, custom format and newline.
// It also prints caller stack info if stack feature is enabled.
2019-06-19 09:06:52 +08:00
func (l *Logger) Warningf(format string, v ...interface{}) {
if l.checkLevel(LEVEL_WARN) {
2020-02-26 23:26:24 +08:00
l.printStd(l.getLevelPrefixWithBrackets(LEVEL_WARN), l.format(format, v...))
2019-06-19 09:06:52 +08:00
}
2019-05-22 09:19:21 +08:00
}
// Error prints the logging content with [ERRO] header and newline.
// It also prints caller stack info if stack feature is enabled.
2019-06-19 09:06:52 +08:00
func (l *Logger) Error(v ...interface{}) {
if l.checkLevel(LEVEL_ERRO) {
2020-02-26 23:26:24 +08:00
l.printErr(l.getLevelPrefixWithBrackets(LEVEL_ERRO), v...)
2019-06-19 09:06:52 +08:00
}
2019-05-22 09:19:21 +08:00
}
// Errorf prints the logging content with [ERRO] header, custom format and newline.
// It also prints caller stack info if stack feature is enabled.
2019-06-19 09:06:52 +08:00
func (l *Logger) Errorf(format string, v ...interface{}) {
if l.checkLevel(LEVEL_ERRO) {
2020-02-26 23:26:24 +08:00
l.printErr(l.getLevelPrefixWithBrackets(LEVEL_ERRO), l.format(format, v...))
2019-06-19 09:06:52 +08:00
}
2019-05-22 09:19:21 +08:00
}
// Critical prints the logging content with [CRIT] header and newline.
// It also prints caller stack info if stack feature is enabled.
2019-06-19 09:06:52 +08:00
func (l *Logger) Critical(v ...interface{}) {
if l.checkLevel(LEVEL_CRIT) {
2020-02-26 23:26:24 +08:00
l.printErr(l.getLevelPrefixWithBrackets(LEVEL_CRIT), v...)
2019-06-19 09:06:52 +08:00
}
2019-05-22 09:19:21 +08:00
}
// Criticalf prints the logging content with [CRIT] header, custom format and newline.
// It also prints caller stack info if stack feature is enabled.
2019-06-19 09:06:52 +08:00
func (l *Logger) Criticalf(format string, v ...interface{}) {
if l.checkLevel(LEVEL_CRIT) {
2020-02-26 23:26:24 +08:00
l.printErr(l.getLevelPrefixWithBrackets(LEVEL_CRIT), l.format(format, v...))
2019-06-19 09:06:52 +08:00
}
2019-05-22 09:19:21 +08:00
}
// checkLevel checks whether the given <level> could be output.
func (l *Logger) checkLevel(level int) bool {
2019-10-26 10:58:07 +08:00
return l.config.Level&level > 0
2019-06-19 09:06:52 +08:00
}