log.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package log
  2. import "github.com/astaxie/beego/logs"
  3. const (
  4. LevelEmergency = iota
  5. LevelAlert
  6. LevelCritical
  7. LevelError
  8. LevelWarning
  9. LevelNotice
  10. LevelInformational
  11. LevelDebug
  12. )
  13. type Logger struct {
  14. *logs.BeeLogger
  15. }
  16. func NewLogger(channelLen int64, adapterName string, config string, logLevel int) *Logger {
  17. logger := logs.NewLogger(channelLen)
  18. logger.SetLogger(adapterName, config)
  19. logger.SetLevel(logLevel)
  20. logger.EnableFuncCallDepth(true)
  21. logger.SetLogFuncCallDepth(3)
  22. return &Logger{logger}
  23. }
  24. func (logger *Logger) Printf(format string, v ...interface{}) {
  25. logger.Trace(format, v...)
  26. }
  27. var l *Logger
  28. func InitLogger(channelLen int64, adapterName string, config string, logLevel int) {
  29. l = NewLogger(channelLen, adapterName, config, logLevel)
  30. }
  31. func Criticalf(format string, v ...interface{}) {
  32. l.Critical(format, v...)
  33. }
  34. func Errorf(format string, v ...interface{}) {
  35. l.Error(format, v...)
  36. }
  37. func Warnf(format string, v ...interface{}) {
  38. l.Warn(format, v...)
  39. }
  40. func Infof(format string, v ...interface{}) {
  41. l.Info(format, v...)
  42. }
  43. func Tracef(format string, v ...interface{}) {
  44. l.Trace(format, v...)
  45. }
  46. func Debugf(format string, v ...interface{}) {
  47. l.Debug(format, v...)
  48. }