glog.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2017 gf Author(https://github.com/gogf/gf). 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. // Package glog implements powerful and easy-to-use levelled logging functionality.
  7. package glog
  8. import (
  9. "github.com/gogf/gf/os/gcmd"
  10. "github.com/gogf/gf/os/grpool"
  11. )
  12. var (
  13. // Default logger object, for package method usage.
  14. logger = New()
  15. // Goroutine pool for async logging output.
  16. // It uses only one asynchronize worker to ensure log sequence.
  17. asyncPool = grpool.New(1)
  18. // defaultDebug enables debug level or not in default,
  19. // which can be configured using command option or system environment.
  20. defaultDebug = true
  21. )
  22. func init() {
  23. defaultDebug = gcmd.GetWithEnv("gf.glog.debug", true).Bool()
  24. SetDebug(defaultDebug)
  25. }
  26. // Default returns the default logger.
  27. func DefaultLogger() *Logger {
  28. return logger
  29. }
  30. // SetDefaultLogger sets the default logger for package glog.
  31. // Note that there might be concurrent safety issue if calls this function
  32. // in different goroutines.
  33. func SetDefaultLogger(l *Logger) {
  34. logger = l
  35. }