github.com/gogf/gf@v1.16.9/os/glog/glog.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/gogf/gf. 6 7 // Package glog implements powerful and easy-to-use levelled logging functionality. 8 package glog 9 10 import ( 11 "github.com/gogf/gf/os/gcmd" 12 "github.com/gogf/gf/os/grpool" 13 ) 14 15 const ( 16 commandEnvKeyForDebug = "gf.glog.debug" 17 ) 18 19 var ( 20 // Default logger object, for package method usage. 21 logger = New() 22 23 // Goroutine pool for async logging output. 24 // It uses only one asynchronous worker to ensure log sequence. 25 asyncPool = grpool.New(1) 26 27 // defaultDebug enables debug level or not in default, 28 // which can be configured using command option or system environment. 29 defaultDebug = true 30 ) 31 32 func init() { 33 defaultDebug = gcmd.GetOptWithEnv(commandEnvKeyForDebug, true).Bool() 34 SetDebug(defaultDebug) 35 } 36 37 // DefaultLogger returns the default logger. 38 func DefaultLogger() *Logger { 39 return logger 40 } 41 42 // SetDefaultLogger sets the default logger for package glog. 43 // Note that there might be concurrent safety issue if calls this function 44 // in different goroutines. 45 func SetDefaultLogger(l *Logger) { 46 logger = l 47 }