fluentd 1.17.0-x64-mingw32 → 1.17.1-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (259) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +46 -0
  3. data/README.md +1 -0
  4. data/SECURITY.md +2 -2
  5. data/fluent.conf +14 -14
  6. data/lib/fluent/command/cap_ctl.rb +4 -4
  7. data/lib/fluent/compat/call_super_mixin.rb +3 -3
  8. data/lib/fluent/compat/propagate_default.rb +4 -4
  9. data/lib/fluent/config/yaml_parser/parser.rb +4 -0
  10. data/lib/fluent/log/console_adapter.rb +4 -2
  11. data/lib/fluent/plugin/in_exec.rb +14 -2
  12. data/lib/fluent/plugin/in_http.rb +1 -1
  13. data/lib/fluent/plugin/in_sample.rb +13 -7
  14. data/lib/fluent/plugin/in_tail.rb +65 -23
  15. data/lib/fluent/plugin/out_copy.rb +1 -1
  16. data/lib/fluent/plugin/out_file.rb +8 -0
  17. data/lib/fluent/plugin/out_http.rb +12 -0
  18. data/lib/fluent/plugin/parser_json.rb +4 -12
  19. data/lib/fluent/plugin_helper/http_server/server.rb +1 -1
  20. data/lib/fluent/version.rb +1 -1
  21. data/templates/new_gem/fluent-plugin.gemspec.erb +6 -5
  22. metadata +25 -472
  23. data/.github/DISCUSSION_TEMPLATE/q-a-japanese.yml +0 -50
  24. data/.github/DISCUSSION_TEMPLATE/q-a.yml +0 -47
  25. data/.github/ISSUE_TEMPLATE/bug_report.yml +0 -71
  26. data/.github/ISSUE_TEMPLATE/config.yml +0 -5
  27. data/.github/ISSUE_TEMPLATE/feature_request.yml +0 -39
  28. data/.github/ISSUE_TEMPLATE.md +0 -17
  29. data/.github/PULL_REQUEST_TEMPLATE.md +0 -14
  30. data/.github/workflows/stale-actions.yml +0 -24
  31. data/.github/workflows/test-ruby-head.yml +0 -31
  32. data/.github/workflows/test.yml +0 -32
  33. data/.gitignore +0 -30
  34. data/Gemfile +0 -9
  35. data/fluentd.gemspec +0 -62
  36. data/test/command/test_binlog_reader.rb +0 -362
  37. data/test/command/test_ca_generate.rb +0 -70
  38. data/test/command/test_cap_ctl.rb +0 -100
  39. data/test/command/test_cat.rb +0 -128
  40. data/test/command/test_ctl.rb +0 -56
  41. data/test/command/test_fluentd.rb +0 -1291
  42. data/test/command/test_plugin_config_formatter.rb +0 -397
  43. data/test/command/test_plugin_generator.rb +0 -109
  44. data/test/compat/test_calls_super.rb +0 -166
  45. data/test/compat/test_parser.rb +0 -92
  46. data/test/config/assertions.rb +0 -42
  47. data/test/config/test_config_parser.rb +0 -551
  48. data/test/config/test_configurable.rb +0 -1784
  49. data/test/config/test_configure_proxy.rb +0 -604
  50. data/test/config/test_dsl.rb +0 -415
  51. data/test/config/test_element.rb +0 -518
  52. data/test/config/test_literal_parser.rb +0 -309
  53. data/test/config/test_plugin_configuration.rb +0 -56
  54. data/test/config/test_section.rb +0 -191
  55. data/test/config/test_system_config.rb +0 -195
  56. data/test/config/test_types.rb +0 -408
  57. data/test/counter/test_client.rb +0 -563
  58. data/test/counter/test_error.rb +0 -44
  59. data/test/counter/test_mutex_hash.rb +0 -179
  60. data/test/counter/test_server.rb +0 -589
  61. data/test/counter/test_store.rb +0 -258
  62. data/test/counter/test_validator.rb +0 -137
  63. data/test/helper.rb +0 -155
  64. data/test/helpers/fuzzy_assert.rb +0 -89
  65. data/test/helpers/process_extenstion.rb +0 -33
  66. data/test/log/test_console_adapter.rb +0 -117
  67. data/test/plugin/data/2010/01/20100102-030405.log +0 -0
  68. data/test/plugin/data/2010/01/20100102-030406.log +0 -0
  69. data/test/plugin/data/2010/01/20100102.log +0 -0
  70. data/test/plugin/data/log/bar +0 -0
  71. data/test/plugin/data/log/foo/bar.log +0 -0
  72. data/test/plugin/data/log/foo/bar2 +0 -0
  73. data/test/plugin/data/log/test.log +0 -0
  74. data/test/plugin/data/log_numeric/01.log +0 -0
  75. data/test/plugin/data/log_numeric/02.log +0 -0
  76. data/test/plugin/data/log_numeric/12.log +0 -0
  77. data/test/plugin/data/log_numeric/14.log +0 -0
  78. data/test/plugin/data/sd_file/config +0 -11
  79. data/test/plugin/data/sd_file/config.json +0 -17
  80. data/test/plugin/data/sd_file/config.yaml +0 -11
  81. data/test/plugin/data/sd_file/config.yml +0 -11
  82. data/test/plugin/data/sd_file/invalid_config.yml +0 -7
  83. data/test/plugin/in_tail/test_fifo.rb +0 -121
  84. data/test/plugin/in_tail/test_io_handler.rb +0 -150
  85. data/test/plugin/in_tail/test_position_file.rb +0 -346
  86. data/test/plugin/out_forward/test_ack_handler.rb +0 -140
  87. data/test/plugin/out_forward/test_connection_manager.rb +0 -145
  88. data/test/plugin/out_forward/test_handshake_protocol.rb +0 -112
  89. data/test/plugin/out_forward/test_load_balancer.rb +0 -106
  90. data/test/plugin/out_forward/test_socket_cache.rb +0 -174
  91. data/test/plugin/test_bare_output.rb +0 -131
  92. data/test/plugin/test_base.rb +0 -247
  93. data/test/plugin/test_buf_file.rb +0 -1314
  94. data/test/plugin/test_buf_file_single.rb +0 -898
  95. data/test/plugin/test_buf_memory.rb +0 -42
  96. data/test/plugin/test_buffer.rb +0 -1493
  97. data/test/plugin/test_buffer_chunk.rb +0 -209
  98. data/test/plugin/test_buffer_file_chunk.rb +0 -871
  99. data/test/plugin/test_buffer_file_single_chunk.rb +0 -611
  100. data/test/plugin/test_buffer_memory_chunk.rb +0 -339
  101. data/test/plugin/test_compressable.rb +0 -87
  102. data/test/plugin/test_file_util.rb +0 -96
  103. data/test/plugin/test_filter.rb +0 -368
  104. data/test/plugin/test_filter_grep.rb +0 -697
  105. data/test/plugin/test_filter_parser.rb +0 -731
  106. data/test/plugin/test_filter_record_transformer.rb +0 -577
  107. data/test/plugin/test_filter_stdout.rb +0 -207
  108. data/test/plugin/test_formatter_csv.rb +0 -136
  109. data/test/plugin/test_formatter_hash.rb +0 -38
  110. data/test/plugin/test_formatter_json.rb +0 -61
  111. data/test/plugin/test_formatter_ltsv.rb +0 -70
  112. data/test/plugin/test_formatter_msgpack.rb +0 -28
  113. data/test/plugin/test_formatter_out_file.rb +0 -116
  114. data/test/plugin/test_formatter_single_value.rb +0 -44
  115. data/test/plugin/test_formatter_tsv.rb +0 -76
  116. data/test/plugin/test_in_debug_agent.rb +0 -49
  117. data/test/plugin/test_in_exec.rb +0 -261
  118. data/test/plugin/test_in_forward.rb +0 -1178
  119. data/test/plugin/test_in_gc_stat.rb +0 -62
  120. data/test/plugin/test_in_http.rb +0 -1124
  121. data/test/plugin/test_in_monitor_agent.rb +0 -922
  122. data/test/plugin/test_in_object_space.rb +0 -66
  123. data/test/plugin/test_in_sample.rb +0 -190
  124. data/test/plugin/test_in_syslog.rb +0 -505
  125. data/test/plugin/test_in_tail.rb +0 -3429
  126. data/test/plugin/test_in_tcp.rb +0 -328
  127. data/test/plugin/test_in_udp.rb +0 -296
  128. data/test/plugin/test_in_unix.rb +0 -181
  129. data/test/plugin/test_input.rb +0 -137
  130. data/test/plugin/test_metadata.rb +0 -89
  131. data/test/plugin/test_metrics.rb +0 -294
  132. data/test/plugin/test_metrics_local.rb +0 -96
  133. data/test/plugin/test_multi_output.rb +0 -204
  134. data/test/plugin/test_out_copy.rb +0 -308
  135. data/test/plugin/test_out_exec.rb +0 -312
  136. data/test/plugin/test_out_exec_filter.rb +0 -606
  137. data/test/plugin/test_out_file.rb +0 -1038
  138. data/test/plugin/test_out_forward.rb +0 -1349
  139. data/test/plugin/test_out_http.rb +0 -557
  140. data/test/plugin/test_out_null.rb +0 -105
  141. data/test/plugin/test_out_relabel.rb +0 -28
  142. data/test/plugin/test_out_roundrobin.rb +0 -146
  143. data/test/plugin/test_out_secondary_file.rb +0 -458
  144. data/test/plugin/test_out_stdout.rb +0 -205
  145. data/test/plugin/test_out_stream.rb +0 -103
  146. data/test/plugin/test_output.rb +0 -1334
  147. data/test/plugin/test_output_as_buffered.rb +0 -2024
  148. data/test/plugin/test_output_as_buffered_backup.rb +0 -363
  149. data/test/plugin/test_output_as_buffered_compress.rb +0 -179
  150. data/test/plugin/test_output_as_buffered_overflow.rb +0 -250
  151. data/test/plugin/test_output_as_buffered_retries.rb +0 -966
  152. data/test/plugin/test_output_as_buffered_secondary.rb +0 -882
  153. data/test/plugin/test_output_as_standard.rb +0 -374
  154. data/test/plugin/test_owned_by.rb +0 -34
  155. data/test/plugin/test_parser.rb +0 -399
  156. data/test/plugin/test_parser_apache.rb +0 -42
  157. data/test/plugin/test_parser_apache2.rb +0 -47
  158. data/test/plugin/test_parser_apache_error.rb +0 -45
  159. data/test/plugin/test_parser_csv.rb +0 -200
  160. data/test/plugin/test_parser_json.rb +0 -244
  161. data/test/plugin/test_parser_labeled_tsv.rb +0 -160
  162. data/test/plugin/test_parser_msgpack.rb +0 -127
  163. data/test/plugin/test_parser_multiline.rb +0 -111
  164. data/test/plugin/test_parser_nginx.rb +0 -88
  165. data/test/plugin/test_parser_none.rb +0 -52
  166. data/test/plugin/test_parser_regexp.rb +0 -284
  167. data/test/plugin/test_parser_syslog.rb +0 -650
  168. data/test/plugin/test_parser_tsv.rb +0 -122
  169. data/test/plugin/test_sd_file.rb +0 -228
  170. data/test/plugin/test_sd_srv.rb +0 -230
  171. data/test/plugin/test_storage.rb +0 -166
  172. data/test/plugin/test_storage_local.rb +0 -335
  173. data/test/plugin/test_string_util.rb +0 -26
  174. data/test/plugin_helper/data/cert/cert-key.pem +0 -27
  175. data/test/plugin_helper/data/cert/cert-with-CRLF.pem +0 -19
  176. data/test/plugin_helper/data/cert/cert-with-no-newline.pem +0 -19
  177. data/test/plugin_helper/data/cert/cert.pem +0 -19
  178. data/test/plugin_helper/data/cert/cert_chains/ca-cert-key.pem +0 -27
  179. data/test/plugin_helper/data/cert/cert_chains/ca-cert.pem +0 -20
  180. data/test/plugin_helper/data/cert/cert_chains/cert-key.pem +0 -27
  181. data/test/plugin_helper/data/cert/cert_chains/cert.pem +0 -40
  182. data/test/plugin_helper/data/cert/empty.pem +0 -0
  183. data/test/plugin_helper/data/cert/generate_cert.rb +0 -125
  184. data/test/plugin_helper/data/cert/with_ca/ca-cert-key-pass.pem +0 -30
  185. data/test/plugin_helper/data/cert/with_ca/ca-cert-key.pem +0 -27
  186. data/test/plugin_helper/data/cert/with_ca/ca-cert-pass.pem +0 -20
  187. data/test/plugin_helper/data/cert/with_ca/ca-cert.pem +0 -20
  188. data/test/plugin_helper/data/cert/with_ca/cert-key-pass.pem +0 -30
  189. data/test/plugin_helper/data/cert/with_ca/cert-key.pem +0 -27
  190. data/test/plugin_helper/data/cert/with_ca/cert-pass.pem +0 -21
  191. data/test/plugin_helper/data/cert/with_ca/cert.pem +0 -21
  192. data/test/plugin_helper/data/cert/without_ca/cert-key-pass.pem +0 -30
  193. data/test/plugin_helper/data/cert/without_ca/cert-key.pem +0 -27
  194. data/test/plugin_helper/data/cert/without_ca/cert-pass.pem +0 -20
  195. data/test/plugin_helper/data/cert/without_ca/cert.pem +0 -20
  196. data/test/plugin_helper/http_server/test_app.rb +0 -65
  197. data/test/plugin_helper/http_server/test_route.rb +0 -32
  198. data/test/plugin_helper/service_discovery/test_manager.rb +0 -93
  199. data/test/plugin_helper/service_discovery/test_round_robin_balancer.rb +0 -21
  200. data/test/plugin_helper/test_cert_option.rb +0 -25
  201. data/test/plugin_helper/test_child_process.rb +0 -862
  202. data/test/plugin_helper/test_compat_parameters.rb +0 -358
  203. data/test/plugin_helper/test_event_emitter.rb +0 -80
  204. data/test/plugin_helper/test_event_loop.rb +0 -52
  205. data/test/plugin_helper/test_extract.rb +0 -194
  206. data/test/plugin_helper/test_formatter.rb +0 -255
  207. data/test/plugin_helper/test_http_server_helper.rb +0 -372
  208. data/test/plugin_helper/test_inject.rb +0 -561
  209. data/test/plugin_helper/test_metrics.rb +0 -137
  210. data/test/plugin_helper/test_parser.rb +0 -264
  211. data/test/plugin_helper/test_record_accessor.rb +0 -238
  212. data/test/plugin_helper/test_retry_state.rb +0 -1006
  213. data/test/plugin_helper/test_server.rb +0 -1895
  214. data/test/plugin_helper/test_service_discovery.rb +0 -165
  215. data/test/plugin_helper/test_socket.rb +0 -146
  216. data/test/plugin_helper/test_storage.rb +0 -542
  217. data/test/plugin_helper/test_thread.rb +0 -164
  218. data/test/plugin_helper/test_timer.rb +0 -130
  219. data/test/scripts/exec_script.rb +0 -32
  220. data/test/scripts/fluent/plugin/formatter1/formatter_test1.rb +0 -7
  221. data/test/scripts/fluent/plugin/formatter2/formatter_test2.rb +0 -7
  222. data/test/scripts/fluent/plugin/formatter_known.rb +0 -8
  223. data/test/scripts/fluent/plugin/out_test.rb +0 -81
  224. data/test/scripts/fluent/plugin/out_test2.rb +0 -80
  225. data/test/scripts/fluent/plugin/parser_known.rb +0 -4
  226. data/test/test_capability.rb +0 -74
  227. data/test/test_clock.rb +0 -164
  228. data/test/test_config.rb +0 -369
  229. data/test/test_configdsl.rb +0 -148
  230. data/test/test_daemonizer.rb +0 -91
  231. data/test/test_engine.rb +0 -203
  232. data/test/test_event.rb +0 -531
  233. data/test/test_event_router.rb +0 -348
  234. data/test/test_event_time.rb +0 -199
  235. data/test/test_file_wrapper.rb +0 -53
  236. data/test/test_filter.rb +0 -121
  237. data/test/test_fluent_log_event_router.rb +0 -99
  238. data/test/test_formatter.rb +0 -369
  239. data/test/test_input.rb +0 -31
  240. data/test/test_log.rb +0 -1076
  241. data/test/test_match.rb +0 -148
  242. data/test/test_mixin.rb +0 -351
  243. data/test/test_msgpack_factory.rb +0 -50
  244. data/test/test_oj_options.rb +0 -55
  245. data/test/test_output.rb +0 -278
  246. data/test/test_plugin.rb +0 -251
  247. data/test/test_plugin_classes.rb +0 -370
  248. data/test/test_plugin_helper.rb +0 -81
  249. data/test/test_plugin_id.rb +0 -119
  250. data/test/test_process.rb +0 -14
  251. data/test/test_root_agent.rb +0 -951
  252. data/test/test_static_config_analysis.rb +0 -177
  253. data/test/test_supervisor.rb +0 -821
  254. data/test/test_test_drivers.rb +0 -136
  255. data/test/test_time_formatter.rb +0 -301
  256. data/test/test_time_parser.rb +0 -362
  257. data/test/test_tls.rb +0 -65
  258. data/test/test_unique_id.rb +0 -47
  259. data/test/test_variable_store.rb +0 -65
data/test/test_log.rb DELETED
@@ -1,1076 +0,0 @@
1
- require_relative 'helper'
2
- require 'fluent/test/driver/input'
3
- require 'fluent/engine'
4
- require 'fluent/log'
5
- require 'timecop'
6
- require 'logger'
7
- require 'securerandom'
8
- require 'pathname'
9
-
10
- class LogTest < Test::Unit::TestCase
11
- def tmp_dir
12
- File.join(File.dirname(__FILE__), "tmp", "log", "#{ENV['TEST_ENV_NUMBER']}", SecureRandom.hex(10))
13
- end
14
-
15
- def setup
16
- @tmp_dir = tmp_dir
17
- FileUtils.mkdir_p(@tmp_dir)
18
- @log_device = Fluent::Test::DummyLogDevice.new
19
- @timestamp = Time.parse("2016-04-21 02:58:41 +0000")
20
- @timestamp_str = @timestamp.strftime("%Y-%m-%d %H:%M:%S %z")
21
- Timecop.freeze(@timestamp)
22
- end
23
-
24
- def teardown
25
- @log_device.reset
26
- Timecop.return
27
- Thread.current[:last_repeated_stacktrace] = nil
28
- begin
29
- FileUtils.rm_rf(@tmp_dir)
30
- rescue Errno::EACCES
31
- # It may occur on Windows because of delete pending state due to delayed GC.
32
- # Ruby 3.2 or later doesn't ignore Errno::EACCES:
33
- # https://github.com/ruby/ruby/commit/983115cf3c8f75b1afbe3274f02c1529e1ce3a81
34
- end
35
- end
36
-
37
- def test_per_process_path
38
- path = Fluent::Log.per_process_path("C:/tmp/test.log", :supervisor, 0)
39
- assert_equal(path, "C:/tmp/test-supervisor-0.log")
40
-
41
- path = Fluent::Log.per_process_path("C:/tmp/test.log", :worker, 1)
42
- assert_equal(path, "C:/tmp/test-1.log")
43
- end
44
-
45
- sub_test_case "log level" do
46
- data(
47
- trace: [Fluent::Log::LEVEL_TRACE, 0],
48
- debug: [Fluent::Log::LEVEL_DEBUG, 1],
49
- info: [Fluent::Log::LEVEL_INFO, 2],
50
- warn: [Fluent::Log::LEVEL_WARN, 3],
51
- error: [Fluent::Log::LEVEL_ERROR, 4],
52
- fatal: [Fluent::Log::LEVEL_FATAL, 5],
53
- )
54
- def test_output(data)
55
- log_level, start = data
56
- logdev = @log_device
57
- logger = ServerEngine::DaemonLogger.new(logdev)
58
- log = Fluent::Log.new(logger)
59
- log.level = log_level
60
- log.trace "trace log"
61
- log.debug "debug log"
62
- log.info "info log"
63
- log.warn "warn log"
64
- log.error "error log"
65
- log.fatal "fatal log"
66
- expected = [
67
- "#{@timestamp_str} [trace]: trace log\n",
68
- "#{@timestamp_str} [debug]: debug log\n",
69
- "#{@timestamp_str} [info]: info log\n",
70
- "#{@timestamp_str} [warn]: warn log\n",
71
- "#{@timestamp_str} [error]: error log\n",
72
- "#{@timestamp_str} [fatal]: fatal log\n"
73
- ][start..-1]
74
- assert_equal(expected, log.out.logs)
75
- end
76
-
77
- data(
78
- trace: [ServerEngine::DaemonLogger::TRACE, 0],
79
- debug: [ServerEngine::DaemonLogger::DEBUG, 1],
80
- info: [ServerEngine::DaemonLogger::INFO, 2],
81
- warn: [ServerEngine::DaemonLogger::WARN, 3],
82
- error: [ServerEngine::DaemonLogger::ERROR, 4],
83
- fatal: [ServerEngine::DaemonLogger::FATAL, 5],
84
- )
85
- def test_output_with_serverengine_loglevel(data)
86
- log_level, start = data
87
-
88
- dl_opts = {}
89
- dl_opts[:log_level] = log_level
90
- logdev = @log_device
91
- logger = ServerEngine::DaemonLogger.new(logdev, dl_opts)
92
- log = Fluent::Log.new(logger)
93
- log.trace "trace log"
94
- log.debug "debug log"
95
- log.info "info log"
96
- log.warn "warn log"
97
- log.error "error log"
98
- log.fatal "fatal log"
99
- expected = [
100
- "#{@timestamp_str} [trace]: trace log\n",
101
- "#{@timestamp_str} [debug]: debug log\n",
102
- "#{@timestamp_str} [info]: info log\n",
103
- "#{@timestamp_str} [warn]: warn log\n",
104
- "#{@timestamp_str} [error]: error log\n",
105
- "#{@timestamp_str} [fatal]: fatal log\n"
106
- ][start..-1]
107
- assert_equal(expected, log.out.logs)
108
- end
109
-
110
- data(
111
- trace: [Fluent::Log::LEVEL_TRACE, 0],
112
- debug: [Fluent::Log::LEVEL_DEBUG, 1],
113
- info: [Fluent::Log::LEVEL_INFO, 2],
114
- warn: [Fluent::Log::LEVEL_WARN, 3],
115
- error: [Fluent::Log::LEVEL_ERROR, 4],
116
- fatal: [Fluent::Log::LEVEL_FATAL, 5],
117
- )
118
- def test_output_with_block(data)
119
- log_level, start = data
120
-
121
- logdev = @log_device
122
- logger = ServerEngine::DaemonLogger.new(logdev)
123
- log = Fluent::Log.new(logger)
124
- log.level = log_level
125
- log.trace { "trace log" }
126
- log.debug { "debug log" }
127
- log.info { "info log" }
128
- log.warn { "warn log" }
129
- log.error { "error log" }
130
- log.fatal { "fatal log" }
131
- expected = [
132
- "#{@timestamp_str} [trace]: trace log\n",
133
- "#{@timestamp_str} [debug]: debug log\n",
134
- "#{@timestamp_str} [info]: info log\n",
135
- "#{@timestamp_str} [warn]: warn log\n",
136
- "#{@timestamp_str} [error]: error log\n",
137
- "#{@timestamp_str} [fatal]: fatal log\n"
138
- ][start..-1]
139
- assert_equal(expected, log.out.logs)
140
- end
141
-
142
- data(
143
- trace: [ServerEngine::DaemonLogger::TRACE, 0],
144
- debug: [ServerEngine::DaemonLogger::DEBUG, 1],
145
- info: [ServerEngine::DaemonLogger::INFO, 2],
146
- warn: [ServerEngine::DaemonLogger::WARN, 3],
147
- error: [ServerEngine::DaemonLogger::ERROR, 4],
148
- fatal: [ServerEngine::DaemonLogger::FATAL, 5],
149
- )
150
- def test_output_with_block_with_serverengine_loglevel(data)
151
- log_level, start = data
152
-
153
- dl_opts = {}
154
- dl_opts[:log_level] = log_level
155
- logdev = @log_device
156
- logger = ServerEngine::DaemonLogger.new(logdev, dl_opts)
157
- log = Fluent::Log.new(logger)
158
- log.trace { "trace log" }
159
- log.debug { "debug log" }
160
- log.info { "info log" }
161
- log.warn { "warn log" }
162
- log.error { "error log" }
163
- log.fatal { "fatal log" }
164
- expected = [
165
- "#{@timestamp_str} [trace]: trace log\n",
166
- "#{@timestamp_str} [debug]: debug log\n",
167
- "#{@timestamp_str} [info]: info log\n",
168
- "#{@timestamp_str} [warn]: warn log\n",
169
- "#{@timestamp_str} [error]: error log\n",
170
- "#{@timestamp_str} [fatal]: fatal log\n"
171
- ][start..-1]
172
- assert_equal(expected, log.out.logs)
173
- end
174
-
175
- data(
176
- trace: [Fluent::Log::LEVEL_TRACE, { trace: true, debug: true, info: true, warn: true, error: true, fatal: true }],
177
- debug: [Fluent::Log::LEVEL_DEBUG, { trace: false, debug: true, info: true, warn: true, error: true, fatal: true }],
178
- info: [Fluent::Log::LEVEL_INFO, { trace: false, debug: false, info: true, warn: true, error: true, fatal: true }],
179
- warn: [Fluent::Log::LEVEL_WARN, { trace: false, debug: false, info: false, warn: true, error: true, fatal: true }],
180
- error: [Fluent::Log::LEVEL_ERROR, { trace: false, debug: false, info: false, warn: false, error: true, fatal: true }],
181
- fatal: [Fluent::Log::LEVEL_FATAL, { trace: false, debug: false, info: false, warn: false, error: false, fatal: true }],
182
- )
183
- def test_execute_block(data)
184
- log_level, expected = data
185
- logdev = @log_device
186
- logger = ServerEngine::DaemonLogger.new(logdev)
187
- log = Fluent::Log.new(logger)
188
- log.level = log_level
189
- block_called = {
190
- trace: false,
191
- debug: false,
192
- info: false,
193
- warn: false,
194
- error: false,
195
- fatal: false,
196
- }
197
- log.trace { block_called[:trace] = true }
198
- log.debug { block_called[:debug] = true }
199
- log.info { block_called[:info] = true }
200
- log.warn { block_called[:warn] = true }
201
- log.error { block_called[:error] = true }
202
- log.fatal { block_called[:fatal] = true }
203
- assert_equal(expected, block_called)
204
- end
205
-
206
- data(
207
- trace: [ServerEngine::DaemonLogger::TRACE, { trace: true, debug: true, info: true, warn: true, error: true, fatal: true }],
208
- debug: [ServerEngine::DaemonLogger::DEBUG, { trace: false, debug: true, info: true, warn: true, error: true, fatal: true }],
209
- info: [ServerEngine::DaemonLogger::INFO, { trace: false, debug: false, info: true, warn: true, error: true, fatal: true }],
210
- warn: [ServerEngine::DaemonLogger::WARN, { trace: false, debug: false, info: false, warn: true, error: true, fatal: true }],
211
- error: [ServerEngine::DaemonLogger::ERROR, { trace: false, debug: false, info: false, warn: false, error: true, fatal: true }],
212
- fatal: [ServerEngine::DaemonLogger::FATAL, { trace: false, debug: false, info: false, warn: false, error: false, fatal: true }],
213
- )
214
- def test_execute_block_with_serverengine_loglevel(data)
215
- log_level, expected = data
216
- dl_opts = {}
217
- dl_opts[:log_level] = log_level
218
- logdev = @log_device
219
- logger = ServerEngine::DaemonLogger.new(logdev, dl_opts)
220
- log = Fluent::Log.new(logger)
221
- block_called = {
222
- trace: false,
223
- debug: false,
224
- info: false,
225
- warn: false,
226
- error: false,
227
- fatal: false,
228
- }
229
- log.trace { block_called[:trace] = true }
230
- log.debug { block_called[:debug] = true }
231
- log.info { block_called[:info] = true }
232
- log.warn { block_called[:warn] = true }
233
- log.error { block_called[:error] = true }
234
- log.fatal { block_called[:fatal] = true }
235
- assert_equal(expected, block_called)
236
- end
237
-
238
- data(
239
- trace: [Fluent::Log::LEVEL_TRACE, 0],
240
- debug: [Fluent::Log::LEVEL_DEBUG, 3],
241
- info: [Fluent::Log::LEVEL_INFO, 6],
242
- warn: [Fluent::Log::LEVEL_WARN, 9],
243
- error: [Fluent::Log::LEVEL_ERROR, 12],
244
- fatal: [Fluent::Log::LEVEL_FATAL, 15],
245
- )
246
- def test_backtrace(data)
247
- log_level, start = data
248
- backtrace = ["line 1", "line 2", "line 3"]
249
- logdev = @log_device
250
- logger = ServerEngine::DaemonLogger.new(logdev)
251
- log = Fluent::Log.new(logger)
252
- log.level = log_level
253
- log.trace_backtrace(backtrace)
254
- log.debug_backtrace(backtrace)
255
- log.info_backtrace(backtrace)
256
- log.warn_backtrace(backtrace)
257
- log.error_backtrace(backtrace)
258
- log.fatal_backtrace(backtrace)
259
- expected = [
260
- " #{@timestamp_str} [trace]: line 1\n",
261
- " #{@timestamp_str} [trace]: line 2\n",
262
- " #{@timestamp_str} [trace]: line 3\n",
263
- " #{@timestamp_str} [debug]: line 1\n",
264
- " #{@timestamp_str} [debug]: line 2\n",
265
- " #{@timestamp_str} [debug]: line 3\n",
266
- " #{@timestamp_str} [info]: line 1\n",
267
- " #{@timestamp_str} [info]: line 2\n",
268
- " #{@timestamp_str} [info]: line 3\n",
269
- " #{@timestamp_str} [warn]: line 1\n",
270
- " #{@timestamp_str} [warn]: line 2\n",
271
- " #{@timestamp_str} [warn]: line 3\n",
272
- " #{@timestamp_str} [error]: line 1\n",
273
- " #{@timestamp_str} [error]: line 2\n",
274
- " #{@timestamp_str} [error]: line 3\n",
275
- " #{@timestamp_str} [fatal]: line 1\n",
276
- " #{@timestamp_str} [fatal]: line 2\n",
277
- " #{@timestamp_str} [fatal]: line 3\n"
278
- ][start..-1]
279
- assert_equal(expected, log.out.logs)
280
- end
281
-
282
- data(
283
- trace: [ServerEngine::DaemonLogger::TRACE, 0],
284
- debug: [ServerEngine::DaemonLogger::DEBUG, 3],
285
- info: [ServerEngine::DaemonLogger::INFO, 6],
286
- warn: [ServerEngine::DaemonLogger::WARN, 9],
287
- error: [ServerEngine::DaemonLogger::ERROR, 12],
288
- fatal: [ServerEngine::DaemonLogger::FATAL, 15],
289
- )
290
- def test_backtrace_with_serverengine_loglevel(data)
291
- log_level, start = data
292
- backtrace = ["line 1", "line 2", "line 3"]
293
- dl_opts = {}
294
- dl_opts[:log_level] = log_level
295
- logdev = @log_device
296
- logger = ServerEngine::DaemonLogger.new(logdev, dl_opts)
297
- log = Fluent::Log.new(logger)
298
- log.trace_backtrace(backtrace)
299
- log.debug_backtrace(backtrace)
300
- log.info_backtrace(backtrace)
301
- log.warn_backtrace(backtrace)
302
- log.error_backtrace(backtrace)
303
- log.fatal_backtrace(backtrace)
304
- expected = [
305
- " #{@timestamp_str} [trace]: line 1\n",
306
- " #{@timestamp_str} [trace]: line 2\n",
307
- " #{@timestamp_str} [trace]: line 3\n",
308
- " #{@timestamp_str} [debug]: line 1\n",
309
- " #{@timestamp_str} [debug]: line 2\n",
310
- " #{@timestamp_str} [debug]: line 3\n",
311
- " #{@timestamp_str} [info]: line 1\n",
312
- " #{@timestamp_str} [info]: line 2\n",
313
- " #{@timestamp_str} [info]: line 3\n",
314
- " #{@timestamp_str} [warn]: line 1\n",
315
- " #{@timestamp_str} [warn]: line 2\n",
316
- " #{@timestamp_str} [warn]: line 3\n",
317
- " #{@timestamp_str} [error]: line 1\n",
318
- " #{@timestamp_str} [error]: line 2\n",
319
- " #{@timestamp_str} [error]: line 3\n",
320
- " #{@timestamp_str} [fatal]: line 1\n",
321
- " #{@timestamp_str} [fatal]: line 2\n",
322
- " #{@timestamp_str} [fatal]: line 3\n"
323
- ][start..-1]
324
- assert_equal(expected, log.out.logs)
325
- end
326
- end
327
-
328
- sub_test_case "suppress repeated backtrace" do
329
- def test_same_log_level
330
- backtrace = ["line 1", "line 2", "line 3"]
331
- dl_opts = {}
332
- dl_opts[:log_level] = ServerEngine::DaemonLogger::TRACE
333
- logdev = @log_device
334
- logger = ServerEngine::DaemonLogger.new(logdev, dl_opts)
335
- opts = {}
336
- opts[:suppress_repeated_stacktrace] = true
337
- log = Fluent::Log.new(logger, opts)
338
- log.trace_backtrace(backtrace)
339
- log.trace_backtrace(backtrace)
340
- log.trace_backtrace(backtrace + ["line 4"])
341
- log.trace_backtrace(backtrace)
342
- log.trace_backtrace(backtrace)
343
- expected = [
344
- " #{@timestamp_str} [trace]: line 1\n",
345
- " #{@timestamp_str} [trace]: line 2\n",
346
- " #{@timestamp_str} [trace]: line 3\n",
347
- " #{@timestamp_str} [trace]: suppressed same stacktrace\n",
348
- " #{@timestamp_str} [trace]: line 1\n",
349
- " #{@timestamp_str} [trace]: line 2\n",
350
- " #{@timestamp_str} [trace]: line 3\n",
351
- " #{@timestamp_str} [trace]: line 4\n",
352
- " #{@timestamp_str} [trace]: line 1\n",
353
- " #{@timestamp_str} [trace]: line 2\n",
354
- " #{@timestamp_str} [trace]: line 3\n",
355
- " #{@timestamp_str} [trace]: suppressed same stacktrace\n",
356
- ]
357
- assert_equal(expected, log.out.logs)
358
- end
359
-
360
- def test_different_log_level
361
- backtrace = ["line 1", "line 2", "line 3"]
362
- dl_opts = {}
363
- dl_opts[:log_level] = ServerEngine::DaemonLogger::TRACE
364
- logdev = @log_device
365
- logger = ServerEngine::DaemonLogger.new(logdev, dl_opts)
366
- opts = {}
367
- opts[:suppress_repeated_stacktrace] = true
368
- log = Fluent::Log.new(logger, opts)
369
- log.trace_backtrace(backtrace)
370
- log.debug_backtrace(backtrace)
371
- log.info_backtrace(backtrace)
372
- log.warn_backtrace(backtrace)
373
- log.error_backtrace(backtrace)
374
- log.fatal_backtrace(backtrace)
375
- expected = [
376
- " #{@timestamp_str} [trace]: line 1\n",
377
- " #{@timestamp_str} [trace]: line 2\n",
378
- " #{@timestamp_str} [trace]: line 3\n",
379
- " #{@timestamp_str} [debug]: suppressed same stacktrace\n",
380
- " #{@timestamp_str} [info]: suppressed same stacktrace\n",
381
- " #{@timestamp_str} [warn]: suppressed same stacktrace\n",
382
- " #{@timestamp_str} [error]: suppressed same stacktrace\n",
383
- " #{@timestamp_str} [fatal]: suppressed same stacktrace\n",
384
- ]
385
- assert_equal(expected, log.out.logs)
386
- end
387
- end
388
-
389
- sub_test_case "ignore_repeated_log_interval" do
390
- def test_same_message
391
- message = "This is test"
392
- logger = ServerEngine::DaemonLogger.new(@log_device, {log_level: ServerEngine::DaemonLogger::INFO})
393
- log = Fluent::Log.new(logger, {ignore_repeated_log_interval: 5})
394
-
395
- log.error message
396
- 10.times { |i|
397
- Timecop.freeze(@timestamp + i)
398
- log.error message
399
- }
400
-
401
- expected = [
402
- "2016-04-21 02:58:41 +0000 [error]: This is test\n",
403
- "2016-04-21 02:58:47 +0000 [error]: This is test\n"
404
- ]
405
- assert_equal(expected, log.out.logs)
406
- end
407
-
408
- def test_different_message
409
- message = "This is test"
410
- logger = ServerEngine::DaemonLogger.new(@log_device, {log_level: ServerEngine::DaemonLogger::INFO})
411
- log = Fluent::Log.new(logger, {ignore_repeated_log_interval: 10})
412
-
413
- log.error message
414
- 3.times { |i|
415
- Timecop.freeze(@timestamp + i)
416
- log.error message
417
- log.error message
418
- log.info "Hello! " + message
419
- }
420
-
421
- expected = [
422
- "2016-04-21 02:58:41 +0000 [error]: This is test\n",
423
- "2016-04-21 02:58:41 +0000 [info]: Hello! This is test\n",
424
- "2016-04-21 02:58:42 +0000 [error]: This is test\n",
425
- "2016-04-21 02:58:42 +0000 [info]: Hello! This is test\n",
426
- "2016-04-21 02:58:43 +0000 [error]: This is test\n",
427
- "2016-04-21 02:58:43 +0000 [info]: Hello! This is test\n",
428
- ]
429
- assert_equal(expected, log.out.logs)
430
- end
431
- end
432
-
433
- sub_test_case "ignore_same_log_interval" do
434
- teardown do
435
- Thread.current[:last_same_log] = nil
436
- end
437
-
438
- def test_same_message
439
- message = "This is test"
440
- logger = ServerEngine::DaemonLogger.new(@log_device, {log_level: ServerEngine::DaemonLogger::INFO})
441
- log = Fluent::Log.new(logger, {ignore_same_log_interval: 5})
442
-
443
- log.error message
444
- 10.times { |i|
445
- Timecop.freeze(@timestamp + i + 1)
446
- log.error message
447
- }
448
-
449
- expected = [
450
- "2016-04-21 02:58:41 +0000 [error]: This is test\n",
451
- "2016-04-21 02:58:47 +0000 [error]: This is test\n"
452
- ]
453
- assert_equal(expected, log.out.logs)
454
- end
455
-
456
- def test_different_message
457
- message = "This is test"
458
- logger = ServerEngine::DaemonLogger.new(@log_device, {log_level: ServerEngine::DaemonLogger::INFO})
459
- log = Fluent::Log.new(logger, {ignore_same_log_interval: 10})
460
-
461
- log.error message
462
- 3.times { |i|
463
- Timecop.freeze(@timestamp + i)
464
- log.error message
465
- log.error message
466
- log.info "Hello! " + message
467
- }
468
-
469
- expected = [
470
- "2016-04-21 02:58:41 +0000 [error]: This is test\n",
471
- "2016-04-21 02:58:41 +0000 [info]: Hello! This is test\n",
472
- ]
473
- assert_equal(expected, log.out.logs)
474
- end
475
-
476
- def test_reject_on_max_size
477
- ignore_same_log_interval = 10
478
-
479
- logger = Fluent::Log.new(
480
- ServerEngine::DaemonLogger.new(@log_device, log_level: ServerEngine::DaemonLogger::INFO),
481
- ignore_same_log_interval: ignore_same_log_interval,
482
- )
483
-
484
- # Output unique log every second.
485
- Fluent::Log::IGNORE_SAME_LOG_MAX_CACHE_SIZE.times do |i|
486
- logger.info "Test #{i}"
487
- Timecop.freeze(@timestamp + i)
488
- end
489
- logger.info "Over max size!"
490
-
491
- # The newest cache and the latest caches in `ignore_same_log_interval` should exist.
492
- assert { Thread.current[:last_same_log].size == ignore_same_log_interval + 1 }
493
- end
494
-
495
- def test_clear_on_max_size
496
- ignore_same_log_interval = 10
497
-
498
- logger = Fluent::Log.new(
499
- ServerEngine::DaemonLogger.new(@log_device, log_level: ServerEngine::DaemonLogger::INFO),
500
- ignore_same_log_interval: ignore_same_log_interval,
501
- )
502
-
503
- # Output unique log at the same time.
504
- Fluent::Log::IGNORE_SAME_LOG_MAX_CACHE_SIZE.times do |i|
505
- logger.info "Test #{i}"
506
- end
507
- logger.info "Over max size!"
508
-
509
- # Can't reject old logs, so all cache should be cleared and only the newest should exist.
510
- assert { Thread.current[:last_same_log].size == 1 }
511
- end
512
- end
513
-
514
- def test_dup
515
- dl_opts = {}
516
- dl_opts[:log_level] = ServerEngine::DaemonLogger::TRACE
517
- logdev = @log_device
518
- logger = ServerEngine::DaemonLogger.new(logdev, dl_opts)
519
- log1 = Fluent::Log.new(logger)
520
- log2 = log1.dup
521
- log1.level = Fluent::Log::LEVEL_DEBUG
522
- assert_equal(Fluent::Log::LEVEL_DEBUG, log1.level)
523
- assert_equal(Fluent::Log::LEVEL_TRACE, log2.level)
524
- end
525
-
526
- def test_format_json
527
- logdev = @log_device
528
- logger = ServerEngine::DaemonLogger.new(logdev)
529
- log = Fluent::Log.new(logger)
530
- log.format = :json
531
- log.level = Fluent::Log::LEVEL_TRACE
532
- log.trace "trace log"
533
- log.debug "debug log"
534
- log.info "info log"
535
- log.warn "warn log"
536
- log.error "error log"
537
- log.fatal "fatal log"
538
- expected = [
539
- "#{@timestamp_str} [trace]: trace log\n",
540
- "#{@timestamp_str} [debug]: debug log\n",
541
- "#{@timestamp_str} [info]: info log\n",
542
- "#{@timestamp_str} [warn]: warn log\n",
543
- "#{@timestamp_str} [error]: error log\n",
544
- "#{@timestamp_str} [fatal]: fatal log\n"
545
- ]
546
- assert_equal(expected, log.out.logs.map { |l|
547
- r = JSON.parse(l)
548
- "#{r['time']} [#{r['level']}]: #{r['message']}\n"
549
- })
550
- end
551
-
552
- def test_time_format
553
- logdev = @log_device
554
- logger = ServerEngine::DaemonLogger.new(logdev)
555
- log = Fluent::Log.new(logger)
556
- log.time_format = "%Y"
557
- log.level = Fluent::Log::LEVEL_TRACE
558
- log.trace "trace log"
559
- log.debug "debug log"
560
- log.info "info log"
561
- log.warn "warn log"
562
- log.error "error log"
563
- log.fatal "fatal log"
564
- timestamp_str = @timestamp.strftime("%Y")
565
- expected = [
566
- "#{timestamp_str} [trace]: trace log\n",
567
- "#{timestamp_str} [debug]: debug log\n",
568
- "#{timestamp_str} [info]: info log\n",
569
- "#{timestamp_str} [warn]: warn log\n",
570
- "#{timestamp_str} [error]: error log\n",
571
- "#{timestamp_str} [fatal]: fatal log\n"
572
- ]
573
- assert_equal(expected, log.out.logs)
574
- end
575
-
576
- def test_disable_events
577
- dl_opts = {}
578
- dl_opts[:log_level] = ServerEngine::DaemonLogger::TRACE
579
- logdev = @log_device
580
- logger = ServerEngine::DaemonLogger.new(logdev, dl_opts)
581
- log = Fluent::Log.new(logger)
582
- log.enable_event(true)
583
- engine = log.instance_variable_get("@engine")
584
- mock(engine).push_log_event(anything, anything, anything).once
585
- log.trace "trace log"
586
- log.disable_events(Thread.current)
587
- log.trace "trace log"
588
- end
589
-
590
- def test_level_reload
591
- dl_opts = {}
592
- dl_opts[:log_level] = ServerEngine::DaemonLogger::TRACE
593
- logdev = @log_device
594
- logger = ServerEngine::DaemonLogger.new(logdev, dl_opts)
595
- log = Fluent::Log.new(logger)
596
- assert_equal(ServerEngine::DaemonLogger::TRACE, logger.level)
597
- assert_equal(Fluent::Log::LEVEL_TRACE, log.level)
598
- # change daemon logger side level
599
- logger.level = ServerEngine::DaemonLogger::DEBUG
600
- assert_equal(ServerEngine::DaemonLogger::DEBUG, logger.level)
601
- # check fluentd log side level is also changed
602
- assert_equal(Fluent::Log::LEVEL_DEBUG, log.level)
603
- end
604
-
605
- DAY_SEC = 60 * 60 * 24
606
- data(
607
- rotate_daily_age: ['daily', 100000, DAY_SEC + 1],
608
- rotate_weekly_age: ['weekly', 100000, DAY_SEC * 7 + 1],
609
- rotate_monthly_age: ['monthly', 100000, DAY_SEC * 31 + 1],
610
- rotate_size: [1, 100, 0, '0'],
611
- )
612
- def test_log_with_logdevio(expected)
613
- with_timezone('utc') do
614
- @timestamp = Time.parse("2016-04-21 00:00:00 +0000")
615
- @timestamp_str = @timestamp.strftime("%Y-%m-%d %H:%M:%S %z")
616
- Timecop.freeze(@timestamp)
617
-
618
- rotate_age, rotate_size, travel_term = expected
619
- path = "#{@tmp_dir}/log-dev-io-#{rotate_size}-#{rotate_age}"
620
-
621
- logdev = Fluent::LogDeviceIO.new(path, shift_age: rotate_age, shift_size: rotate_size)
622
- logger = ServerEngine::DaemonLogger.new(logdev)
623
- log = Fluent::Log.new(logger)
624
-
625
- msg = 'a' * 101
626
- log.info msg
627
- assert_match msg, File.read(path)
628
-
629
- Timecop.freeze(@timestamp + travel_term)
630
-
631
- msg2 = 'b' * 101
632
- log.info msg2
633
- c = File.read(path)
634
-
635
- assert_match msg2, c
636
- assert_not_equal msg, c
637
- end
638
- end
639
-
640
- def test_log_rotates_specified_size_with_logdevio
641
- with_timezone('utc') do
642
- begin
643
- rotate_age = 2
644
- rotate_size = 100
645
- path = "#{@tmp_dir}/log-dev-io-#{rotate_size}-#{rotate_age}"
646
- path0 = path + '.0'
647
- path1 = path + '.1'
648
-
649
- logdev = Fluent::LogDeviceIO.new(path, shift_age: rotate_age, shift_size: rotate_size)
650
- logger = ServerEngine::DaemonLogger.new(logdev)
651
- log = Fluent::Log.new(logger)
652
-
653
- msg = 'a' * 101
654
- log.info msg
655
- assert_match msg, File.read(path)
656
- assert_true File.exist?(path)
657
- assert_true !File.exist?(path0)
658
- assert_true !File.exist?(path1)
659
-
660
- # create log.0
661
- msg2 = 'b' * 101
662
- log.info msg2
663
- c = File.read(path)
664
- c0 = File.read(path0)
665
- assert_match msg2, c
666
- assert_match msg, c0
667
- assert_true File.exist?(path)
668
- assert_true File.exist?(path0)
669
- assert_true !File.exist?(path1)
670
-
671
- # rotate
672
- msg3 = 'c' * 101
673
- log.info msg3
674
- c = File.read(path)
675
- c0 = File.read(path0)
676
- assert_match msg3, c
677
- assert_match msg2, c0
678
- assert_true File.exist?(path)
679
- assert_true File.exist?(path0)
680
- assert_true !File.exist?(path1)
681
- ensure
682
- logdev&.close
683
- end
684
- end
685
- end
686
-
687
- def test_reopen
688
- path = Pathname(@tmp_dir) + "fluent.log"
689
-
690
- logdev = Fluent::LogDeviceIO.new(path.to_s)
691
- logger = ServerEngine::DaemonLogger.new(logdev)
692
- log = Fluent::Log.new(logger, path: path)
693
-
694
- message = "This is test message."
695
-
696
- log.info message
697
- log.reopen!
698
- log.info message
699
-
700
- assert { path.read.lines.count{ |line| line.include?(message) } == 2 }
701
- # Assert reopening the same file.
702
- # Especially, on Windows, the filepath is fixed for each process with rotate,
703
- # so we need to care about this.
704
- assert { path.parent.entries.size == 3 } # [".", "..", "fluent.log"]
705
- ensure
706
- logdev&.close
707
- end
708
- end
709
-
710
- class PluginLoggerTest < Test::Unit::TestCase
711
- def setup
712
- @log_device = Fluent::Test::DummyLogDevice.new
713
- @timestamp = Time.parse("2016-04-21 02:58:41 +0000")
714
- @timestamp_str = @timestamp.strftime("%Y-%m-%d %H:%M:%S %z")
715
- Timecop.freeze(@timestamp)
716
- dl_opts = {}
717
- dl_opts[:log_level] = ServerEngine::DaemonLogger::TRACE
718
- logdev = @log_device
719
- logger = ServerEngine::DaemonLogger.new(logdev, dl_opts)
720
- @logger = Fluent::Log.new(logger)
721
- end
722
-
723
- def teardown
724
- @log_device.reset
725
- Timecop.return
726
- Thread.current[:last_repeated_stacktrace] = nil
727
- end
728
-
729
- def test_initialize
730
- log = Fluent::PluginLogger.new(@logger)
731
- logger = log.instance_variable_get("@logger")
732
- assert_equal(logger, @logger)
733
- end
734
-
735
- def test_level
736
- log = Fluent::PluginLogger.new(@logger)
737
- assert_equal(log.level, @logger.level)
738
- log.level = "fatal"
739
- assert_equal(Fluent::Log::LEVEL_FATAL, log.level)
740
- assert_equal(Fluent::Log::LEVEL_TRACE, @logger.level)
741
- end
742
-
743
- def test_enable_color
744
- log = Fluent::PluginLogger.new(@logger)
745
- log.enable_color(true)
746
- assert_equal(true, log.enable_color?)
747
- assert_equal(true, @logger.enable_color?)
748
- log.enable_color(false)
749
- assert_equal(false, log.enable_color?)
750
- assert_equal(false, @logger.enable_color?)
751
- log.enable_color
752
- assert_equal(true, log.enable_color?)
753
- assert_equal(true, @logger.enable_color?)
754
- end
755
-
756
- def test_log_type_in_default
757
- mock(@logger).caller_line(:default, Time.now, 1, Fluent::Log::LEVEL_TRACE).once
758
- mock(@logger).caller_line(:default, Time.now, 1, Fluent::Log::LEVEL_DEBUG).once
759
- mock(@logger).caller_line(:default, Time.now, 1, Fluent::Log::LEVEL_INFO).once
760
- mock(@logger).caller_line(:default, Time.now, 1, Fluent::Log::LEVEL_WARN).once
761
- mock(@logger).caller_line(:default, Time.now, 1, Fluent::Log::LEVEL_ERROR).once
762
- mock(@logger).caller_line(:default, Time.now, 1, Fluent::Log::LEVEL_FATAL).once
763
-
764
- @logger.trace "trace log 1"
765
- @logger.debug "debug log 2"
766
- @logger.info "info log 3"
767
- @logger.warn "warn log 4"
768
- @logger.error "error log 5"
769
- @logger.fatal "fatal log 6"
770
- end
771
-
772
- def test_log_types
773
- mock(@logger).caller_line(:default, Time.now, 1, Fluent::Log::LEVEL_TRACE).once
774
- mock(@logger).caller_line(:supervisor, Time.now, 1, Fluent::Log::LEVEL_DEBUG).once
775
- mock(@logger).caller_line(:worker0, Time.now, 1, Fluent::Log::LEVEL_INFO).once
776
- mock(@logger).caller_line(:default, Time.now, 1, Fluent::Log::LEVEL_WARN).once
777
- mock(@logger).caller_line(:supervisor, Time.now, 1, Fluent::Log::LEVEL_ERROR).once
778
- mock(@logger).caller_line(:worker0, Time.now, 1, Fluent::Log::LEVEL_FATAL).once
779
-
780
- @logger.trace :default, "trace log 1"
781
- @logger.debug :supervisor, "debug log 2"
782
- @logger.info :worker0, "info log 3"
783
- @logger.warn :default, "warn log 4"
784
- @logger.error :supervisor, "error log 5"
785
- @logger.fatal :worker0, "fatal log 6"
786
- end
787
-
788
- sub_test_case "supervisor process type" do
789
- setup do
790
- dl_opts = {}
791
- dl_opts[:log_level] = ServerEngine::DaemonLogger::TRACE
792
- logdev = @log_device
793
- logger = ServerEngine::DaemonLogger.new(logdev, dl_opts)
794
- @logger = Fluent::Log.new(logger, process_type: :supervisor)
795
- end
796
-
797
- test 'default type logs are shown w/o worker id' do
798
- @logger.info "yaaay"
799
- @logger.info :default, "booo"
800
- assert{ @log_device.logs.include?("#{@timestamp_str} [info]: yaaay\n") }
801
- assert{ @log_device.logs.include?("#{@timestamp_str} [info]: booo\n") }
802
- end
803
-
804
- test 'supervisor type logs are shown w/o worker id' do
805
- @logger.info :supervisor, "yaaay"
806
- assert{ @log_device.logs.include?("#{@timestamp_str} [info]: yaaay\n") }
807
- end
808
-
809
- test 'worker0 type logs are not shown' do
810
- @logger.info :worker0, "yaaay"
811
- assert{ !@log_device.logs.include?("#{@timestamp_str} [info]: yaaay\n") }
812
- end
813
- end
814
-
815
- sub_test_case "worker0 process type" do
816
- setup do
817
- dl_opts = {}
818
- dl_opts[:log_level] = ServerEngine::DaemonLogger::TRACE
819
- logdev = @log_device
820
- logger = ServerEngine::DaemonLogger.new(logdev, dl_opts)
821
- @logger = Fluent::Log.new(logger, process_type: :worker0, worker_id: 10)
822
- end
823
-
824
- test 'default type logs are shown w/ worker id' do
825
- @logger.info "yaaay"
826
- @logger.info :default, "booo"
827
- assert{ @log_device.logs.include?("#{@timestamp_str} [info]: #10 yaaay\n") }
828
- assert{ @log_device.logs.include?("#{@timestamp_str} [info]: #10 booo\n") }
829
- end
830
-
831
- test 'supervisor type logs are not shown' do
832
- @logger.info :supervisor, "yaaay"
833
- assert{ !@log_device.logs.include?("#{@timestamp_str} [info]: yaaay\n") }
834
- end
835
-
836
- test 'worker0 type logs are shown w/o worker id' do
837
- @logger.info :worker0, "yaaay"
838
- assert{ @log_device.logs.include?("#{@timestamp_str} [info]: yaaay\n") }
839
- end
840
- end
841
-
842
- sub_test_case "workers process type" do
843
- setup do
844
- dl_opts = {}
845
- dl_opts[:log_level] = ServerEngine::DaemonLogger::TRACE
846
- logdev = @log_device
847
- logger = ServerEngine::DaemonLogger.new(logdev, dl_opts)
848
- @logger = Fluent::Log.new(logger, process_type: :workers, worker_id: 7)
849
- end
850
-
851
- test 'default type logs are shown w/ worker id' do
852
- @logger.info "yaaay"
853
- @logger.info :default, "booo"
854
- assert{ @log_device.logs.include?("#{@timestamp_str} [info]: #7 yaaay\n") }
855
- assert{ @log_device.logs.include?("#{@timestamp_str} [info]: #7 booo\n") }
856
- end
857
-
858
- test 'supervisor type logs are not shown' do
859
- @logger.info :supervisor, "yaaay"
860
- assert{ !@log_device.logs.include?("#{@timestamp_str} [info]: yaaay\n") }
861
- end
862
-
863
- test 'worker0 type logs are not shown' do
864
- @logger.info :worker0, "yaaay"
865
- assert{ !@log_device.logs.include?("#{@timestamp_str} [info]: yaaay\n") }
866
- end
867
- end
868
-
869
- sub_test_case "standalone process type" do
870
- setup do
871
- dl_opts = {}
872
- dl_opts[:log_level] = ServerEngine::DaemonLogger::TRACE
873
- logdev = @log_device
874
- logger = ServerEngine::DaemonLogger.new(logdev, dl_opts)
875
- @logger = Fluent::Log.new(logger, process_type: :standalone, worker_id: 0)
876
- end
877
-
878
- test 'default type logs are shown w/o worker id' do
879
- @logger.info "yaaay"
880
- @logger.info :default, "booo"
881
- assert{ @log_device.logs.include?("#{@timestamp_str} [info]: yaaay\n") }
882
- assert{ @log_device.logs.include?("#{@timestamp_str} [info]: booo\n") }
883
- end
884
-
885
- test 'supervisor type logs are shown w/o worker id' do
886
- @logger.info :supervisor, "yaaay"
887
- assert{ @log_device.logs.include?("#{@timestamp_str} [info]: yaaay\n") }
888
- end
889
-
890
- test 'worker0 type logs are shown w/o worker id' do
891
- @logger.info :worker0, "yaaay"
892
- assert{ @log_device.logs.include?("#{@timestamp_str} [info]: yaaay\n") }
893
- end
894
- end
895
-
896
- sub_test_case "delegators" do
897
- def setup
898
- super
899
- @log = Fluent::PluginLogger.new(@logger)
900
- end
901
-
902
- def test_enable_debug
903
- mock(@logger).enable_debug
904
- @log.enable_debug
905
- end
906
-
907
- def test_enable_event
908
- mock(@logger).enable_event
909
- @log.enable_event
910
- end
911
-
912
- def test_disable_events
913
- mock(@logger).disable_events(Thread.current)
914
- @log.disable_events(Thread.current)
915
- end
916
-
917
- def test_event
918
- mock(@logger).event(Fluent::Log::LEVEL_TRACE, { key: "value" })
919
- @log.event(Fluent::Log::LEVEL_TRACE, { key: "value" })
920
- end
921
-
922
- def test_caller_line
923
- mock(@logger).caller_line(Time.now, 1, Fluent::Log::LEVEL_TRACE)
924
- @log.caller_line(Time.now, 1, Fluent::Log::LEVEL_TRACE)
925
- end
926
-
927
- def test_puts
928
- mock(@logger).puts("log")
929
- @log.puts("log")
930
- end
931
-
932
- def test_write
933
- mock(@logger).write("log")
934
- @log.write("log")
935
- end
936
-
937
- def test_write_alias
938
- assert(@log.respond_to?(:<<))
939
- mock(@log.out).write("log")
940
- @log << "log"
941
- end
942
-
943
- def test_out
944
- assert_equal(@log.out, @logger.out)
945
- @log.out = Object.new
946
- assert_equal(@log.out, @logger.out)
947
- end
948
-
949
- def test_optional_header
950
- assert_equal(@log.optional_header, @logger.optional_header)
951
- @log.optional_header = "optional_header"
952
- assert_equal(@log.optional_header, @logger.optional_header)
953
- end
954
-
955
- def test_optional_attrs
956
- assert_equal(@log.optional_attrs, @logger.optional_attrs)
957
- @log.optional_attrs = "optional_attrs"
958
- assert_equal(@log.optional_attrs, @logger.optional_attrs)
959
- end
960
- end
961
-
962
- sub_test_case "partially delegated" do
963
- def setup
964
- super
965
- @log = Fluent::PluginLogger.new(@logger)
966
- end
967
-
968
- data(
969
- text: [:text, "2016-04-21 02:58:41 +0000 [info]: yaaay\n"],
970
- json: [:json, %Q({"time":"2016-04-21 02:58:41 +0000","level":"info","message":"yaaay"}\n)],
971
- )
972
- def test_format(data)
973
- fmt, expected_log_line = data
974
- with_timezone('utc') {
975
- @log.format = fmt
976
- @log.info "yaaay"
977
- }
978
- assert{ @log_device.logs.include? expected_log_line }
979
- end
980
-
981
- data(
982
- text: [:text, "2016 [info]: yaaay\n"],
983
- json: [:json, %Q({"time":"2016","level":"info","message":"yaaay"}\n)],
984
- )
985
- def test_time_format(data)
986
- fmt, expected_log_line = data
987
- @log.format = fmt
988
- @log.time_format = "%Y"
989
- @log.info "yaaay"
990
- assert{ @log_device.logs.include? expected_log_line }
991
- end
992
- end
993
- end
994
-
995
- class PluginLoggerMixinTest < Test::Unit::TestCase
996
- class DummyPlugin < Fluent::Plugin::Input
997
- end
998
-
999
- def create_driver(conf)
1000
- Fluent::Test::Driver::Input.new(DummyPlugin).configure(conf)
1001
- end
1002
-
1003
- def setup
1004
- Fluent::Test.setup
1005
- end
1006
-
1007
- def test_default_log
1008
- plugin = DummyPlugin.new
1009
- log = plugin.log
1010
- assert_equal($log, log)
1011
- end
1012
-
1013
- def test_log_level
1014
- d = create_driver(%[log_level fatal])
1015
- log = d.instance.log
1016
- assert_not_equal($log.level, log.level)
1017
- assert_equal(Fluent::Log::LEVEL_FATAL, log.level)
1018
- end
1019
-
1020
- def test_optional_header
1021
- d = create_driver(%[@id myplugin])
1022
- log = d.instance.log
1023
- assert_equal("[myplugin] ", log.optional_header)
1024
- assert_equal({}, log.optional_attrs)
1025
- end
1026
-
1027
- def test_start
1028
- plugin = DummyPlugin.new
1029
- mock(plugin.log).should_receive(:reset).never
1030
- plugin.start
1031
- end
1032
-
1033
- def test_terminate
1034
- plugin = DummyPlugin.new
1035
- mock(plugin.log).reset
1036
- plugin.terminate
1037
- end
1038
- end
1039
-
1040
- class LogDeviceIOTest < Test::Unit::TestCase
1041
- test 'flush' do
1042
- io = StringIO.new
1043
- logdev = Fluent::LogDeviceIO.new(io)
1044
- assert_equal io, logdev.flush
1045
-
1046
- io.instance_eval { undef :flush }
1047
- logdev = Fluent::LogDeviceIO.new(io)
1048
- assert_raise NoMethodError do
1049
- logdev.flush
1050
- end
1051
- end
1052
-
1053
- test 'tty?' do
1054
- io = StringIO.new
1055
- logdev = Fluent::LogDeviceIO.new(io)
1056
- assert_equal io.tty?, logdev.tty?
1057
-
1058
- io.instance_eval { undef :tty? }
1059
- logdev = Fluent::LogDeviceIO.new(io)
1060
- assert_raise NoMethodError do
1061
- logdev.tty?
1062
- end
1063
- end
1064
-
1065
- test 'sync=' do
1066
- io = StringIO.new
1067
- logdev = Fluent::LogDeviceIO.new(io)
1068
- assert_true logdev.sync = true
1069
-
1070
- io.instance_eval { undef :sync= }
1071
- logdev = Fluent::LogDeviceIO.new(io)
1072
- assert_raise NoMethodError do
1073
- logdev.sync = true
1074
- end
1075
- end
1076
- end