Files
gf/os/glog/glog.go

49 lines
1.3 KiB
Go
Raw Permalink 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/v2/internal/command"
2021-10-11 21:41:56 +08:00
"github.com/gogf/gf/v2/os/grpool"
"github.com/gogf/gf/v2/util/gconv"
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.
defaultLogger = 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 = gconv.Bool(command.GetOptWithEnv(commandEnvKeyForDebug, "true"))
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 {
return defaultLogger
2019-08-26 19:39:04 +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) {
defaultLogger = l
}