mark deprecated for *fln functions of glog; fix issue in gfile.MainPkgPath in Windows

This commit is contained in:
John
2019-05-29 15:18:12 +08:00
parent 945dd71251
commit 7335126064
5 changed files with 83 additions and 77 deletions

View File

@ -417,14 +417,16 @@ func MainPkgPath() string {
}
for i := 1; i < 10000; i++ {
if _, file, _, ok := runtime.Caller(i); ok {
// <file> is separated by '/'
if gstr.Contains(file, "/gf/g/") {
continue
}
if Ext(file) != ".go" {
continue
}
path = file
for path != "/" && gstr.Contains(path, "/") {
// separator of <file> '/' will be converted to Separator.
path = Dir(file)
for path != "/" && gstr.Contains(path, Separator) {
files, _ := ScanDir(path, "*.go")
for _, v := range files {
if gregex.IsMatchString(`package\s+main`, GetContents(v)) {

View File

@ -23,8 +23,8 @@ func Println(v ...interface{}) {
logger.Println(v ...)
}
// Printf prints <v> with newline and format <format> using fmt.Sprintf.
// The param <v> can be multiple variables.
// Deprecated.
// Use Printf instead.
func Printfln(format string, v ...interface{}) {
logger.Printfln(format, v ...)
}
@ -34,12 +34,13 @@ func Fatal(v ...interface{}) {
logger.Fatal(v ...)
}
// Fatalf prints the logging content with [FATA] header and custom format, then exit the current process.
// Fatalf prints the logging content with [FATA] header, custom format and newline, then exit the current process.
func Fatalf(format string, v ...interface{}) {
logger.Fatalf(format, v ...)
}
// Fatalf prints the logging content with [FATA] header, custom format and newline, then exit the current process.
// Deprecated.
// Use Fatalf instead.
func Fatalfln(format string, v ...interface{}) {
logger.Fatalfln(format, v ...)
}
@ -49,12 +50,13 @@ func Panic(v ...interface{}) {
logger.Panic(v ...)
}
// Panicf prints the logging content with [PANI] header and custom format, then panics.
// Panicf prints the logging content with [PANI] header, custom format and newline, then panics.
func Panicf(format string, v ...interface{}) {
logger.Panicf(format, v ...)
}
// Panicfln prints the logging content with [PANI] header, newline and custom format, then panics.
// Deprecated.
// Use Panicf instead.
func Panicfln(format string, v ...interface{}) {
logger.Panicfln(format, v ...)
}
@ -64,12 +66,13 @@ func Info(v ...interface{}) {
logger.Info(v...)
}
// Infof prints the logging content with [INFO] header and custom format.
// Infof prints the logging content with [INFO] header, custom format and newline.
func Infof(format string, v ...interface{}) {
logger.Infof(format, v...)
}
// Infofln prints the logging content with [INFO] header, newline and custom format.
// Deprecated.
// Use Infof instead.
func Infofln(format string, v ...interface{}) {
logger.Infofln(format, v...)
}
@ -79,12 +82,13 @@ func Debug(v ...interface{}) {
logger.Debug(v...)
}
// Debugf prints the logging content with [DEBU] header and custom format.
// Debugf prints the logging content with [DEBU] header, custom format and newline.
func Debugf(format string, v ...interface{}) {
logger.Debugf(format, v...)
}
// Debugfln prints the logging content with [DEBU] header, newline and custom format.
// Deprecated.
// Use Debugf instead.
func Debugfln(format string, v ...interface{}) {
logger.Debugfln(format, v...)
}
@ -95,14 +99,14 @@ func Notice(v ...interface{}) {
logger.Notice(v...)
}
// Noticef prints the logging content with [NOTI] header and custom format.
// Noticef prints the logging content with [NOTI] header, custom format and newline.
// It also prints caller backtrace info if backtrace feature is enabled.
func Noticef(format string, v ...interface{}) {
logger.Noticef(format, v...)
}
// Noticefln prints the logging content with [NOTI] header, newline and custom format.
// It also prints caller backtrace info if backtrace feature is enabled.
// Deprecated.
// Use Noticef instead.
func Noticefln(format string, v ...interface{}) {
logger.Noticefln(format, v...)
}
@ -113,14 +117,14 @@ func Warning(v ...interface{}) {
logger.Warning(v...)
}
// Warningf prints the logging content with [WARN] header and custom format.
// Warningf prints the logging content with [WARN] header, custom format and newline.
// It also prints caller backtrace info if backtrace feature is enabled.
func Warningf(format string, v ...interface{}) {
logger.Warningf(format, v...)
}
// Warningfln prints the logging content with [WARN] header, newline and custom format.
// It also prints caller backtrace info if backtrace feature is enabled.
// Deprecated.
// Use Warningf instead.
func Warningfln(format string, v ...interface{}) {
logger.Warningfln(format, v...)
}
@ -131,14 +135,14 @@ func Error(v ...interface{}) {
logger.Error(v...)
}
// Errorf prints the logging content with [ERRO] header and custom format.
// Errorf prints the logging content with [ERRO] header, custom format and newline.
// It also prints caller backtrace info if backtrace feature is enabled.
func Errorf(format string, v ...interface{}) {
logger.Errorf(format, v...)
}
// Errorfln prints the logging content with [ERRO] header, newline and custom format.
// It also prints caller backtrace info if backtrace feature is enabled.
// Deprecated.
// Use Errorf instead.
func Errorfln(format string, v ...interface{}) {
logger.Errorfln(format, v...)
}
@ -149,14 +153,14 @@ func Critical(v ...interface{}) {
logger.Critical(v...)
}
// Criticalf prints the logging content with [CRIT] header and custom format.
// Criticalf prints the logging content with [CRIT] header, custom format and newline.
// It also prints caller backtrace info if backtrace feature is enabled.
func Criticalf(format string, v ...interface{}) {
logger.Criticalf(format, v...)
}
// Criticalfln prints the logging content with [CRIT] header, newline and custom format.
// It also prints caller backtrace info if backtrace feature is enabled.
// Deprecated.
// Use Criticalf instead.
func Criticalfln(format string, v ...interface{}) {
logger.Criticalfln(format, v...)
}

View File

@ -299,7 +299,7 @@ func (l *Logger) GetBacktrace(skip...int) string {
backtrace := ""
from := 0
// Find the caller position exclusive of the glog file.
for i := 0; i < 100; i++ {
for i := 0; i < 1000; i++ {
if _, file, _, ok := runtime.Caller(i); ok {
if !gregex.IsMatchString("/g/os/glog/glog.+$", file) {
from = i
@ -310,7 +310,7 @@ func (l *Logger) GetBacktrace(skip...int) string {
// Find the true caller file path using custom skip.
index := 1
goRoot := runtime.GOROOT()
for i := from + customSkip + l.btSkip; i < 10000; i++ {
for i := from + customSkip + l.btSkip; i < 1000; i++ {
if _, file, cline, ok := runtime.Caller(i); ok && file != "" {
if (goRoot == "" || !gregex.IsMatchString("^" + goRoot, file)) && !gregex.IsMatchString(`<autogenerated>`, file) {
backtrace += fmt.Sprintf(`%d. %s:%d%s`, index, file, cline, ln)
@ -327,18 +327,17 @@ func (l *Logger) GetBacktrace(skip...int) string {
func (l *Logger) getLongFile() string {
from := 0
// Find the caller position exclusive of the glog file.
for i := 0; i < 100; i++ {
if _, file, line, ok := runtime.Caller(i); ok {
for i := 0; i < 1000; i++ {
if _, file, _, ok := runtime.Caller(i); ok {
if !gregex.IsMatchString("/g/os/glog/glog.+$", file) {
from = i
break
return fmt.Sprintf(`%s:%d`, file, line)
}
}
}
// Find the true caller file path using custom skip.
goRoot := runtime.GOROOT()
for i := from + l.btSkip; i < 10000; i++ {
for i := from + l.btSkip; i < 1000; i++ {
if _, file, line, ok := runtime.Caller(i); ok && file != "" {
if (goRoot == "" || !gregex.IsMatchString("^" + goRoot, file)) && !gregex.IsMatchString(`<autogenerated>`, file) {
return fmt.Sprintf(`%s:%d`, file, line)

View File

@ -20,7 +20,7 @@ func (l *Logger) Print(v ...interface{}) {
// Printf prints <v> with format <format> using fmt.Sprintf.
// The param <v> can be multiple variables.
func (l *Logger) Printf(format string, v ...interface{}) {
l.printStd(fmt.Sprintf(format, v...))
l.printStd(fmt.Sprintf(format + ln, v...))
}
// See Print.
@ -28,8 +28,8 @@ func (l *Logger) Println(v ...interface{}) {
l.Print(v...)
}
// Printfln prints <v> with newline and format <format> using fmt.Sprintf.
// The param <v> can be multiple variables.
// Deprecated.
// Use Printf instead.
func (l *Logger) Printfln(format string, v ...interface{}) {
l.printStd(fmt.Sprintf(format + ln, v...))
}
@ -40,13 +40,14 @@ func (l *Logger) Fatal(v ...interface{}) {
os.Exit(1)
}
// Fatalf prints the logging content with [FATA] header and custom format, then exit the current process.
// Fatalf prints the logging content with [FATA] header, custom format and newline, then exit the current process.
func (l *Logger) Fatalf(format string, v ...interface{}) {
l.printErr("[FATA] " + fmt.Sprintf(format, v...))
l.printErr("[FATA] " + fmt.Sprintf(format + ln, v...))
os.Exit(1)
}
// Fatalfln prints the logging content with [FATA] header, custom format and newline, then exit the current process.
// Deprecated.
// Use Fatalf instead.
func (l *Logger) Fatalfln(format string, v ...interface{}) {
l.printErr("[FATA] " + fmt.Sprintf(format + ln, v...))
os.Exit(1)
@ -59,14 +60,15 @@ func (l *Logger) Panic(v ...interface{}) {
panic(s)
}
// Panicf prints the logging content with [PANI] header and custom format, then panics.
// Panicf prints the logging content with [PANI] header, custom format and newline, then panics.
func (l *Logger) Panicf(format string, v ...interface{}) {
s := fmt.Sprintf(format, v...)
s := fmt.Sprintf(format + ln, v...)
l.printErr("[PANI] " + s)
panic(s)
}
// Panicfln prints the logging content with [PANI] header, newline and custom format, then panics.
// Deprecated.
// Use Panicf instead.
func (l *Logger) Panicfln(format string, v ...interface{}) {
s := fmt.Sprintf(format + ln, v...)
l.printErr("[PANI] " + s)
@ -80,17 +82,18 @@ func (l *Logger) Info(v ...interface{}) {
}
}
// Infof prints the logging content with [INFO] header and custom format.
// Infof prints the logging content with [INFO] header, custom format and newline.
func (l *Logger) Infof(format string, v ...interface{}) {
if l.checkLevel(LEVEL_INFO) {
l.printStd("[INFO] " + fmt.Sprintf(format, v...))
l.printStd("[INFO] " + fmt.Sprintf(format + ln, v...))
}
}
// Infofln prints the logging content with [INFO] header, newline and custom format.
// Deprecated.
// Use Infof instead.
func (l *Logger) Infofln(format string, v ...interface{}) {
if l.checkLevel(LEVEL_INFO) {
l.printStd("[INFO] " + fmt.Sprintf(format, v...) + ln)
l.printStd("[INFO] " + fmt.Sprintf(format + ln, v...) + ln)
}
}
@ -101,17 +104,18 @@ func (l *Logger) Debug(v ...interface{}) {
}
}
// Debugf prints the logging content with [DEBU] header and custom format.
// Debugf prints the logging content with [DEBU] header, custom format and newline.
func (l *Logger) Debugf(format string, v ...interface{}) {
if l.checkLevel(LEVEL_DEBU) {
l.printStd("[DEBU] " + fmt.Sprintf(format, v...))
l.printStd("[DEBU] " + fmt.Sprintf(format + ln, v...))
}
}
// Debugfln prints the logging content with [DEBU] header, newline and custom format.
// Deprecated.
// Use Debugf instead.
func (l *Logger) Debugfln(format string, v ...interface{}) {
if l.checkLevel(LEVEL_DEBU) {
l.printStd("[DEBU] " + fmt.Sprintf(format, v...) + ln)
l.printStd("[DEBU] " + fmt.Sprintf(format + ln, v...) + ln)
}
}
@ -123,19 +127,19 @@ func (l *Logger) Notice(v ...interface{}) {
}
}
// Noticef prints the logging content with [NOTI] header and custom format.
// Noticef prints the logging content with [NOTI] header, custom format and newline.
// It also prints caller backtrace info if backtrace feature is enabled.
func (l *Logger) Noticef(format string, v ...interface{}) {
if l.checkLevel(LEVEL_NOTI) {
l.printErr("[NOTI] " + fmt.Sprintf(format, v...))
l.printErr("[NOTI] " + fmt.Sprintf(format + ln, v...))
}
}
// Noticefln prints the logging content with [NOTI] header, newline and custom format.
// It also prints caller backtrace info if backtrace feature is enabled.
// Deprecated.
// Use Noticef instead.
func (l *Logger) Noticefln(format string, v ...interface{}) {
if l.checkLevel(LEVEL_NOTI) {
l.printErr("[NOTI] " + fmt.Sprintf(format, v...) + ln)
l.printErr("[NOTI] " + fmt.Sprintf(format + ln, v...) + ln)
}
}
@ -147,19 +151,19 @@ func (l *Logger) Warning(v ...interface{}) {
}
}
// Warningf prints the logging content with [WARN] header and custom format.
// Warningf prints the logging content with [WARN] header, custom format and newline.
// It also prints caller backtrace info if backtrace feature is enabled.
func (l *Logger) Warningf(format string, v ...interface{}) {
if l.checkLevel(LEVEL_WARN) {
l.printErr("[WARN] " + fmt.Sprintf(format, v...))
l.printErr("[WARN] " + fmt.Sprintf(format + ln, v...))
}
}
// Warningfln prints the logging content with [WARN] header, newline and custom format.
// It also prints caller backtrace info if backtrace feature is enabled.
// Deprecated.
// Use Warningf instead.
func (l *Logger) Warningfln(format string, v ...interface{}) {
if l.checkLevel(LEVEL_WARN) {
l.printErr("[WARN] " + fmt.Sprintf(format, v...) + ln)
l.printErr("[WARN] " + fmt.Sprintf(format + ln, v...) + ln)
}
}
@ -171,19 +175,19 @@ func (l *Logger) Error(v ...interface{}) {
}
}
// Errorf prints the logging content with [ERRO] header and custom format.
// Errorf prints the logging content with [ERRO] header, custom format and newline.
// It also prints caller backtrace info if backtrace feature is enabled.
func (l *Logger) Errorf(format string, v ...interface{}) {
if l.checkLevel(LEVEL_ERRO) {
l.printErr("[ERRO] " + fmt.Sprintf(format, v...))
l.printErr("[ERRO] " + fmt.Sprintf(format + ln, v...))
}
}
// Errorfln prints the logging content with [ERRO] header, newline and custom format.
// It also prints caller backtrace info if backtrace feature is enabled.
// Deprecated.
// Use Errorf instead.
func (l *Logger) Errorfln(format string, v ...interface{}) {
if l.checkLevel(LEVEL_ERRO) {
l.printErr("[ERRO] " + fmt.Sprintf(format, v...) + ln)
l.printErr("[ERRO] " + fmt.Sprintf(format + ln, v...) + ln)
}
}
@ -195,19 +199,19 @@ func (l *Logger) Critical(v ...interface{}) {
}
}
// Criticalf prints the logging content with [CRIT] header and custom format.
// Criticalf prints the logging content with [CRIT] header, custom format and newline.
// It also prints caller backtrace info if backtrace feature is enabled.
func (l *Logger) Criticalf(format string, v ...interface{}) {
if l.checkLevel(LEVEL_CRIT) {
l.printErr("[CRIT] " + fmt.Sprintf(format, v...))
l.printErr("[CRIT] " + fmt.Sprintf(format + ln, v...))
}
}
// Criticalfln prints the logging content with [CRIT] header, newline and custom format.
// It also prints caller backtrace info if backtrace feature is enabled.
// Deprecated.
// Use Criticalf instead.
func (l *Logger) Criticalfln(format string, v ...interface{}) {
if l.checkLevel(LEVEL_CRIT) {
l.printErr("[CRIT] " + fmt.Sprintf(format, v...) + ln)
l.printErr("[CRIT] " + fmt.Sprintf(format + ln, v...) + ln)
}
}

View File

@ -1,17 +1,14 @@
package main
import (
"github.com/gogf/gf/g/os/glog"
"github.com/gogf/gf/g/os/gtime"
"log"
)
func main() {
Time := gtime.Now().AddDate(0, -1, 0).Format("Y-m")
glog.Debug(Time)
Time = gtime.Now().AddDate(0, -2, 0).Format("Y-m")
glog.Debug(Time)
Time = gtime.Now().AddDate(0, -3, 0).Format("Y-m")
glog.Debug(Time)
Time = gtime.Now().AddDate(0, -4, 0).Format("Y-m")
glog.Debug(Time)
log.Printf("111")
log.Printf("111")
log.Print("222")
log.Print("222")
log.Println("333")
log.Println("333")
}