高热共公日志库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.4 KiB

  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 logs
  15. import (
  16. "testing"
  17. )
  18. // Try each log level in decreasing order of priority.
  19. func testConsoleCalls(bl *BeeLogger) {
  20. bl.Emergency("emergency")
  21. bl.Alert("alert")
  22. bl.Critical("critical")
  23. bl.Error("error")
  24. bl.Warning("warning")
  25. bl.Notice("notice")
  26. bl.Informational("informational")
  27. bl.Debug("debug")
  28. }
  29. // Test console logging by visually comparing the lines being output with and
  30. // without a log level specification.
  31. func TestConsole(t *testing.T) {
  32. log1 := NewLogger(10000)
  33. log1.EnableFuncCallDepth(true)
  34. log1.SetLogger("console", "")
  35. testConsoleCalls(log1)
  36. log2 := NewLogger(100)
  37. log2.SetLogger("console", `{"level":3}`)
  38. testConsoleCalls(log2)
  39. }
  40. // Test console without color
  41. func TestConsoleNoColor(t *testing.T) {
  42. log := NewLogger(100)
  43. log.SetLogger("console", `{"color":false}`)
  44. testConsoleCalls(log)
  45. }