Class: Fluent::Plugin::StdoutOutput

Inherits:
Output show all
Defined in:
lib/fluent/plugin/out_stdout.rb

Constant Summary collapse

DEFAULT_FORMAT_TYPE =
'json'
TIME_FORMAT =
'%Y-%m-%d %H:%M:%S.%9N %z'

Constants inherited from Output

Output::CHUNKING_FIELD_WARN_NUM, Output::CHUNK_KEY_PATTERN, Output::CHUNK_KEY_PLACEHOLDER_PATTERN, Output::CHUNK_TAG_PLACEHOLDER_PATTERN, Output::FORMAT_COMPRESSED_MSGPACK_STREAM, Output::FORMAT_COMPRESSED_MSGPACK_STREAM_TIME_INT, Output::FORMAT_MSGPACK_STREAM, Output::FORMAT_MSGPACK_STREAM_TIME_INT, Output::TIMESTAMP_CHECK_BASE_TIME, Output::TIME_KEY_PLACEHOLDER_THRESHOLDS

Constants included from Configurable

Configurable::CONFIG_TYPE_REGISTRY

Instance Attribute Summary collapse

Attributes inherited from Output

#as_secondary, #buffer, #chunk_key_tag, #chunk_key_time, #chunk_keys, #delayed_commit, #delayed_commit_timeout, #emit_count, #emit_records, #in_tests, #num_errors, #output_enqueue_thread_waiting, #retry, #rollback_count, #secondary, #timekey_zone, #write_count

Attributes included from Fluent::PluginLoggerMixin

#log

Attributes inherited from Base

#under_plugin_development

Instance Method Summary collapse

Methods inherited from Output

#acts_as_secondary, #after_shutdown, #after_start, #before_shutdown, #close, #commit_write, #emit_buffered, #emit_events, #emit_sync, #enqueue_thread_run, #enqueue_thread_wait, #execute_chunking, #extract_placeholders, #flush_thread_run, #flush_thread_wakeup, #force_flush, #formatted_to_msgpack_binary, #generate_format_proc, #get_placeholders_keys, #get_placeholders_tag, #get_placeholders_time, #handle_stream_simple, #handle_stream_with_custom_format, #handle_stream_with_standard_format, #implement?, #interrupt_flushes, #metadata, #metadata_for_test, #next_flush_time, #placeholder_validate!, #placeholder_validators, #retry_state, #rollback_write, #shutdown, #start, #stop, #submit_flush_all, #submit_flush_once, #support_in_v12_style?, #terminate, #try_flush, #try_rollback_all, #try_rollback_write, #write_guard

Methods included from UniqueId::Mixin

#dump_unique_id_hex, #generate_unique_id

Methods included from Fluent::PluginHelper::Mixin

included

Methods included from Fluent::PluginLoggerMixin

included, #start, #terminate

Methods included from Fluent::PluginId

#plugin_id, #plugin_id_configured?, #plugin_id_for_test?

Methods inherited from Base

#after_shutdown, #after_shutdown?, #after_start, #after_started?, #before_shutdown, #before_shutdown?, #close, #closed?, #configured?, #has_router?, #inspect, #shutdown, #shutdown?, #start, #started?, #stop, #stopped?, #terminate, #terminated?

Methods included from SystemConfig::Mixin

#system_config, #system_config_override

Methods included from Configurable

#config, included, lookup_type, register_type

Constructor Details

#initializeStdoutOutput

Returns a new instance of StdoutOutput.



48
49
50
51
# File 'lib/fluent/plugin/out_stdout.rb', line 48

def initialize
  super
  @delayed = false
end

Instance Attribute Details

#delayedObject

Returns the value of attribute delayed.



46
47
48
# File 'lib/fluent/plugin/out_stdout.rb', line 46

def delayed
  @delayed
end

Instance Method Details

#configure(conf) ⇒ Object



53
54
55
56
57
58
59
60
61
62
# File 'lib/fluent/plugin/out_stdout.rb', line 53

def configure(conf)
  if conf['output_type'] && !conf['format']
    conf['format'] = conf['output_type']
  end
  compat_parameters_convert(conf, :inject, :formatter)

  super

  @formatter = formatter_create(conf: conf.elements('format').first, default_type: DEFAULT_FORMAT_TYPE)
end

#format(tag, time, record) ⇒ Object



71
72
73
74
# File 'lib/fluent/plugin/out_stdout.rb', line 71

def format(tag, time, record)
  record = inject_values_to_record(tag, time, record)
  "#{Time.at(time).localtime.strftime(TIME_FORMAT)} #{tag}: #{@formatter.format(tag, time, record).chomp}\n"
end

#prefer_buffered_processingObject



38
39
40
# File 'lib/fluent/plugin/out_stdout.rb', line 38

def prefer_buffered_processing
  false
end

#prefer_delayed_commitObject



42
43
44
# File 'lib/fluent/plugin/out_stdout.rb', line 42

def prefer_delayed_commit
  @delayed
end

#process(tag, es) ⇒ Object



64
65
66
67
68
69
# File 'lib/fluent/plugin/out_stdout.rb', line 64

def process(tag, es)
  es.each {|time,record|
    $log.write(format(tag, time, record))
  }
  $log.flush
end

#try_write(chunk) ⇒ Object



80
81
82
83
# File 'lib/fluent/plugin/out_stdout.rb', line 80

def try_write(chunk)
  chunk.write_to($log)
  commit_write(chunk.unique_id)
end

#write(chunk) ⇒ Object



76
77
78
# File 'lib/fluent/plugin/out_stdout.rb', line 76

def write(chunk)
  chunk.write_to($log)
end