diff --git a/lib/fluent/agent.rb b/lib/fluent/agent.rb index 4767533339..815a542c79 100644 --- a/lib/fluent/agent.rb +++ b/lib/fluent/agent.rb @@ -84,7 +84,7 @@ def shutdown log.info "shutting down filter#{@context.nil? ? '' : " in #{@context}"}", type: Plugin.lookup_type_from_class(f.class), plugin_id: f.plugin_id f.shutdown rescue => e - log.warn "unexpected error while shutting down filter plugins", plugin: f.class, plugin_id: f.plugin_id, error_class: e.class, error: e + log.warn "unexpected error while shutting down filter plugins", plugin: f.class, plugin_id: f.plugin_id, error: e log.warn_backtrace end end @@ -98,7 +98,7 @@ def shutdown log.info "shutting down output#{@context.nil? ? '' : " in #{@context}"}", type: Plugin.lookup_type_from_class(o.class), plugin_id: o.plugin_id o.shutdown rescue => e - log.warn "unexpected error while shutting down output plugins", plugin: o.class, plugin_id: o.plugin_id, error_class: e.class, error: e + log.warn "unexpected error while shutting down output plugins", plugin: o.class, plugin_id: o.plugin_id, error: e log.warn_backtrace end end @@ -118,7 +118,7 @@ def flush_recursive(array) flush_recursive(o.outputs) end rescue => e - log.debug "error while force flushing", error_class: e.class, error: e + log.debug "error while force flushing", error: e log.debug_backtrace end } diff --git a/lib/fluent/engine.rb b/lib/fluent/engine.rb index a832b2eecc..435f844b1d 100644 --- a/lib/fluent/engine.rb +++ b/lib/fluent/engine.rb @@ -166,7 +166,7 @@ def log_event_loop begin @event_router.emit(tag, time, record) rescue => e - $log.error "failed to emit fluentd's log event", tag: tag, event: record, error_class: e.class, error: e + $log.error "failed to emit fluentd's log event", tag: tag, event: record, error: e end } end @@ -195,7 +195,7 @@ def run end rescue => e - $log.error "unexpected error", error_class: e.class, error: e + $log.error "unexpected error", error: e $log.error_backtrace ensure $log.info "shutting down fluentd" diff --git a/lib/fluent/log.rb b/lib/fluent/log.rb index 8464c9fbac..95ca46be06 100644 --- a/lib/fluent/log.rb +++ b/lib/fluent/log.rb @@ -292,7 +292,11 @@ def event(level, args) } map.each_pair {|k,v| - message << " #{k}=#{v.inspect}" + if k == "error".freeze && v.is_a?(Exception) && !map.has_key?("error_class") + message << " error_class=#{v.class.to_s} error=#{v.to_s.inspect}" + else + message << " #{k}=#{v.inspect}" + end } unless @threads_exclude_events.include?(Thread.current) diff --git a/lib/fluent/output.rb b/lib/fluent/output.rb index d65f99b046..009bf308b5 100644 --- a/lib/fluent/output.rb +++ b/lib/fluent/output.rb @@ -329,20 +329,20 @@ def try_flush end if @disable_retry_limit || error_count < @retry_limit - $log.warn "temporarily failed to flush the buffer.", next_retry: Time.at(@next_retry_time), error_class: e.class.to_s, error: e.to_s, plugin_id: plugin_id + $log.warn "temporarily failed to flush the buffer.", next_retry: Time.at(@next_retry_time), error: e, plugin_id: plugin_id $log.warn_backtrace e.backtrace elsif @secondary if error_count == @retry_limit - $log.warn "failed to flush the buffer.", error_class: e.class.to_s, error: e.to_s, plugin_id: plugin_id + $log.warn "failed to flush the buffer.", error: e, plugin_id: plugin_id $log.warn "retry count exceededs limit. falling back to secondary output." $log.warn_backtrace e.backtrace retry # retry immediately elsif error_count <= @retry_limit + @secondary_limit - $log.warn "failed to flush the buffer, next retry will be with secondary output.", next_retry: Time.at(@next_retry_time), error_class: e.class.to_s, error: e.to_s, plugin_id: plugin_id + $log.warn "failed to flush the buffer, next retry will be with secondary output.", next_retry: Time.at(@next_retry_time), error: e, plugin_id: plugin_id $log.warn_backtrace e.backtrace else - $log.warn "failed to flush the buffer.", error_class: e.class, error: e.to_s, plugin_id: plugin_id + $log.warn "failed to flush the buffer.", error: e, plugin_id: plugin_id $log.warn "secondary retry count exceededs limit." $log.warn_backtrace e.backtrace write_abort @@ -350,7 +350,7 @@ def try_flush end else - $log.warn "failed to flush the buffer.", error_class: e.class.to_s, error: e.to_s, plugin_id: plugin_id + $log.warn "failed to flush the buffer.", error: e, plugin_id: plugin_id $log.warn "retry count exceededs limit." $log.warn_backtrace e.backtrace write_abort @@ -373,7 +373,7 @@ def before_shutdown begin @buffer.before_shutdown(self) rescue - $log.warn "before_shutdown failed", error: $!.to_s + $log.warn "before_shutdown failed", error: $! $log.warn_backtrace end end @@ -395,7 +395,7 @@ def write_abort begin @buffer.clear! rescue - $log.error "unexpected error while aborting", error: $!.to_s + $log.error "unexpected error while aborting", error: $! $log.error_backtrace end end diff --git a/lib/fluent/plugin/filter_grep.rb b/lib/fluent/plugin/filter_grep.rb index be8b61a2fa..0ba1328b8d 100644 --- a/lib/fluent/plugin/filter_grep.rb +++ b/lib/fluent/plugin/filter_grep.rb @@ -70,7 +70,7 @@ def filter(tag, time, record) result = record end rescue => e - log.warn "failed to grep events", error_class: e.class, error: e.message + log.warn "failed to grep events", error: e log.warn_backtrace end result diff --git a/lib/fluent/plugin/filter_record_transformer.rb b/lib/fluent/plugin/filter_record_transformer.rb index 6855dc99af..c2ca53ca9d 100644 --- a/lib/fluent/plugin/filter_record_transformer.rb +++ b/lib/fluent/plugin/filter_record_transformer.rb @@ -107,7 +107,7 @@ def filter_stream(tag, es) end new_es rescue => e - log.warn "failed to reform records", error_class: e.class, error: e.message + log.warn "failed to reform records", error: e log.warn_backtrace log.debug "map:#{@map} record:#{last_record} placeholder_values:#{placeholder_values}" end @@ -121,7 +121,7 @@ def parse_value(value_str) value_str end rescue => e - log.warn "failed to parse #{value_str} as json. Assuming #{value_str} is a string", error_class: e.class, error: e.message + log.warn "failed to parse #{value_str} as json. Assuming #{value_str} is a string", error: e value_str # emit as string end @@ -307,7 +307,7 @@ def expand(str, placeholders, force_stringify = false) placeholders['hostname'], ) rescue => e - log.warn "failed to expand `#{str}`", error_class: e.class, error: e.message + log.warn "failed to expand `#{str}`", error: e log.warn_backtrace nil end diff --git a/lib/fluent/plugin/in_exec.rb b/lib/fluent/plugin/in_exec.rb index 98585fb87c..00b8b4a12e 100644 --- a/lib/fluent/plugin/in_exec.rb +++ b/lib/fluent/plugin/in_exec.rb @@ -149,7 +149,7 @@ def run_periodic Process.waitpid(io.pid) sleep @run_interval rescue - log.error "exec failed to run or shutdown child process", error: $!.to_s, error_class: $!.class.to_s + log.error "exec failed to run or shutdown child process", error: $! log.warn_backtrace $!.backtrace end end @@ -176,7 +176,7 @@ def on_message(record, parsed_time = nil) router.emit(tag, time, record) rescue => e - log.error "exec failed to emit", error: e.to_s, error_class: e.class.to_s, tag: tag, record: Yajl.dump(record) + log.error "exec failed to emit", error: e, tag: tag, record: Yajl.dump(record) end end end diff --git a/lib/fluent/plugin/in_forward.rb b/lib/fluent/plugin/in_forward.rb index 525dc06fdb..2fbd52c271 100644 --- a/lib/fluent/plugin/in_forward.rb +++ b/lib/fluent/plugin/in_forward.rb @@ -106,7 +106,7 @@ def listen def run @loop.run(@blocking_timeout) rescue => e - log.error "unexpected error", error: e, error_class: e.class + log.error "unexpected error", error: e log.error_backtrace end diff --git a/lib/fluent/plugin/in_object_space.rb b/lib/fluent/plugin/in_object_space.rb index e3c28399fb..717b3b7ea7 100644 --- a/lib/fluent/plugin/in_object_space.rb +++ b/lib/fluent/plugin/in_object_space.rb @@ -115,7 +115,7 @@ def on_timer router.emit(@tag, now, record) rescue => e - log.error "object space failed to emit", error: e.to_s, error_class: e.class.to_s, tag: @tag, record: Yajl.dump(record) + log.error "object space failed to emit", error: e, tag: @tag, record: Yajl.dump(record) end end end diff --git a/lib/fluent/plugin/in_syslog.rb b/lib/fluent/plugin/in_syslog.rb index 60990049ab..206c8fbe4a 100644 --- a/lib/fluent/plugin/in_syslog.rb +++ b/lib/fluent/plugin/in_syslog.rb @@ -200,7 +200,7 @@ def emit(pri, time, record) router.emit(tag, time, record) rescue => e - log.error "syslog failed to emit", error: e.to_s, error_class: e.class.to_s, tag: tag, record: Yajl.dump(record) + log.error "syslog failed to emit", error: e, tag: tag, record: Yajl.dump(record) end end end diff --git a/lib/fluent/plugin/out_exec_filter.rb b/lib/fluent/plugin/out_exec_filter.rb index 93364248ea..6336559cd9 100644 --- a/lib/fluent/plugin/out_exec_filter.rb +++ b/lib/fluent/plugin/out_exec_filter.rb @@ -383,7 +383,7 @@ def on_message(record) router.emit(tag, time, record) rescue if @suppress_error_log_interval == 0 || Time.now.to_i > @next_log_time - log.error "exec_filter failed to emit", error: $!.to_s, error_class: $!.class.to_s, record: Yajl.dump(record) + log.error "exec_filter failed to emit", error: $!, record: Yajl.dump(record) log.warn_backtrace $!.backtrace @next_log_time = Time.now.to_i + @suppress_error_log_interval end diff --git a/lib/fluent/plugin/socket_util.rb b/lib/fluent/plugin/socket_util.rb index 8ae46e8d2a..83f2e00355 100644 --- a/lib/fluent/plugin/socket_util.rb +++ b/lib/fluent/plugin/socket_util.rb @@ -46,7 +46,7 @@ def on_readable msg.chomp! @callback.call(msg, addr) rescue => e - @log.error "unexpected error", error: e, error_class: e.class + @log.error "unexpected error", error: e end end @@ -82,7 +82,7 @@ def on_read(data) end @buffer.slice!(0, pos) if pos > 0 rescue => e - @log.error "unexpected error", error: e, error_class: e.class + @log.error "unexpected error", error: e close end @@ -133,7 +133,7 @@ def shutdown def run @loop.run(@blocking_timeout) rescue => e - log.error "unexpected error", error: e, error_class: e.class + log.error "unexpected error", error: e log.error_backtrace end @@ -150,7 +150,7 @@ def on_message(msg, addr) router.emit(@tag, time, record) } rescue => e - log.error msg.dump, error: e, error_class: e.class, host: addr[3] + log.error msg.dump, error: e, host: addr[3] log.error_backtrace end end diff --git a/lib/fluent/plugin/storage_local.rb b/lib/fluent/plugin/storage_local.rb index fabde6e0bd..2f9d1268e9 100644 --- a/lib/fluent/plugin/storage_local.rb +++ b/lib/fluent/plugin/storage_local.rb @@ -49,7 +49,7 @@ def configure(conf, plugin) data = Yajl::Parser.parse(open(@path, 'r:utf-8'){ |io| io.read }) raise Fluent::ConfigError, "Invalid contents (not object) in plugin storage file: '#{@path}'" unless data.is_a?(Hash) rescue => e - log.error "failed to read data from plugin storage file", path: @path, error_class: e.class, error: e + log.error "failed to read data from plugin storage file", path: @path, error: e raise Fluent::ConfigError, "Unexpected error: failed to read data from plugin storage file: '#{@path}'" end else @@ -71,7 +71,7 @@ def load end @store = json rescue => e - log.error "failed to load data for plugin storage from file", path: @path, error_class: e.class, error: e + log.error "failed to load data for plugin storage from file", path: @path, error: e end end @@ -83,7 +83,7 @@ def save open(tmp_path, 'w:utf-8', @mode){ |io| io.write json_string } File.rename(tmp_path, @path) rescue => e - log.error "failed to save data for plugin storage to file", path: @path, tmp: tmp_path, error_class: e.class, error: e + log.error "failed to save data for plugin storage to file", path: @path, tmp: tmp_path, error: e end end diff --git a/lib/fluent/plugin_helper/child_process.rb b/lib/fluent/plugin_helper/child_process.rb index 76341f999a..f36b68e947 100644 --- a/lib/fluent/plugin_helper/child_process.rb +++ b/lib/fluent/plugin_helper/child_process.rb @@ -272,10 +272,10 @@ def child_process_execute_once( if e.message == 'stream closed' log.debug "Process I/O stream closed", title: title, pid: pid, command: command, arguments: arguments else - log.error "Unexpected I/O error for child process", title: title, pid: pid, command: command, arguments: arguments, error_class: e.class, error: e + log.error "Unexpected I/O error for child process", title: title, pid: pid, command: command, arguments: arguments, error: e end rescue => e - log.warn "Unexpected error while processing I/O for child process", title: title, pid: pid, command: command, error_class: e.class, error: e + log.warn "Unexpected error while processing I/O for child process", title: title, pid: pid, command: command, error: e end process_info = @_child_process_mutex.synchronize do process_info = @_child_process_processes[pid] diff --git a/lib/fluent/plugin_helper/storage.rb b/lib/fluent/plugin_helper/storage.rb index cc89b83916..295590e7db 100644 --- a/lib/fluent/plugin_helper/storage.rb +++ b/lib/fluent/plugin_helper/storage.rb @@ -62,7 +62,7 @@ def storage_create(usage: '', type: nil, conf: nil) begin s.storage.save rescue => e - log.error "plugin storage failed to save its data", usage: usage, type: type, error_class: e.class, error: e + log.error "plugin storage failed to save its data", usage: usage, type: type, error: e end end end @@ -115,7 +115,7 @@ def shutdown begin s.storage.save if s.storage.save_at_shutdown rescue => e - log.error "unexpected error while saving data of plugin storages", usage: usage, storage: s.storage, error_class: e.class, error: e + log.error "unexpected error while saving data of plugin storages", usage: usage, storage: s.storage, error: e end end @@ -127,7 +127,7 @@ def close begin s.storage.close rescue => e - log.error "unexpected error while closing plugin storages", usage: usage, storage: s.storage, error_class: e.class, error: e + log.error "unexpected error while closing plugin storages", usage: usage, storage: s.storage, error: e end s.running = false end @@ -140,7 +140,7 @@ def terminate begin s.storage.terminate rescue => e - log.error "unexpected error while terminating plugin storages", usage: usage, storage: s.storage, error_class: e.class, error: e + log.error "unexpected error while terminating plugin storages", usage: usage, storage: s.storage, error: e end end @_storages = {} diff --git a/lib/fluent/plugin_helper/thread.rb b/lib/fluent/plugin_helper/thread.rb index d3273cbd79..4e40604505 100644 --- a/lib/fluent/plugin_helper/thread.rb +++ b/lib/fluent/plugin_helper/thread.rb @@ -60,7 +60,7 @@ def thread_create(title) yield thread_exit = true rescue => e - log.warn "thread exited by unexpected error", plugin: self.class, title: title, error_class: e.class, error: e + log.warn "thread exited by unexpected error", plugin: self.class, title: title, error: e thread_exit = true raise ensure diff --git a/lib/fluent/plugin_helper/timer.rb b/lib/fluent/plugin_helper/timer.rb index 5b17c6f98b..918bca94ee 100644 --- a/lib/fluent/plugin_helper/timer.rb +++ b/lib/fluent/plugin_helper/timer.rb @@ -74,7 +74,7 @@ def initialize(title, interval, repeat, log, checker, &callback) def on_timer @callback.call if @checker.call rescue => e - @log.error "Unexpected error raised. Stopping the timer.", title: @title, error: e, error_class: e.class + @log.error "Unexpected error raised. Stopping the timer.", title: @title, error: e @log.error_backtrace self.detach @log.error "Timer detached.", title: @title diff --git a/lib/fluent/root_agent.rb b/lib/fluent/root_agent.rb index 4814e20551..12b5eb1a54 100644 --- a/lib/fluent/root_agent.rb +++ b/lib/fluent/root_agent.rb @@ -126,7 +126,7 @@ def shutdown log.info "shutting down input", type: Plugin.lookup_type_from_class(i.class), plugin_id: i.plugin_id i.shutdown rescue => e - log.warn "unexpected error while shutting down input plugin", plugin: i.class, plugin_id: i.plugin_id, error_class: e.class, error: e + log.warn "unexpected error while shutting down input plugin", plugin: i.class, plugin_id: i.plugin_id, error: e log.warn_backtrace end end @@ -173,7 +173,7 @@ def find_label(label_name) end def emit_error_event(tag, time, record, error) - error_info = {error_class: error.class, error: error.to_s, tag: tag, time: time} + error_info = {error: error, tag: tag, time: time} if @error_collector # A record is not included in the logs because <@ERROR> handles it. This warn is for the notification log.warn "send an error event to @ERROR:", error_info @@ -185,7 +185,7 @@ def emit_error_event(tag, time, record, error) end def handle_emits_error(tag, es, error) - error_info = {error_class: error.class, error: error.to_s, tag: tag} + error_info = {error: error, tag: tag} if @error_collector log.warn "send an error event stream to @ERROR:", error_info @error_collector.emit_stream(tag, es) @@ -214,14 +214,14 @@ def initialize(root_agent) end def emit_error_event(tag, time, record, error) - error_info = {error_class: error.class, error: error.to_s, tag: tag, time: time, record: record} + error_info = {error: error, tag: tag, time: time, record: record} log.warn "dump an error event in @ERROR:", error_info end def handle_emits_error(tag, es, e) now = Engine.now if @suppress_emit_error_log_interval.zero? || now > @next_emit_error_log_time - log.warn "emit transaction failed in @ERROR:", error_class: e.class, error: e, tag: tag + log.warn "emit transaction failed in @ERROR:", error: e, tag: tag log.warn_backtrace @next_emit_error_log_time = now + @suppress_emit_error_log_interval end