mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-11-11 11:43:46 +08:00
77 lines
1.5 KiB
Go
77 lines
1.5 KiB
Go
// Copyright GoFrame gf Author(https://goframe.org). 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 mlog
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/gogf/gf/v2/os/gcmd"
|
|
"github.com/gogf/gf/v2/os/genv"
|
|
"github.com/gogf/gf/v2/os/glog"
|
|
)
|
|
|
|
const (
|
|
headerPrintEnvName = "GF_CLI_MLOG_HEADER"
|
|
)
|
|
|
|
var (
|
|
ctx = context.TODO()
|
|
logger = glog.New()
|
|
)
|
|
|
|
func init() {
|
|
if genv.Get(headerPrintEnvName).String() == "1" {
|
|
logger.SetHeaderPrint(true)
|
|
} else {
|
|
logger.SetHeaderPrint(false)
|
|
}
|
|
|
|
if gcmd.GetOpt("debug") != nil || gcmd.GetOpt("gf.debug") != nil {
|
|
logger.SetHeaderPrint(true)
|
|
logger.SetStackSkip(4)
|
|
logger.SetFlags(logger.GetFlags() | glog.F_FILE_LONG)
|
|
logger.SetDebug(true)
|
|
} else {
|
|
logger.SetStack(false)
|
|
logger.SetDebug(false)
|
|
}
|
|
}
|
|
|
|
// SetHeaderPrint enables/disables header printing to stdout.
|
|
func SetHeaderPrint(enabled bool) {
|
|
logger.SetHeaderPrint(enabled)
|
|
if enabled {
|
|
_ = genv.Set(headerPrintEnvName, "1")
|
|
} else {
|
|
_ = genv.Set(headerPrintEnvName, "0")
|
|
}
|
|
}
|
|
|
|
func Print(v ...any) {
|
|
logger.Print(ctx, v...)
|
|
}
|
|
|
|
func Printf(format string, v ...any) {
|
|
logger.Printf(ctx, format, v...)
|
|
}
|
|
|
|
func Fatal(v ...any) {
|
|
logger.Fatal(ctx, v...)
|
|
}
|
|
|
|
func Fatalf(format string, v ...any) {
|
|
logger.Fatalf(ctx, format, v...)
|
|
}
|
|
|
|
func Debug(v ...any) {
|
|
logger.Debug(ctx, v...)
|
|
}
|
|
|
|
func Debugf(format string, v ...any) {
|
|
logger.Debugf(ctx, format, v...)
|
|
}
|