gf/os/glog/glog.go

48 lines
1.2 KiB
Go
Raw Normal View History

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,
// 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 (
"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
)
const (
commandEnvKeyForDebug = "gf.glog.debug"
)
2018-08-24 23:41:58 +08:00
var (
// Default logger object, for package method usage.
2019-06-19 09:06:52 +08:00
logger = New()
2019-06-19 09:06:52 +08:00
// Goroutine pool for async logging output.
// It uses only one asynchronous worker to ensure log sequence.
2019-06-01 19:34:03 +08:00
asyncPool = grpool.New(1)
// 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
func init() {
defaultDebug = gcmd.GetOptWithEnv(commandEnvKeyForDebug, true).Bool()
SetDebug(defaultDebug)
}
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
}
// 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
}