log.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // Copyright 2014 beego Author. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package beego
  15. import (
  16. "strings"
  17. "github.com/astaxie/beego/logs"
  18. )
  19. // Log levels to control the logging output.
  20. const (
  21. LevelEmergency = iota
  22. LevelAlert
  23. LevelCritical
  24. LevelError
  25. LevelWarning
  26. LevelNotice
  27. LevelInformational
  28. LevelDebug
  29. )
  30. // BeeLogger references the used application logger.
  31. var BeeLogger = logs.GetBeeLogger()
  32. // SetLevel sets the global log level used by the simple logger.
  33. func SetLevel(l int) {
  34. logs.SetLevel(l)
  35. }
  36. // SetLogFuncCall set the CallDepth, default is 3
  37. func SetLogFuncCall(b bool) {
  38. logs.SetLogFuncCall(b)
  39. }
  40. // SetLogger sets a new logger.
  41. func SetLogger(adaptername string, config string) error {
  42. return logs.SetLogger(adaptername, config)
  43. }
  44. // Emergency logs a message at emergency level.
  45. func Emergency(v ...interface{}) {
  46. logs.Emergency(generateFmtStr(len(v)), v...)
  47. }
  48. // Alert logs a message at alert level.
  49. func Alert(v ...interface{}) {
  50. logs.Alert(generateFmtStr(len(v)), v...)
  51. }
  52. // Critical logs a message at critical level.
  53. func Critical(v ...interface{}) {
  54. logs.Critical(generateFmtStr(len(v)), v...)
  55. }
  56. // Error logs a message at error level.
  57. func Error(v ...interface{}) {
  58. logs.Error(generateFmtStr(len(v)), v...)
  59. }
  60. // Warning logs a message at warning level.
  61. func Warning(v ...interface{}) {
  62. logs.Warning(generateFmtStr(len(v)), v...)
  63. }
  64. // Warn compatibility alias for Warning()
  65. func Warn(v ...interface{}) {
  66. logs.Warn(generateFmtStr(len(v)), v...)
  67. }
  68. // Notice logs a message at notice level.
  69. func Notice(v ...interface{}) {
  70. logs.Notice(generateFmtStr(len(v)), v...)
  71. }
  72. // Informational logs a message at info level.
  73. func Informational(v ...interface{}) {
  74. logs.Informational(generateFmtStr(len(v)), v...)
  75. }
  76. // Info compatibility alias for Warning()
  77. func Info(v ...interface{}) {
  78. logs.Info(generateFmtStr(len(v)), v...)
  79. }
  80. // Debug logs a message at debug level.
  81. func Debug(v ...interface{}) {
  82. logs.Debug(generateFmtStr(len(v)), v...)
  83. }
  84. // Trace logs a message at trace level.
  85. // compatibility alias for Warning()
  86. func Trace(v ...interface{}) {
  87. logs.Trace(generateFmtStr(len(v)), v...)
  88. }
  89. func generateFmtStr(n int) string {
  90. return strings.Repeat("%v ", n)
  91. }