fluentd-hubspot 0.14.14.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (396) hide show
  1. data/.github/ISSUE_TEMPLATE.md +6 -0
  2. data/.gitignore +28 -0
  3. data/.travis.yml +51 -0
  4. data/AUTHORS +2 -0
  5. data/CONTRIBUTING.md +42 -0
  6. data/COPYING +14 -0
  7. data/ChangeLog +593 -0
  8. data/Gemfile +9 -0
  9. data/README.md +76 -0
  10. data/Rakefile +74 -0
  11. data/Vagrantfile +17 -0
  12. data/appveyor.yml +43 -0
  13. data/bin/fluent-binlog-reader +7 -0
  14. data/bin/fluent-debug +5 -0
  15. data/bin/fluent-plugin-config-format +5 -0
  16. data/bin/fluent-plugin-generate +5 -0
  17. data/code-of-conduct.md +3 -0
  18. data/example/copy_roundrobin.conf +39 -0
  19. data/example/filter_stdout.conf +22 -0
  20. data/example/in_dummy_blocks.conf +17 -0
  21. data/example/in_dummy_with_compression.conf +23 -0
  22. data/example/in_forward.conf +14 -0
  23. data/example/in_forward_client.conf +37 -0
  24. data/example/in_forward_shared_key.conf +15 -0
  25. data/example/in_forward_tls.conf +14 -0
  26. data/example/in_forward_users.conf +24 -0
  27. data/example/in_forward_workers.conf +21 -0
  28. data/example/in_http.conf +14 -0
  29. data/example/in_out_forward.conf +17 -0
  30. data/example/in_syslog.conf +15 -0
  31. data/example/in_tail.conf +14 -0
  32. data/example/in_tcp.conf +13 -0
  33. data/example/in_udp.conf +13 -0
  34. data/example/logevents.conf +25 -0
  35. data/example/multi_filters.conf +61 -0
  36. data/example/out_copy.conf +20 -0
  37. data/example/out_exec_filter.conf +42 -0
  38. data/example/out_file.conf +13 -0
  39. data/example/out_forward.conf +35 -0
  40. data/example/out_forward_buf_file.conf +23 -0
  41. data/example/out_forward_client.conf +109 -0
  42. data/example/out_forward_heartbeat_none.conf +16 -0
  43. data/example/out_forward_shared_key.conf +36 -0
  44. data/example/out_forward_tls.conf +18 -0
  45. data/example/out_forward_users.conf +65 -0
  46. data/example/out_null.conf +36 -0
  47. data/example/secondary_file.conf +41 -0
  48. data/example/suppress_config_dump.conf +7 -0
  49. data/example/v0_12_filter.conf +78 -0
  50. data/example/v1_literal_example.conf +36 -0
  51. data/fluent.conf +139 -0
  52. data/fluentd.gemspec +51 -0
  53. data/lib/fluent/agent.rb +163 -0
  54. data/lib/fluent/clock.rb +62 -0
  55. data/lib/fluent/command/binlog_reader.rb +234 -0
  56. data/lib/fluent/command/bundler_injection.rb +45 -0
  57. data/lib/fluent/command/cat.rb +330 -0
  58. data/lib/fluent/command/debug.rb +102 -0
  59. data/lib/fluent/command/fluentd.rb +301 -0
  60. data/lib/fluent/command/plugin_config_formatter.rb +258 -0
  61. data/lib/fluent/command/plugin_generator.rb +301 -0
  62. data/lib/fluent/compat/call_super_mixin.rb +67 -0
  63. data/lib/fluent/compat/detach_process_mixin.rb +25 -0
  64. data/lib/fluent/compat/exec_util.rb +129 -0
  65. data/lib/fluent/compat/file_util.rb +54 -0
  66. data/lib/fluent/compat/filter.rb +68 -0
  67. data/lib/fluent/compat/formatter.rb +111 -0
  68. data/lib/fluent/compat/formatter_utils.rb +85 -0
  69. data/lib/fluent/compat/handle_tag_and_time_mixin.rb +62 -0
  70. data/lib/fluent/compat/handle_tag_name_mixin.rb +53 -0
  71. data/lib/fluent/compat/input.rb +59 -0
  72. data/lib/fluent/compat/output.rb +728 -0
  73. data/lib/fluent/compat/output_chain.rb +60 -0
  74. data/lib/fluent/compat/parser.rb +310 -0
  75. data/lib/fluent/compat/parser_utils.rb +40 -0
  76. data/lib/fluent/compat/propagate_default.rb +62 -0
  77. data/lib/fluent/compat/record_filter_mixin.rb +34 -0
  78. data/lib/fluent/compat/set_tag_key_mixin.rb +50 -0
  79. data/lib/fluent/compat/set_time_key_mixin.rb +69 -0
  80. data/lib/fluent/compat/socket_util.rb +165 -0
  81. data/lib/fluent/compat/string_util.rb +34 -0
  82. data/lib/fluent/compat/structured_format_mixin.rb +26 -0
  83. data/lib/fluent/compat/type_converter.rb +90 -0
  84. data/lib/fluent/config.rb +56 -0
  85. data/lib/fluent/config/basic_parser.rb +123 -0
  86. data/lib/fluent/config/configure_proxy.rb +418 -0
  87. data/lib/fluent/config/dsl.rb +149 -0
  88. data/lib/fluent/config/element.rb +218 -0
  89. data/lib/fluent/config/error.rb +26 -0
  90. data/lib/fluent/config/literal_parser.rb +251 -0
  91. data/lib/fluent/config/parser.rb +107 -0
  92. data/lib/fluent/config/section.rb +223 -0
  93. data/lib/fluent/config/types.rb +136 -0
  94. data/lib/fluent/config/v1_parser.rb +190 -0
  95. data/lib/fluent/configurable.rb +200 -0
  96. data/lib/fluent/daemon.rb +15 -0
  97. data/lib/fluent/engine.rb +266 -0
  98. data/lib/fluent/env.rb +28 -0
  99. data/lib/fluent/error.rb +30 -0
  100. data/lib/fluent/event.rb +334 -0
  101. data/lib/fluent/event_router.rb +269 -0
  102. data/lib/fluent/filter.rb +21 -0
  103. data/lib/fluent/formatter.rb +23 -0
  104. data/lib/fluent/input.rb +21 -0
  105. data/lib/fluent/label.rb +46 -0
  106. data/lib/fluent/load.rb +35 -0
  107. data/lib/fluent/log.rb +546 -0
  108. data/lib/fluent/match.rb +178 -0
  109. data/lib/fluent/mixin.rb +31 -0
  110. data/lib/fluent/msgpack_factory.rb +62 -0
  111. data/lib/fluent/output.rb +29 -0
  112. data/lib/fluent/output_chain.rb +23 -0
  113. data/lib/fluent/parser.rb +23 -0
  114. data/lib/fluent/plugin.rb +183 -0
  115. data/lib/fluent/plugin/bare_output.rb +63 -0
  116. data/lib/fluent/plugin/base.rb +165 -0
  117. data/lib/fluent/plugin/buf_file.rb +184 -0
  118. data/lib/fluent/plugin/buf_memory.rb +34 -0
  119. data/lib/fluent/plugin/buffer.rb +617 -0
  120. data/lib/fluent/plugin/buffer/chunk.rb +221 -0
  121. data/lib/fluent/plugin/buffer/file_chunk.rb +364 -0
  122. data/lib/fluent/plugin/buffer/memory_chunk.rb +90 -0
  123. data/lib/fluent/plugin/compressable.rb +92 -0
  124. data/lib/fluent/plugin/exec_util.rb +22 -0
  125. data/lib/fluent/plugin/file_util.rb +22 -0
  126. data/lib/fluent/plugin/file_wrapper.rb +120 -0
  127. data/lib/fluent/plugin/filter.rb +93 -0
  128. data/lib/fluent/plugin/filter_grep.rb +75 -0
  129. data/lib/fluent/plugin/filter_parser.rb +119 -0
  130. data/lib/fluent/plugin/filter_record_transformer.rb +322 -0
  131. data/lib/fluent/plugin/filter_stdout.rb +53 -0
  132. data/lib/fluent/plugin/formatter.rb +50 -0
  133. data/lib/fluent/plugin/formatter_csv.rb +52 -0
  134. data/lib/fluent/plugin/formatter_hash.rb +33 -0
  135. data/lib/fluent/plugin/formatter_json.rb +55 -0
  136. data/lib/fluent/plugin/formatter_ltsv.rb +42 -0
  137. data/lib/fluent/plugin/formatter_msgpack.rb +33 -0
  138. data/lib/fluent/plugin/formatter_out_file.rb +51 -0
  139. data/lib/fluent/plugin/formatter_single_value.rb +34 -0
  140. data/lib/fluent/plugin/formatter_stdout.rb +75 -0
  141. data/lib/fluent/plugin/formatter_tsv.rb +34 -0
  142. data/lib/fluent/plugin/in_debug_agent.rb +64 -0
  143. data/lib/fluent/plugin/in_dummy.rb +139 -0
  144. data/lib/fluent/plugin/in_exec.rb +108 -0
  145. data/lib/fluent/plugin/in_forward.rb +455 -0
  146. data/lib/fluent/plugin/in_gc_stat.rb +56 -0
  147. data/lib/fluent/plugin/in_http.rb +433 -0
  148. data/lib/fluent/plugin/in_monitor_agent.rb +448 -0
  149. data/lib/fluent/plugin/in_object_space.rb +93 -0
  150. data/lib/fluent/plugin/in_syslog.rb +209 -0
  151. data/lib/fluent/plugin/in_tail.rb +905 -0
  152. data/lib/fluent/plugin/in_tcp.rb +85 -0
  153. data/lib/fluent/plugin/in_udp.rb +81 -0
  154. data/lib/fluent/plugin/in_unix.rb +201 -0
  155. data/lib/fluent/plugin/input.rb +37 -0
  156. data/lib/fluent/plugin/multi_output.rb +157 -0
  157. data/lib/fluent/plugin/out_copy.rb +46 -0
  158. data/lib/fluent/plugin/out_exec.rb +105 -0
  159. data/lib/fluent/plugin/out_exec_filter.rb +317 -0
  160. data/lib/fluent/plugin/out_file.rb +302 -0
  161. data/lib/fluent/plugin/out_forward.rb +912 -0
  162. data/lib/fluent/plugin/out_null.rb +74 -0
  163. data/lib/fluent/plugin/out_relabel.rb +32 -0
  164. data/lib/fluent/plugin/out_roundrobin.rb +84 -0
  165. data/lib/fluent/plugin/out_secondary_file.rb +133 -0
  166. data/lib/fluent/plugin/out_stdout.rb +75 -0
  167. data/lib/fluent/plugin/out_stream.rb +130 -0
  168. data/lib/fluent/plugin/output.rb +1291 -0
  169. data/lib/fluent/plugin/owned_by_mixin.rb +42 -0
  170. data/lib/fluent/plugin/parser.rb +191 -0
  171. data/lib/fluent/plugin/parser_apache.rb +28 -0
  172. data/lib/fluent/plugin/parser_apache2.rb +84 -0
  173. data/lib/fluent/plugin/parser_apache_error.rb +26 -0
  174. data/lib/fluent/plugin/parser_csv.rb +39 -0
  175. data/lib/fluent/plugin/parser_json.rb +81 -0
  176. data/lib/fluent/plugin/parser_ltsv.rb +42 -0
  177. data/lib/fluent/plugin/parser_msgpack.rb +50 -0
  178. data/lib/fluent/plugin/parser_multiline.rb +105 -0
  179. data/lib/fluent/plugin/parser_nginx.rb +28 -0
  180. data/lib/fluent/plugin/parser_none.rb +36 -0
  181. data/lib/fluent/plugin/parser_regexp.rb +63 -0
  182. data/lib/fluent/plugin/parser_syslog.rb +121 -0
  183. data/lib/fluent/plugin/parser_tsv.rb +42 -0
  184. data/lib/fluent/plugin/socket_util.rb +22 -0
  185. data/lib/fluent/plugin/storage.rb +84 -0
  186. data/lib/fluent/plugin/storage_local.rb +159 -0
  187. data/lib/fluent/plugin/string_util.rb +22 -0
  188. data/lib/fluent/plugin_helper.rb +70 -0
  189. data/lib/fluent/plugin_helper/cert_option.rb +159 -0
  190. data/lib/fluent/plugin_helper/child_process.rb +364 -0
  191. data/lib/fluent/plugin_helper/compat_parameters.rb +331 -0
  192. data/lib/fluent/plugin_helper/event_emitter.rb +93 -0
  193. data/lib/fluent/plugin_helper/event_loop.rb +161 -0
  194. data/lib/fluent/plugin_helper/extract.rb +104 -0
  195. data/lib/fluent/plugin_helper/formatter.rb +147 -0
  196. data/lib/fluent/plugin_helper/inject.rb +151 -0
  197. data/lib/fluent/plugin_helper/parser.rb +147 -0
  198. data/lib/fluent/plugin_helper/retry_state.rb +201 -0
  199. data/lib/fluent/plugin_helper/server.rb +738 -0
  200. data/lib/fluent/plugin_helper/socket.rb +241 -0
  201. data/lib/fluent/plugin_helper/socket_option.rb +69 -0
  202. data/lib/fluent/plugin_helper/storage.rb +349 -0
  203. data/lib/fluent/plugin_helper/thread.rb +179 -0
  204. data/lib/fluent/plugin_helper/timer.rb +91 -0
  205. data/lib/fluent/plugin_id.rb +80 -0
  206. data/lib/fluent/process.rb +22 -0
  207. data/lib/fluent/registry.rb +116 -0
  208. data/lib/fluent/root_agent.rb +323 -0
  209. data/lib/fluent/rpc.rb +94 -0
  210. data/lib/fluent/supervisor.rb +741 -0
  211. data/lib/fluent/system_config.rb +159 -0
  212. data/lib/fluent/test.rb +58 -0
  213. data/lib/fluent/test/base.rb +78 -0
  214. data/lib/fluent/test/driver/base.rb +224 -0
  215. data/lib/fluent/test/driver/base_owned.rb +70 -0
  216. data/lib/fluent/test/driver/base_owner.rb +135 -0
  217. data/lib/fluent/test/driver/event_feeder.rb +98 -0
  218. data/lib/fluent/test/driver/filter.rb +57 -0
  219. data/lib/fluent/test/driver/formatter.rb +30 -0
  220. data/lib/fluent/test/driver/input.rb +31 -0
  221. data/lib/fluent/test/driver/multi_output.rb +53 -0
  222. data/lib/fluent/test/driver/output.rb +102 -0
  223. data/lib/fluent/test/driver/parser.rb +30 -0
  224. data/lib/fluent/test/driver/test_event_router.rb +45 -0
  225. data/lib/fluent/test/filter_test.rb +77 -0
  226. data/lib/fluent/test/formatter_test.rb +65 -0
  227. data/lib/fluent/test/helpers.rb +134 -0
  228. data/lib/fluent/test/input_test.rb +174 -0
  229. data/lib/fluent/test/log.rb +79 -0
  230. data/lib/fluent/test/output_test.rb +156 -0
  231. data/lib/fluent/test/parser_test.rb +70 -0
  232. data/lib/fluent/test/startup_shutdown.rb +46 -0
  233. data/lib/fluent/time.rb +412 -0
  234. data/lib/fluent/timezone.rb +133 -0
  235. data/lib/fluent/unique_id.rb +39 -0
  236. data/lib/fluent/version.rb +21 -0
  237. data/lib/fluent/winsvc.rb +71 -0
  238. data/templates/new_gem/Gemfile +3 -0
  239. data/templates/new_gem/README.md.erb +43 -0
  240. data/templates/new_gem/Rakefile +13 -0
  241. data/templates/new_gem/fluent-plugin.gemspec.erb +27 -0
  242. data/templates/new_gem/lib/fluent/plugin/filter.rb.erb +14 -0
  243. data/templates/new_gem/lib/fluent/plugin/formatter.rb.erb +14 -0
  244. data/templates/new_gem/lib/fluent/plugin/input.rb.erb +11 -0
  245. data/templates/new_gem/lib/fluent/plugin/output.rb.erb +11 -0
  246. data/templates/new_gem/lib/fluent/plugin/parser.rb.erb +15 -0
  247. data/templates/new_gem/test/helper.rb.erb +8 -0
  248. data/templates/new_gem/test/plugin/test_filter.rb.erb +18 -0
  249. data/templates/new_gem/test/plugin/test_formatter.rb.erb +18 -0
  250. data/templates/new_gem/test/plugin/test_input.rb.erb +18 -0
  251. data/templates/new_gem/test/plugin/test_output.rb.erb +18 -0
  252. data/templates/new_gem/test/plugin/test_parser.rb.erb +18 -0
  253. data/templates/plugin_config_formatter/param.md-compact.erb +25 -0
  254. data/templates/plugin_config_formatter/param.md.erb +34 -0
  255. data/templates/plugin_config_formatter/section.md.erb +12 -0
  256. data/test/command/test_binlog_reader.rb +346 -0
  257. data/test/command/test_fluentd.rb +618 -0
  258. data/test/command/test_plugin_config_formatter.rb +275 -0
  259. data/test/command/test_plugin_generator.rb +66 -0
  260. data/test/compat/test_calls_super.rb +166 -0
  261. data/test/compat/test_parser.rb +92 -0
  262. data/test/config/assertions.rb +42 -0
  263. data/test/config/test_config_parser.rb +513 -0
  264. data/test/config/test_configurable.rb +1587 -0
  265. data/test/config/test_configure_proxy.rb +566 -0
  266. data/test/config/test_dsl.rb +415 -0
  267. data/test/config/test_element.rb +403 -0
  268. data/test/config/test_literal_parser.rb +297 -0
  269. data/test/config/test_section.rb +184 -0
  270. data/test/config/test_system_config.rb +168 -0
  271. data/test/config/test_types.rb +191 -0
  272. data/test/helper.rb +153 -0
  273. data/test/plugin/data/2010/01/20100102-030405.log +0 -0
  274. data/test/plugin/data/2010/01/20100102-030406.log +0 -0
  275. data/test/plugin/data/2010/01/20100102.log +0 -0
  276. data/test/plugin/data/log/bar +0 -0
  277. data/test/plugin/data/log/foo/bar.log +0 -0
  278. data/test/plugin/data/log/foo/bar2 +0 -0
  279. data/test/plugin/data/log/test.log +0 -0
  280. data/test/plugin/test_bare_output.rb +118 -0
  281. data/test/plugin/test_base.rb +115 -0
  282. data/test/plugin/test_buf_file.rb +843 -0
  283. data/test/plugin/test_buf_memory.rb +42 -0
  284. data/test/plugin/test_buffer.rb +1220 -0
  285. data/test/plugin/test_buffer_chunk.rb +198 -0
  286. data/test/plugin/test_buffer_file_chunk.rb +844 -0
  287. data/test/plugin/test_buffer_memory_chunk.rb +338 -0
  288. data/test/plugin/test_compressable.rb +84 -0
  289. data/test/plugin/test_file_util.rb +96 -0
  290. data/test/plugin/test_filter.rb +357 -0
  291. data/test/plugin/test_filter_grep.rb +119 -0
  292. data/test/plugin/test_filter_parser.rb +700 -0
  293. data/test/plugin/test_filter_record_transformer.rb +556 -0
  294. data/test/plugin/test_filter_stdout.rb +202 -0
  295. data/test/plugin/test_formatter_csv.rb +111 -0
  296. data/test/plugin/test_formatter_hash.rb +35 -0
  297. data/test/plugin/test_formatter_json.rb +51 -0
  298. data/test/plugin/test_formatter_ltsv.rb +59 -0
  299. data/test/plugin/test_formatter_msgpack.rb +28 -0
  300. data/test/plugin/test_formatter_out_file.rb +95 -0
  301. data/test/plugin/test_formatter_single_value.rb +38 -0
  302. data/test/plugin/test_in_debug_agent.rb +28 -0
  303. data/test/plugin/test_in_dummy.rb +192 -0
  304. data/test/plugin/test_in_exec.rb +245 -0
  305. data/test/plugin/test_in_forward.rb +1120 -0
  306. data/test/plugin/test_in_gc_stat.rb +39 -0
  307. data/test/plugin/test_in_http.rb +588 -0
  308. data/test/plugin/test_in_monitor_agent.rb +516 -0
  309. data/test/plugin/test_in_object_space.rb +64 -0
  310. data/test/plugin/test_in_syslog.rb +271 -0
  311. data/test/plugin/test_in_tail.rb +1216 -0
  312. data/test/plugin/test_in_tcp.rb +118 -0
  313. data/test/plugin/test_in_udp.rb +152 -0
  314. data/test/plugin/test_in_unix.rb +126 -0
  315. data/test/plugin/test_input.rb +126 -0
  316. data/test/plugin/test_multi_output.rb +180 -0
  317. data/test/plugin/test_out_copy.rb +160 -0
  318. data/test/plugin/test_out_exec.rb +310 -0
  319. data/test/plugin/test_out_exec_filter.rb +613 -0
  320. data/test/plugin/test_out_file.rb +873 -0
  321. data/test/plugin/test_out_forward.rb +685 -0
  322. data/test/plugin/test_out_null.rb +105 -0
  323. data/test/plugin/test_out_relabel.rb +28 -0
  324. data/test/plugin/test_out_roundrobin.rb +146 -0
  325. data/test/plugin/test_out_secondary_file.rb +442 -0
  326. data/test/plugin/test_out_stdout.rb +170 -0
  327. data/test/plugin/test_out_stream.rb +93 -0
  328. data/test/plugin/test_output.rb +870 -0
  329. data/test/plugin/test_output_as_buffered.rb +1932 -0
  330. data/test/plugin/test_output_as_buffered_compress.rb +165 -0
  331. data/test/plugin/test_output_as_buffered_overflow.rb +250 -0
  332. data/test/plugin/test_output_as_buffered_retries.rb +839 -0
  333. data/test/plugin/test_output_as_buffered_secondary.rb +877 -0
  334. data/test/plugin/test_output_as_standard.rb +374 -0
  335. data/test/plugin/test_owned_by.rb +35 -0
  336. data/test/plugin/test_parser.rb +359 -0
  337. data/test/plugin/test_parser_apache.rb +42 -0
  338. data/test/plugin/test_parser_apache2.rb +46 -0
  339. data/test/plugin/test_parser_apache_error.rb +45 -0
  340. data/test/plugin/test_parser_csv.rb +103 -0
  341. data/test/plugin/test_parser_json.rb +114 -0
  342. data/test/plugin/test_parser_labeled_tsv.rb +128 -0
  343. data/test/plugin/test_parser_multiline.rb +100 -0
  344. data/test/plugin/test_parser_nginx.rb +48 -0
  345. data/test/plugin/test_parser_none.rb +52 -0
  346. data/test/plugin/test_parser_regexp.rb +281 -0
  347. data/test/plugin/test_parser_syslog.rb +242 -0
  348. data/test/plugin/test_parser_tsv.rb +122 -0
  349. data/test/plugin/test_storage.rb +167 -0
  350. data/test/plugin/test_storage_local.rb +335 -0
  351. data/test/plugin/test_string_util.rb +26 -0
  352. data/test/plugin_helper/test_child_process.rb +794 -0
  353. data/test/plugin_helper/test_compat_parameters.rb +331 -0
  354. data/test/plugin_helper/test_event_emitter.rb +51 -0
  355. data/test/plugin_helper/test_event_loop.rb +52 -0
  356. data/test/plugin_helper/test_extract.rb +194 -0
  357. data/test/plugin_helper/test_formatter.rb +255 -0
  358. data/test/plugin_helper/test_inject.rb +519 -0
  359. data/test/plugin_helper/test_parser.rb +264 -0
  360. data/test/plugin_helper/test_retry_state.rb +422 -0
  361. data/test/plugin_helper/test_server.rb +1677 -0
  362. data/test/plugin_helper/test_storage.rb +542 -0
  363. data/test/plugin_helper/test_thread.rb +164 -0
  364. data/test/plugin_helper/test_timer.rb +132 -0
  365. data/test/scripts/exec_script.rb +32 -0
  366. data/test/scripts/fluent/plugin/formatter1/formatter_test1.rb +7 -0
  367. data/test/scripts/fluent/plugin/formatter2/formatter_test2.rb +7 -0
  368. data/test/scripts/fluent/plugin/formatter_known.rb +8 -0
  369. data/test/scripts/fluent/plugin/out_test.rb +81 -0
  370. data/test/scripts/fluent/plugin/out_test2.rb +80 -0
  371. data/test/scripts/fluent/plugin/parser_known.rb +4 -0
  372. data/test/test_clock.rb +164 -0
  373. data/test/test_config.rb +179 -0
  374. data/test/test_configdsl.rb +148 -0
  375. data/test/test_event.rb +515 -0
  376. data/test/test_event_router.rb +331 -0
  377. data/test/test_event_time.rb +186 -0
  378. data/test/test_filter.rb +121 -0
  379. data/test/test_formatter.rb +312 -0
  380. data/test/test_input.rb +31 -0
  381. data/test/test_log.rb +828 -0
  382. data/test/test_match.rb +137 -0
  383. data/test/test_mixin.rb +351 -0
  384. data/test/test_output.rb +273 -0
  385. data/test/test_plugin.rb +251 -0
  386. data/test/test_plugin_classes.rb +253 -0
  387. data/test/test_plugin_helper.rb +81 -0
  388. data/test/test_plugin_id.rb +101 -0
  389. data/test/test_process.rb +14 -0
  390. data/test/test_root_agent.rb +611 -0
  391. data/test/test_supervisor.rb +373 -0
  392. data/test/test_test_drivers.rb +135 -0
  393. data/test/test_time_formatter.rb +282 -0
  394. data/test/test_time_parser.rb +211 -0
  395. data/test/test_unique_id.rb +47 -0
  396. metadata +898 -0
@@ -0,0 +1,21 @@
1
+ #
2
+ # Fluentd
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'fluent/compat/filter'
18
+
19
+ module Fluent
20
+ Filter = Fluent::Compat::Filter
21
+ end
@@ -0,0 +1,23 @@
1
+ #
2
+ # Fluentd
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'fluent/compat/formatter'
18
+
19
+ module Fluent
20
+ Formatter = Fluent::Compat::Formatter
21
+ TextFormatter = Fluent::Compat::TextFormatter
22
+ # deprecate_constant is ruby 2.3 feature
23
+ end
@@ -0,0 +1,21 @@
1
+ #
2
+ # Fluentd
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'fluent/compat/input'
18
+
19
+ module Fluent
20
+ Input = Fluent::Compat::Input
21
+ end
@@ -0,0 +1,46 @@
1
+ #
2
+ # Fluentd
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'fluent/agent'
18
+
19
+ module Fluent
20
+ class Label < Agent
21
+ def initialize(name, log:)
22
+ super(log: log)
23
+
24
+ @context = name
25
+ @root_agent = nil
26
+ end
27
+
28
+ attr_accessor :root_agent
29
+
30
+ def configure(conf)
31
+ super
32
+
33
+ if conf.elements('match').size == 0
34
+ raise ConfigError, "Missing <match> sections in <label #{@context}> section"
35
+ end
36
+ end
37
+
38
+ def emit_error_event(tag, time, record, e)
39
+ @root_agent.emit_error_event(tag, time, record, e)
40
+ end
41
+
42
+ def handle_emits_error(tag, es, e)
43
+ @root_agent.handle_emits_error(tag, es, e)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,35 @@
1
+ require 'thread'
2
+ require 'socket'
3
+ require 'fcntl'
4
+ require 'time'
5
+ require 'monitor'
6
+ require 'stringio'
7
+ require 'fileutils'
8
+ require 'json'
9
+ require 'yajl'
10
+ require 'uri'
11
+ require 'msgpack'
12
+ require 'strptime'
13
+ begin
14
+ require 'sigdump/setup'
15
+ rescue
16
+ # ignore setup error on Win or similar platform which doesn't support signal
17
+ end
18
+ require 'cool.io'
19
+
20
+ require 'fluent/time'
21
+ require 'fluent/env'
22
+ require 'fluent/version'
23
+ require 'fluent/log'
24
+ require 'fluent/config'
25
+ require 'fluent/engine'
26
+ require 'fluent/rpc'
27
+ require 'fluent/mixin'
28
+ require 'fluent/plugin'
29
+ require 'fluent/parser'
30
+ require 'fluent/formatter'
31
+ require 'fluent/event'
32
+ require 'fluent/input'
33
+ require 'fluent/output'
34
+ require 'fluent/filter'
35
+ require 'fluent/match'
data/lib/fluent/log.rb ADDED
@@ -0,0 +1,546 @@
1
+ #
2
+ # Fluentd
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'forwardable'
18
+ require 'logger'
19
+
20
+ module Fluent
21
+ class Log
22
+ module TTYColor
23
+ RESET = "\033]R"
24
+ CRE = "\033[K"
25
+ CLEAR = "\033c"
26
+ NORMAL = "\033[0;39m"
27
+ RED = "\033[1;31m"
28
+ GREEN = "\033[1;32m"
29
+ YELLOW = "\033[1;33m"
30
+ BLUE = "\033[1;34m"
31
+ MAGENTA = "\033[1;35m"
32
+ CYAN = "\033[1;36m"
33
+ WHITE = "\033[1;37m"
34
+ end
35
+
36
+ LEVEL_TRACE = 0
37
+ LEVEL_DEBUG = 1
38
+ LEVEL_INFO = 2
39
+ LEVEL_WARN = 3
40
+ LEVEL_ERROR = 4
41
+ LEVEL_FATAL = 5
42
+
43
+ LEVEL_TEXT = %w(trace debug info warn error fatal)
44
+
45
+ LOG_EVENT_TAG_PREFIX = 'fluent'
46
+ LOG_EVENT_LABEL = '@FLUENT_LOG'
47
+ LOG_TYPE_SUPERVISOR = :supervisor # only in supervisor, or a worker with --no-supervisor
48
+ LOG_TYPE_WORKER0 = :worker0 # only in a worker with worker_id=0 (without showing worker id)
49
+ LOG_TYPE_DEFAULT = :default # show logs in all supervisor/workers, with worker id in workers (default)
50
+
51
+ LOG_TYPES = [LOG_TYPE_SUPERVISOR, LOG_TYPE_WORKER0, LOG_TYPE_DEFAULT].freeze
52
+
53
+ def self.str_to_level(log_level_str)
54
+ case log_level_str.downcase
55
+ when "trace" then LEVEL_TRACE
56
+ when "debug" then LEVEL_DEBUG
57
+ when "info" then LEVEL_INFO
58
+ when "warn" then LEVEL_WARN
59
+ when "error" then LEVEL_ERROR
60
+ when "fatal" then LEVEL_FATAL
61
+ else raise "Unknown log level: level = #{log_level_str}"
62
+ end
63
+ end
64
+
65
+ def self.event_tags
66
+ LEVEL_TEXT.map{|t| "#{LOG_EVENT_TAG_PREFIX}.#{t}" }
67
+ end
68
+
69
+ def initialize(logger, opts={})
70
+ # overwrites logger.level= so that config reloading resets level of Fluentd::Log
71
+ orig_logger_level_setter = logger.class.public_instance_method(:level=).bind(logger)
72
+ me = self
73
+ # The original ruby logger sets the number as each log level like below.
74
+ # DEBUG = 0
75
+ # INFO = 1
76
+ # WARN = 2
77
+ # ERROR = 3
78
+ # FATAL = 4
79
+ # Serverengine use this original log number. In addition to this, serverengine sets -1 as TRACE level.
80
+ # TRACE = -1
81
+ #
82
+ # On the other hand, in fluentd side, it sets the number like below.
83
+ # TRACE = 0
84
+ # DEBUG = 1
85
+ # INFO = 2
86
+ # WARN = 3
87
+ # ERROR = 4
88
+ # FATAL = 5
89
+ #
90
+ # Then fluentd's level is set as serverengine's level + 1.
91
+ # So if serverengine's logger level is changed, fluentd's log level will be changed to that + 1.
92
+ logger.define_singleton_method(:level=) {|level| orig_logger_level_setter.call(level); me.level = self.level + 1 }
93
+
94
+ @logger = logger
95
+ @out = logger.instance_variable_get(:@logdev)
96
+ @level = logger.level + 1
97
+ @debug_mode = false
98
+ @log_event_enabled = false
99
+ @time_format = '%Y-%m-%d %H:%M:%S %z '
100
+ @depth_offset = 1
101
+ enable_color out.tty?
102
+ # TODO: This variable name is unclear so we should change to better name.
103
+ @threads_exclude_events = []
104
+
105
+ # Fluent::Engine requires Fluent::Log, so we must take that object lazily
106
+ @engine = Fluent.const_get('Engine')
107
+ @optional_header = nil
108
+ @optional_attrs = nil
109
+
110
+ @suppress_repeated_stacktrace = opts[:suppress_repeated_stacktrace]
111
+
112
+ @process_type = opts[:process_type] # :supervisor, :worker0, :workers Or :standalone
113
+ @process_type ||= :standalone # to keep behavior of existing code
114
+ case @process_type
115
+ when :supervisor
116
+ @show_supervisor_log = true
117
+ @show_worker0_log = false
118
+ when :worker0
119
+ @show_supervisor_log = false
120
+ @show_worker0_log = true
121
+ when :workers
122
+ @show_supervisor_log = false
123
+ @show_worker0_log = false
124
+ when :standalone
125
+ @show_supervisor_log = true
126
+ @show_worker0_log = true
127
+ else
128
+ raise "BUG: unknown process type for logger:#{@process_type}"
129
+ end
130
+ @worker_id = opts[:worker_id]
131
+ @worker_id_part = "##{@worker_id} " # used only for :default log type in workers
132
+ end
133
+
134
+ def dup
135
+ dl_opts = {}
136
+ dl_opts[:log_level] = @level - 1
137
+ logger = ServerEngine::DaemonLogger.new(@out, dl_opts)
138
+ clone = self.class.new(logger, suppress_repeated_stacktrace: @suppress_repeated_stacktrace, process_type: @process_type, worker_id: @worker_id)
139
+ clone.time_format = @time_format
140
+ clone.log_event_enabled = @log_event_enabled
141
+ # optional headers/attrs are not copied, because new PluginLogger should have another one of it
142
+ clone
143
+ end
144
+
145
+ attr_accessor :log_event_enabled
146
+ attr_accessor :out
147
+ attr_accessor :level
148
+ attr_accessor :time_format
149
+ attr_accessor :optional_header, :optional_attrs
150
+
151
+ def logdev=(logdev)
152
+ @out = logdev
153
+ @logger.instance_variable_set(:@logdev, logdev)
154
+ nil
155
+ end
156
+
157
+ def reopen!
158
+ # do nothing in @logger.reopen! because it's already reopened in Supervisor.load_config
159
+ @logger.reopen! if @logger
160
+ nil
161
+ end
162
+
163
+ def enable_debug(b=true)
164
+ @debug_mode = b
165
+ self
166
+ end
167
+
168
+ def enable_event(b=true)
169
+ @log_event_enabled = b
170
+ self
171
+ end
172
+
173
+ # If you want to suppress event emitting in specific thread, please use this method.
174
+ # Events in passed thread are never emitted.
175
+ def disable_events(thread)
176
+ # this method is not symmetric with #enable_event.
177
+ @threads_exclude_events.push(thread) unless @threads_exclude_events.include?(thread)
178
+ end
179
+
180
+ def enable_color?
181
+ !@color_reset.empty?
182
+ end
183
+
184
+ def enable_color(b=true)
185
+ if b
186
+ @color_trace = TTYColor::BLUE
187
+ @color_debug = TTYColor::WHITE
188
+ @color_info = TTYColor::GREEN
189
+ @color_warn = TTYColor::YELLOW
190
+ @color_error = TTYColor::MAGENTA
191
+ @color_fatal = TTYColor::RED
192
+ @color_reset = TTYColor::NORMAL
193
+ else
194
+ @color_trace = ''
195
+ @color_debug = ''
196
+ @color_info = ''
197
+ @color_warn = ''
198
+ @color_error = ''
199
+ @color_fatal = ''
200
+ @color_reset = ''
201
+ end
202
+ self
203
+ end
204
+
205
+ def log_type(args)
206
+ if LOG_TYPES.include?(args.first)
207
+ args.shift
208
+ else
209
+ LOG_TYPE_DEFAULT
210
+ end
211
+ end
212
+
213
+ # TODO: skip :worker0 logs when Fluentd gracefully restarted
214
+ def skipped_type?(type)
215
+ case type
216
+ when LOG_TYPE_DEFAULT
217
+ false
218
+ when LOG_TYPE_WORKER0
219
+ !@show_worker0_log
220
+ when LOG_TYPE_SUPERVISOR
221
+ !@show_supervisor_log
222
+ else
223
+ raise "BUG: unknown log type:#{type}"
224
+ end
225
+ end
226
+
227
+ def on_trace(&block)
228
+ return if @level > LEVEL_TRACE
229
+ block.call if block
230
+ end
231
+
232
+ def trace(*args, &block)
233
+ return if @level > LEVEL_TRACE
234
+ type = log_type(args)
235
+ return if skipped_type?(type)
236
+ args << block.call if block
237
+ time, msg = event(:trace, args)
238
+ puts [@color_trace, caller_line(type, time, @depth_offset, LEVEL_TRACE), msg, @color_reset].join
239
+ rescue
240
+ # logger should not raise an exception. This rescue prevents unexpected behaviour.
241
+ end
242
+ alias TRACE trace
243
+
244
+ def trace_backtrace(backtrace=$!.backtrace, type: :default)
245
+ dump_stacktrace(type, backtrace, LEVEL_TRACE)
246
+ end
247
+
248
+ def on_debug(&block)
249
+ return if @level > LEVEL_DEBUG
250
+ block.call if block
251
+ end
252
+
253
+ def debug(*args, &block)
254
+ return if @level > LEVEL_DEBUG
255
+ type = log_type(args)
256
+ return if skipped_type?(type)
257
+ args << block.call if block
258
+ time, msg = event(:debug, args)
259
+ puts [@color_debug, caller_line(type, time, @depth_offset, LEVEL_DEBUG), msg, @color_reset].join
260
+ rescue
261
+ end
262
+ alias DEBUG debug
263
+
264
+ def debug_backtrace(backtrace=$!.backtrace, type: :default)
265
+ dump_stacktrace(type, backtrace, LEVEL_DEBUG)
266
+ end
267
+
268
+ def on_info(&block)
269
+ return if @level > LEVEL_INFO
270
+ block.call if block
271
+ end
272
+
273
+ def info(*args, &block)
274
+ return if @level > LEVEL_INFO
275
+ type = log_type(args)
276
+ return if skipped_type?(type)
277
+ args << block.call if block
278
+ time, msg = event(:info, args)
279
+ puts [@color_info, caller_line(type, time, @depth_offset, LEVEL_INFO), msg, @color_reset].join
280
+ rescue
281
+ end
282
+ alias INFO info
283
+
284
+ def info_backtrace(backtrace=$!.backtrace, type: :default)
285
+ dump_stacktrace(type, backtrace, LEVEL_INFO)
286
+ end
287
+
288
+ def on_warn(&block)
289
+ return if @level > LEVEL_WARN
290
+ block.call if block
291
+ end
292
+
293
+ def warn(*args, &block)
294
+ return if @level > LEVEL_WARN
295
+ type = log_type(args)
296
+ return if skipped_type?(type)
297
+ args << block.call if block
298
+ time, msg = event(:warn, args)
299
+ puts [@color_warn, caller_line(type, time, @depth_offset, LEVEL_WARN), msg, @color_reset].join
300
+ rescue
301
+ end
302
+ alias WARN warn
303
+
304
+ def warn_backtrace(backtrace=$!.backtrace, type: :default)
305
+ dump_stacktrace(type, backtrace, LEVEL_WARN)
306
+ end
307
+
308
+ def on_error(&block)
309
+ return if @level > LEVEL_ERROR
310
+ block.call if block
311
+ end
312
+
313
+ def error(*args, &block)
314
+ return if @level > LEVEL_ERROR
315
+ type = log_type(args)
316
+ return if skipped_type?(type)
317
+ args << block.call if block
318
+ time, msg = event(:error, args)
319
+ puts [@color_error, caller_line(type, time, @depth_offset, LEVEL_ERROR), msg, @color_reset].join
320
+ rescue
321
+ end
322
+ alias ERROR error
323
+
324
+ def error_backtrace(backtrace=$!.backtrace, type: :default)
325
+ dump_stacktrace(type, backtrace, LEVEL_ERROR)
326
+ end
327
+
328
+ def on_fatal(&block)
329
+ return if @level > LEVEL_FATAL
330
+ block.call if block
331
+ end
332
+
333
+ def fatal(*args, &block)
334
+ return if @level > LEVEL_FATAL
335
+ type = log_type(args)
336
+ return if skipped_type?(type)
337
+ args << block.call if block
338
+ time, msg = event(:fatal, args)
339
+ puts [@color_fatal, caller_line(type, time, @depth_offset, LEVEL_FATAL), msg, @color_reset].join
340
+ rescue
341
+ end
342
+ alias FATAL fatal
343
+
344
+ def fatal_backtrace(backtrace=$!.backtrace, type: :default)
345
+ dump_stacktrace(type, backtrace, LEVEL_FATAL)
346
+ end
347
+
348
+ def puts(msg)
349
+ @logger << msg + "\n"
350
+ @out.flush
351
+ msg
352
+ rescue
353
+ # FIXME
354
+ nil
355
+ end
356
+
357
+ def write(data)
358
+ @out.write(data)
359
+ end
360
+ # We need `#<<` method to use this logger class with other
361
+ # libraries such as aws-sdk
362
+ alias << write
363
+
364
+ def flush
365
+ @out.flush
366
+ end
367
+
368
+ def reset
369
+ @out.reset if @out.respond_to?(:reset)
370
+ end
371
+
372
+ def dump_stacktrace(type, backtrace, level)
373
+ return if @level > level
374
+
375
+ time = Time.now
376
+ line = caller_line(type, time, 5, level)
377
+ if @suppress_repeated_stacktrace && (Thread.current[:last_repeated_stacktrace] == backtrace)
378
+ puts [" ", line, 'suppressed same stacktrace'].join
379
+ else
380
+ backtrace.each { |msg|
381
+ puts [" ", line, msg].join
382
+ }
383
+ Thread.current[:last_repeated_stacktrace] = backtrace if @suppress_repeated_stacktrace
384
+ end
385
+
386
+ nil
387
+ end
388
+
389
+ def event(level, args)
390
+ time = Time.now
391
+ message = @optional_header ? @optional_header.dup : ''
392
+ map = @optional_attrs ? @optional_attrs.dup : {}
393
+ args.each {|a|
394
+ if a.is_a?(Hash)
395
+ a.each_pair {|k,v|
396
+ map[k.to_s] = v
397
+ }
398
+ else
399
+ message << a.to_s
400
+ end
401
+ }
402
+
403
+ map.each_pair {|k,v|
404
+ if k == "error".freeze && v.is_a?(Exception) && !map.has_key?("error_class")
405
+ message << " error_class=#{v.class.to_s} error=#{v.to_s.inspect}"
406
+ else
407
+ message << " #{k}=#{v.inspect}"
408
+ end
409
+ }
410
+
411
+ if @log_event_enabled && !@threads_exclude_events.include?(Thread.current)
412
+ record = map.dup
413
+ record.keys.each {|key|
414
+ record[key] = record[key].inspect unless record[key].respond_to?(:to_msgpack)
415
+ }
416
+ record['message'] = message.dup
417
+ @engine.push_log_event("#{LOG_EVENT_TAG_PREFIX}.#{level}", Fluent::EventTime.from_time(time), record)
418
+ end
419
+
420
+ return time, message
421
+ end
422
+
423
+ def caller_line(type, time, depth, level)
424
+ worker_id_part = if type == :default && (@process_type == :worker0 || @process_type == :workers)
425
+ @worker_id_part
426
+ else
427
+ "".freeze
428
+ end
429
+ log_msg = "#{time.strftime(@time_format)}[#{LEVEL_TEXT[level]}]: #{worker_id_part}"
430
+ if @debug_mode
431
+ line = caller(depth+1)[0]
432
+ if match = /^(.+?):(\d+)(?::in `(.*)')?/.match(line)
433
+ file = match[1].split('/')[-2,2].join('/')
434
+ line = match[2]
435
+ method = match[3]
436
+ return "#{log_msg}#{file}:#{line}:#{method}: "
437
+ end
438
+ end
439
+ return log_msg
440
+ end
441
+ end
442
+
443
+
444
+ # PluginLogger has own log level separated from global $log object.
445
+ # This class enables log_level option in each plugin.
446
+ #
447
+ # PluginLogger has same functionality as Log but some methods are forwarded to internal logger
448
+ # for keeping logging action consistency in the process, e.g. color, event, etc.
449
+ class PluginLogger < Log
450
+ def initialize(logger)
451
+ @logger = logger
452
+ @level = @logger.level
453
+ @depth_offset = 2
454
+ if logger.instance_variable_defined?(:@suppress_repeated_stacktrace)
455
+ @suppress_repeated_stacktrace = logger.instance_variable_get(:@suppress_repeated_stacktrace)
456
+ end
457
+
458
+ enable_color @logger.enable_color?
459
+ end
460
+
461
+ def level=(log_level_str)
462
+ @level = Log.str_to_level(log_level_str)
463
+ end
464
+
465
+ alias orig_enable_color enable_color
466
+
467
+ def enable_color(b = true)
468
+ orig_enable_color b
469
+ @logger.enable_color b
470
+ end
471
+
472
+ extend Forwardable
473
+ def_delegators '@logger', :enable_color?, :enable_debug, :enable_event,
474
+ :disable_events, :log_event_enabled, :log_event_enamed=, :time_format, :time_format=,
475
+ :event, :caller_line, :puts, :write, :flush, :reset, :out, :out=,
476
+ :optional_header, :optional_header=, :optional_attrs, :optional_attrs=
477
+ end
478
+
479
+
480
+ module PluginLoggerMixin
481
+ def self.included(klass)
482
+ klass.instance_eval {
483
+ desc 'Allows the user to set different levels of logging for each plugin.'
484
+ config_param :@log_level, :string, default: nil, alias: :log_level # 'log_level' will be warned as deprecated
485
+ }
486
+ end
487
+
488
+ def initialize
489
+ super
490
+
491
+ @log = $log # Use $log object directly by default
492
+ end
493
+
494
+ attr_accessor :log
495
+
496
+ def configure(conf)
497
+ super
498
+
499
+ if plugin_id_configured? || conf['@log_level']
500
+ @log = PluginLogger.new($log.dup) unless @log.is_a?(PluginLogger)
501
+ @log.optional_attrs = {}
502
+
503
+ if level = conf['@log_level']
504
+ @log.level = level
505
+ end
506
+
507
+ if plugin_id_configured?
508
+ @log.optional_header = "[#{@id}] "
509
+ end
510
+ end
511
+ end
512
+
513
+ def terminate
514
+ super
515
+ @log.reset
516
+ end
517
+ end
518
+
519
+ # This class delegetes some methods which are used in `Fluent::Logger` to a instance variable(`dev`) in `Logger::LogDevice` class
520
+ # https://github.com/ruby/ruby/blob/7b2d47132ff8ee950b0f978ab772dee868d9f1b0/lib/logger.rb#L661
521
+ class LogDeviceIO < ::Logger::LogDevice
522
+ def flush
523
+ if @dev.respond_to?(:flush)
524
+ @dev.flush
525
+ else
526
+ super
527
+ end
528
+ end
529
+
530
+ def tty?
531
+ if @dev.respond_to?(:tty?)
532
+ @dev.tty?
533
+ else
534
+ super
535
+ end
536
+ end
537
+
538
+ def sync=(v)
539
+ if @dev.respond_to?(:sync=)
540
+ @dev.sync = v
541
+ else
542
+ super
543
+ end
544
+ end
545
+ end
546
+ end