log.t 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. use Test::Nginx::Socket;
  2. our $HttpConfig = <<'_EOC_';
  3. lua_package_path "lib/?.lua;/usr/local/share/lua/5.1/?.lua;;";
  4. _EOC_
  5. repeat_each(3);
  6. plan tests => repeat_each() * (blocks() * 2 + 2);
  7. run_tests();
  8. __DATA__
  9. === TEST 1: err_fmt
  10. --- http_config eval: $::HttpConfig
  11. --- config
  12. location /t {
  13. content_by_lua_block {
  14. local log = require "resty.t1k.log"
  15. ngx.log(log.err_fmt("%s - %04d - %.4f", "test", 1, 1))
  16. }
  17. }
  18. --- request
  19. GET /t
  20. [error]
  21. --- error_log
  22. lua-resty-t1k: test - 0001 - 1.0000
  23. --- log_level: error
  24. === TEST 2: warn_fmt
  25. --- http_config eval: $::HttpConfig
  26. --- config
  27. location /t {
  28. content_by_lua_block {
  29. local log = require "resty.t1k.log"
  30. ngx.log(log.warn_fmt("%s - %04d - %.4f", "test", 1, 1))
  31. }
  32. }
  33. --- request
  34. GET /t
  35. --- no_error_log
  36. [error]
  37. --- error_log
  38. lua-resty-t1k: test - 0001 - 1.0000
  39. --- log_level: warn
  40. === TEST 3: debug_fmt
  41. --- http_config eval: $::HttpConfig
  42. --- config
  43. location /t {
  44. content_by_lua_block {
  45. local log = require "resty.t1k.log"
  46. ngx.log(log.debug_fmt("%s - %04d - %.4f", "test", 1, 1))
  47. }
  48. }
  49. --- request
  50. GET /t
  51. --- no_error_log
  52. [error]
  53. --- error_log
  54. lua-resty-t1k: test - 0001 - 1.0000
  55. --- log_level: debug