2021-01-17 21:46:25 +08:00
|
|
|
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
2017-12-29 16:03:30 +08:00
|
|
|
//
|
|
|
|
// 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,
|
2019-02-02 16:18:25 +08:00
|
|
|
// You can obtain one at https://github.com/gogf/gf.
|
2017-12-29 16:03:30 +08:00
|
|
|
|
2019-01-16 09:00:23 +08:00
|
|
|
// Package glog implements powerful and easy-to-use levelled logging functionality.
|
2017-11-23 10:21:28 +08:00
|
|
|
package glog
|
|
|
|
|
|
|
|
import (
|
2020-12-04 23:44:54 +08:00
|
|
|
"github.com/gogf/gf/os/gcmd"
|
2019-07-29 21:01:19 +08:00
|
|
|
"github.com/gogf/gf/os/grpool"
|
2017-11-23 10:21:28 +08:00
|
|
|
)
|
|
|
|
|
2021-06-26 12:08:18 +08:00
|
|
|
const (
|
|
|
|
commandEnvKeyForDebug = "gf.glog.debug"
|
|
|
|
)
|
|
|
|
|
2018-08-24 23:41:58 +08:00
|
|
|
var (
|
2020-04-15 11:04:39 +08:00
|
|
|
// Default logger object, for package method usage.
|
2019-06-19 09:06:52 +08:00
|
|
|
logger = New()
|
2020-04-15 11:04:39 +08:00
|
|
|
|
2019-06-19 09:06:52 +08:00
|
|
|
// Goroutine pool for async logging output.
|
2021-06-26 12:08:18 +08:00
|
|
|
// It uses only one asynchronous worker to ensure log sequence.
|
2019-06-01 19:34:03 +08:00
|
|
|
asyncPool = grpool.New(1)
|
2020-04-15 11:04:39 +08:00
|
|
|
|
2019-11-19 17:26:06 +08:00
|
|
|
// defaultDebug enables debug level or not in default,
|
|
|
|
// which can be configured using command option or system environment.
|
|
|
|
defaultDebug = true
|
2018-08-24 23:41:58 +08:00
|
|
|
)
|
2017-11-23 10:21:28 +08:00
|
|
|
|
2019-01-23 13:01:58 +08:00
|
|
|
func init() {
|
2021-06-26 12:08:18 +08:00
|
|
|
defaultDebug = gcmd.GetOptWithEnv(commandEnvKeyForDebug, true).Bool()
|
2019-11-19 17:26:06 +08:00
|
|
|
SetDebug(defaultDebug)
|
2019-01-23 13:01:58 +08:00
|
|
|
}
|
|
|
|
|
2021-06-02 09:42:27 +08:00
|
|
|
// DefaultLogger returns the default logger.
|
2019-10-26 10:58:07 +08:00
|
|
|
func DefaultLogger() *Logger {
|
2019-08-26 19:39:04 +08:00
|
|
|
return logger
|
|
|
|
}
|
|
|
|
|
2020-01-21 15:42:08 +08:00
|
|
|
// SetDefaultLogger sets the default logger for package glog.
|
|
|
|
// Note that there might be concurrent safety issue if calls this function
|
|
|
|
// in different goroutines.
|
|
|
|
func SetDefaultLogger(l *Logger) {
|
|
|
|
logger = l
|
|
|
|
}
|