Class: Fluent::Log
- Inherits:
-
Object
- Object
- Fluent::Log
- Defined in:
- lib/fluent/log.rb,
lib/fluent/log/console_adapter.rb
Direct Known Subclasses
Defined Under Namespace
Modules: TTYColor Classes: CachedLog, ConsoleAdapter
Constant Summary collapse
- LEVEL_TRACE =
0- LEVEL_DEBUG =
1- LEVEL_INFO =
2- LEVEL_WARN =
3- LEVEL_ERROR =
4- LEVEL_FATAL =
5- LEVEL_TEXT =
%w(trace debug info warn error fatal)
- LOG_EVENT_TAG_PREFIX =
'fluent'- LOG_EVENT_LABEL =
'@FLUENT_LOG'- LOG_TYPE_SUPERVISOR =
only in supervisor, or a worker with –no-supervisor
:supervisor- LOG_TYPE_WORKER0 =
only in a worker with worker_id=0 (without showing worker id)
:worker0- LOG_TYPE_DEFAULT =
show logs in all supervisor/workers, with worker id in workers (default)
:default- LOG_TYPES =
[LOG_TYPE_SUPERVISOR, LOG_TYPE_WORKER0, LOG_TYPE_DEFAULT].freeze
- LOG_ROTATE_AGE =
%w(daily weekly monthly)
- IGNORE_SAME_LOG_MAX_CACHE_SIZE =
If need, make this an option of system config.
1000
Instance Attribute Summary collapse
-
#format ⇒ Object
Returns the value of attribute format.
-
#ignore_repeated_log_interval ⇒ Object
Returns the value of attribute ignore_repeated_log_interval.
-
#ignore_same_log_interval ⇒ Object
Returns the value of attribute ignore_same_log_interval.
-
#level ⇒ Object
Strictly speaking, we should also change @logger.level when the setter of @level is called.
-
#log_event_enabled ⇒ Object
Returns the value of attribute log_event_enabled.
-
#optional_attrs ⇒ Object
Returns the value of attribute optional_attrs.
-
#optional_header ⇒ Object
Returns the value of attribute optional_header.
-
#out ⇒ Object
Returns the value of attribute out.
-
#suppress_repeated_stacktrace ⇒ Object
Returns the value of attribute suppress_repeated_stacktrace.
-
#time_format ⇒ Object
Returns the value of attribute time_format.
Class Method Summary collapse
- .event_tags ⇒ Object
-
.per_process_path(path, process_type, worker_id) ⇒ Object
Create a unique path for each process.
- .str_to_level(log_level_str) ⇒ Object
Instance Method Summary collapse
- #caller_line(type, time, depth, level) ⇒ Object
- #debug(*args, &block) ⇒ Object (also: #DEBUG)
- #debug_backtrace(backtrace = $!.backtrace, type: :default) ⇒ Object
-
#disable_events(thread) ⇒ Object
If you want to suppress event emitting in specific thread, please use this method.
- #dump_stacktrace(type, backtrace, level) ⇒ Object
- #dump_stacktrace_internal(type, backtrace, level) ⇒ Object
- #dup ⇒ Object
- #enable_color(b = true) ⇒ Object
- #enable_color? ⇒ Boolean
- #enable_debug(b = true) ⇒ Object
- #enable_event(b = true) ⇒ Object
- #error(*args, &block) ⇒ Object (also: #ERROR)
- #error_backtrace(backtrace = $!.backtrace, type: :default) ⇒ Object
- #event(level, args) ⇒ Object
- #fatal(*args, &block) ⇒ Object (also: #FATAL)
- #fatal_backtrace(backtrace = $!.backtrace, type: :default) ⇒ Object
- #flush ⇒ Object
- #force_stacktrace_level(level) ⇒ Object
- #force_stacktrace_level? ⇒ Boolean
- #format_time(time) ⇒ Object
- #get_worker_id(type) ⇒ Object
- #ignore_repeated_log?(key, time, message) ⇒ Boolean
- #ignore_same_log?(time, message) ⇒ Boolean
- #info(*args, &block) ⇒ Object (also: #INFO)
- #info_backtrace(backtrace = $!.backtrace, type: :default) ⇒ Object
-
#initialize(logger, opts = {}) ⇒ Log
constructor
A new instance of Log.
- #log_type(args) ⇒ Object
- #logdev=(logdev) ⇒ Object
- #on_debug ⇒ Object
- #on_error ⇒ Object
- #on_fatal ⇒ Object
- #on_info ⇒ Object
- #on_trace ⇒ Object
- #on_warn ⇒ Object
- #puts(msg) ⇒ Object
- #reopen! ⇒ Object
- #reset ⇒ Object
-
#skipped_type?(type) ⇒ Boolean
TODO: skip :worker0 logs when Fluentd gracefully restarted.
- #stdout? ⇒ Boolean
- #suppress_stacktrace?(backtrace) ⇒ Boolean
- #trace(*args, &block) ⇒ Object (also: #TRACE)
- #trace_backtrace(backtrace = $!.backtrace, type: :default) ⇒ Object
- #warn(*args, &block) ⇒ Object (also: #WARN)
- #warn_backtrace(backtrace = $!.backtrace, type: :default) ⇒ Object
- #write(data) ⇒ Object (also: #<<)
Constructor Details
#initialize(logger, opts = {}) ⇒ Log
Returns a new instance of Log.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/fluent/log.rb', line 90 def initialize(logger, opts={}) # When ServerEngine changes the logger.level, the Fluentd logger level should also change. # So overwrites logger.level= below. # However, currently Fluentd doesn't use the ServerEngine's reloading feature, # so maybe we don't need this overwriting anymore. orig_logger_level_setter = logger.class.public_instance_method(:level=).bind(logger) me = self # The original ruby logger sets the number as each log level like below. # DEBUG = 0 # INFO = 1 # WARN = 2 # ERROR = 3 # FATAL = 4 # Serverengine use this original log number. In addition to this, serverengine sets -1 as TRACE level. # TRACE = -1 # # On the other hand, in fluentd side, it sets the number like below. # TRACE = 0 # DEBUG = 1 # INFO = 2 # WARN = 3 # ERROR = 4 # FATAL = 5 # # Then fluentd's level is set as serverengine's level + 1. # So if serverengine's logger level is changed, fluentd's log level will be changed to that + 1. logger.define_singleton_method(:level=) {|level| orig_logger_level_setter.call(level); me.level = self.level + 1 } @path = opts[:path] @logger = logger @out = logger.instance_variable_get(:@logdev) @level = logger.level + 1 @debug_mode = false @log_event_enabled = false @depth_offset = 1 @format = nil @time_format = nil @formatter = nil self.format = opts.fetch(:format, :text) self.time_format = opts[:time_format] if opts.key?(:time_format) enable_color out.tty? # TODO: This variable name is unclear so we should change to better name. @threads_exclude_events = [] # Fluent::Engine requires Fluent::Log, so we must take that object lazily @engine = Fluent.const_get('Engine') @optional_header = nil @optional_attrs = nil @suppress_repeated_stacktrace = opts[:suppress_repeated_stacktrace] @forced_stacktrace_level = nil @ignore_repeated_log_interval = opts[:ignore_repeated_log_interval] @ignore_same_log_interval = opts[:ignore_same_log_interval] @process_type = opts[:process_type] # :supervisor, :worker0, :workers Or :standalone @process_type ||= :standalone # to keep behavior of existing code case @process_type when :supervisor @show_supervisor_log = true @show_worker0_log = false when :worker0 @show_supervisor_log = false @show_worker0_log = true when :workers @show_supervisor_log = false @show_worker0_log = false when :standalone @show_supervisor_log = true @show_worker0_log = true else raise "BUG: unknown process type for logger:#{@process_type}" end @worker_id = opts[:worker_id] @worker_id_part = "##{@worker_id} " # used only for :default log type in workers end |
Instance Attribute Details
#format ⇒ Object
Returns the value of attribute format.
182 183 184 |
# File 'lib/fluent/log.rb', line 182 def format @format end |
#ignore_repeated_log_interval ⇒ Object
Returns the value of attribute ignore_repeated_log_interval.
184 185 186 |
# File 'lib/fluent/log.rb', line 184 def ignore_repeated_log_interval @ignore_repeated_log_interval end |
#ignore_same_log_interval ⇒ Object
Returns the value of attribute ignore_same_log_interval.
184 185 186 |
# File 'lib/fluent/log.rb', line 184 def ignore_same_log_interval @ignore_same_log_interval end |
#level ⇒ Object
Strictly speaking, we should also change @logger.level when the setter of @level is called. Currently, we don’t need to do it, since Fluentd::Log doesn’t use ServerEngine::DaemonLogger.level. Since We overwrites logger.level= so that @logger.level is applied to @level, we need to find a good way to do this, otherwise we will end up in an endless loop.
190 191 192 |
# File 'lib/fluent/log.rb', line 190 def level @level end |
#log_event_enabled ⇒ Object
Returns the value of attribute log_event_enabled.
184 185 186 |
# File 'lib/fluent/log.rb', line 184 def log_event_enabled @log_event_enabled end |
#optional_attrs ⇒ Object
Returns the value of attribute optional_attrs.
191 192 193 |
# File 'lib/fluent/log.rb', line 191 def optional_attrs @optional_attrs end |
#optional_header ⇒ Object
Returns the value of attribute optional_header.
191 192 193 |
# File 'lib/fluent/log.rb', line 191 def optional_header @optional_header end |
#out ⇒ Object
Returns the value of attribute out.
185 186 187 |
# File 'lib/fluent/log.rb', line 185 def out @out end |
#suppress_repeated_stacktrace ⇒ Object
Returns the value of attribute suppress_repeated_stacktrace.
184 185 186 |
# File 'lib/fluent/log.rb', line 184 def suppress_repeated_stacktrace @suppress_repeated_stacktrace end |
#time_format ⇒ Object
Returns the value of attribute time_format.
183 184 185 |
# File 'lib/fluent/log.rb', line 183 def time_format @time_format end |
Class Method Details
.event_tags ⇒ Object
68 69 70 |
# File 'lib/fluent/log.rb', line 68 def self. LEVEL_TEXT.map{|t| "#{LOG_EVENT_TAG_PREFIX}.#{t}" } end |
.per_process_path(path, process_type, worker_id) ⇒ Object
Create a unique path for each process.
>>> per_process_path(“C:/tmp/test.log”, :worker, 1) C:/tmp/test-1.log >>> per_process_path(“C:/tmp/test.log”, :supervisor, 0) C:/tmp/test-supervisor-0.log
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/fluent/log.rb', line 78 def self.per_process_path(path, process_type, worker_id) path = Pathname(path) ext = path.extname if process_type == :supervisor suffix = "-#{process_type}-0#{ext}" # "-0" for backword compatibility. else suffix = "-#{worker_id}#{ext}" end return path.sub_ext(suffix).to_s end |
.str_to_level(log_level_str) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/fluent/log.rb', line 56 def self.str_to_level(log_level_str) case log_level_str.downcase when "trace" then LEVEL_TRACE when "debug" then LEVEL_DEBUG when "info" then LEVEL_INFO when "warn" then LEVEL_WARN when "error" then LEVEL_ERROR when "fatal" then LEVEL_FATAL else raise "Unknown log level: level = #{log_level_str}" end end |
Instance Method Details
#caller_line(type, time, depth, level) ⇒ Object
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 |
# File 'lib/fluent/log.rb', line 617 def caller_line(type, time, depth, level) worker_id_part = if type == :default && (@process_type == :worker0 || @process_type == :workers) @worker_id_part else "".freeze end log_msg = "#{format_time(time)} [#{LEVEL_TEXT[level]}]: #{worker_id_part}" if @debug_mode line = caller(depth+1)[0] if match = /^(.+?):(\d+)(?::in `(.*)')?/.match(line) file = match[1].split('/')[-2,2].join('/') line = match[2] method = match[3] return "#{log_msg}#{file}:#{line}:#{method}: " end end return log_msg end |
#debug(*args, &block) ⇒ Object Also known as: DEBUG
344 345 346 347 348 349 350 351 352 353 |
# File 'lib/fluent/log.rb', line 344 def debug(*args, &block) return if @level > LEVEL_DEBUG type = log_type(args) return if skipped_type?(type) args << block.call if block time, msg = event(:debug, args) return if time.nil? puts [@color_debug, @formatter.call(type, time, LEVEL_DEBUG, msg), @color_reset].join rescue end |
#debug_backtrace(backtrace = $!.backtrace, type: :default) ⇒ Object
356 357 358 |
# File 'lib/fluent/log.rb', line 356 def debug_backtrace(backtrace=$!.backtrace, type: :default) dump_stacktrace(type, backtrace, LEVEL_DEBUG) end |
#disable_events(thread) ⇒ Object
If you want to suppress event emitting in specific thread, please use this method. Events in passed thread are never emitted.
265 266 267 268 |
# File 'lib/fluent/log.rb', line 265 def disable_events(thread) # this method is not symmetric with #enable_event. @threads_exclude_events.push(thread) unless @threads_exclude_events.include?(thread) end |
#dump_stacktrace(type, backtrace, level) ⇒ Object
510 511 512 513 514 515 516 517 518 |
# File 'lib/fluent/log.rb', line 510 def dump_stacktrace(type, backtrace, level) return if @level > level dump_stacktrace_internal( type, backtrace, force_stacktrace_level? ? @forced_stacktrace_level : level, ) end |
#dump_stacktrace_internal(type, backtrace, level) ⇒ Object
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 |
# File 'lib/fluent/log.rb', line 520 def dump_stacktrace_internal(type, backtrace, level) return if @level > level time = Time.now if @format == :text line = caller_line(type, time, 5, level) if @ignore_repeated_log_interval && ignore_repeated_log?(:last_repeated_stacktrace, time, backtrace) return elsif @suppress_repeated_stacktrace && suppress_stacktrace?(backtrace) puts [" ", line, 'suppressed same stacktrace'].join Thread.current[:last_repeated_stacktrace] = CachedLog.new(backtrace, time) if @ignore_repeated_log_interval else backtrace.each { |msg| puts [" ", line, msg].join } Thread.current[:last_repeated_stacktrace] = CachedLog.new(backtrace, time) if @suppress_repeated_stacktrace end else r = { 'time' => format_time(time), 'level' => LEVEL_TEXT[level], } if wid = get_worker_id(type) r['worker_id'] = wid end if @ignore_repeated_log_interval && ignore_repeated_log?(:last_repeated_stacktrace, time, backtrace) return elsif @suppress_repeated_stacktrace && suppress_stacktrace?(backtrace) r['message'] = 'suppressed same stacktrace' Thread.current[:last_repeated_stacktrace] = CachedLog.new(backtrace, time) if @ignore_repeated_log_interval else r['message'] = backtrace.join("\n") Thread.current[:last_repeated_stacktrace] = CachedLog.new(backtrace, time) if @suppress_repeated_stacktrace end puts Yajl.dump(r) end nil end |
#dup ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/fluent/log.rb', line 167 def dup dl_opts = {} dl_opts[:log_level] = @level - 1 logger = ServerEngine::DaemonLogger.new(@out, dl_opts) clone = self.class.new(logger, suppress_repeated_stacktrace: @suppress_repeated_stacktrace, process_type: @process_type, worker_id: @worker_id, ignore_repeated_log_interval: @ignore_repeated_log_interval, ignore_same_log_interval: @ignore_same_log_interval) clone.format = @format clone.time_format = @time_format clone.log_event_enabled = @log_event_enabled clone.force_stacktrace_level(@forced_stacktrace_level) # optional headers/attrs are not copied, because new PluginLogger should have another one of it clone end |
#enable_color(b = true) ⇒ Object
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
# File 'lib/fluent/log.rb', line 274 def enable_color(b=true) if b @color_trace = TTYColor::BLUE @color_debug = TTYColor::WHITE @color_info = TTYColor::GREEN @color_warn = TTYColor::YELLOW @color_error = TTYColor::MAGENTA @color_fatal = TTYColor::RED @color_reset = TTYColor::NORMAL else @color_trace = '' @color_debug = '' @color_info = '' @color_warn = '' @color_error = '' @color_fatal = '' @color_reset = '' end self end |
#enable_color? ⇒ Boolean
270 271 272 |
# File 'lib/fluent/log.rb', line 270 def enable_color? !@color_reset.empty? end |
#enable_debug(b = true) ⇒ Object
253 254 255 256 |
# File 'lib/fluent/log.rb', line 253 def enable_debug(b=true) @debug_mode = b self end |
#enable_event(b = true) ⇒ Object
258 259 260 261 |
# File 'lib/fluent/log.rb', line 258 def enable_event(b=true) @log_event_enabled = b self end |
#error(*args, &block) ⇒ Object Also known as: ERROR
407 408 409 410 411 412 413 414 415 416 |
# File 'lib/fluent/log.rb', line 407 def error(*args, &block) return if @level > LEVEL_ERROR type = log_type(args) return if skipped_type?(type) args << block.call if block time, msg = event(:error, args) return if time.nil? puts [@color_error, @formatter.call(type, time, LEVEL_ERROR, msg), @color_reset].join rescue end |
#error_backtrace(backtrace = $!.backtrace, type: :default) ⇒ Object
419 420 421 |
# File 'lib/fluent/log.rb', line 419 def error_backtrace(backtrace=$!.backtrace, type: :default) dump_stacktrace(type, backtrace, LEVEL_ERROR) end |
#event(level, args) ⇒ Object
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 |
# File 'lib/fluent/log.rb', line 571 def event(level, args) time = Time.now = @optional_header ? @optional_header.dup : '' map = @optional_attrs ? @optional_attrs.dup : {} args.each {|a| if a.is_a?(Hash) a.each_pair {|k,v| map[k.to_s] = v } else << a.to_s end } map.each_pair {|k,v| if k == "error".freeze && v.is_a?(Exception) && !map.has_key?("error_class") << " error_class=#{v.class.to_s} error=#{v.to_s.inspect}" else << " #{k}=#{v.inspect}" end } if @ignore_same_log_interval if ignore_same_log?(time, ) return nil, nil end elsif @ignore_repeated_log_interval if ignore_repeated_log?(:last_repeated_log, time, ) return nil, nil else Thread.current[:last_repeated_log] = CachedLog.new(, time) end end if @log_event_enabled && !@threads_exclude_events.include?(Thread.current) record = map.dup record.keys.each {|key| record[key] = record[key].inspect unless record[key].respond_to?(:to_msgpack) } record['message'] = .dup @engine.push_log_event("#{LOG_EVENT_TAG_PREFIX}.#{level}", Fluent::EventTime.from_time(time), record) end return time, end |
#fatal(*args, &block) ⇒ Object Also known as: FATAL
428 429 430 431 432 433 434 435 436 437 |
# File 'lib/fluent/log.rb', line 428 def fatal(*args, &block) return if @level > LEVEL_FATAL type = log_type(args) return if skipped_type?(type) args << block.call if block time, msg = event(:fatal, args) return if time.nil? puts [@color_fatal, @formatter.call(type, time, LEVEL_FATAL, msg), @color_reset].join rescue end |
#fatal_backtrace(backtrace = $!.backtrace, type: :default) ⇒ Object
440 441 442 |
# File 'lib/fluent/log.rb', line 440 def fatal_backtrace(backtrace=$!.backtrace, type: :default) dump_stacktrace(type, backtrace, LEVEL_FATAL) end |
#flush ⇒ Object
460 461 462 |
# File 'lib/fluent/log.rb', line 460 def flush @out.flush end |
#force_stacktrace_level(level) ⇒ Object
249 250 251 |
# File 'lib/fluent/log.rb', line 249 def force_stacktrace_level(level) @forced_stacktrace_level = level end |
#force_stacktrace_level? ⇒ Boolean
245 246 247 |
# File 'lib/fluent/log.rb', line 245 def force_stacktrace_level? not @forced_stacktrace_level.nil? end |
#format_time(time) ⇒ Object
636 637 638 |
# File 'lib/fluent/log.rb', line 636 def format_time(time) @time_formatter ? @time_formatter.exec(time) : time.strftime(@time_format) end |
#get_worker_id(type) ⇒ Object
563 564 565 566 567 568 569 |
# File 'lib/fluent/log.rb', line 563 def get_worker_id(type) if type == :default && (@process_type == :worker0 || @process_type == :workers) @worker_id else nil end end |
#ignore_repeated_log?(key, time, message) ⇒ Boolean
470 471 472 473 474 |
# File 'lib/fluent/log.rb', line 470 def ignore_repeated_log?(key, time, ) cached_log = Thread.current[key] return false if cached_log.nil? (cached_log.msg == ) && (time - cached_log.time <= @ignore_repeated_log_interval) end |
#ignore_same_log?(time, message) ⇒ Boolean
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 |
# File 'lib/fluent/log.rb', line 476 def ignore_same_log?(time, ) cached_log = Thread.current[:last_same_log] if cached_log.nil? Thread.current[:last_same_log] = { => time} return false end prev_time = cached_log[] if prev_time if (time - prev_time) <= @ignore_same_log_interval true else cached_log[] = time false end else if cached_log.size >= IGNORE_SAME_LOG_MAX_CACHE_SIZE cached_log.reject! do |_, cached_time| (time - cached_time) > @ignore_same_log_interval end end # If the size is still over, we have no choice but to clear it. cached_log.clear if cached_log.size >= IGNORE_SAME_LOG_MAX_CACHE_SIZE cached_log[] = time false end end |
#info(*args, &block) ⇒ Object Also known as: INFO
365 366 367 368 369 370 371 372 373 374 |
# File 'lib/fluent/log.rb', line 365 def info(*args, &block) return if @level > LEVEL_INFO type = log_type(args) return if skipped_type?(type) args << block.call if block time, msg = event(:info, args) return if time.nil? puts [@color_info, @formatter.call(type, time, LEVEL_INFO, msg), @color_reset].join rescue end |
#info_backtrace(backtrace = $!.backtrace, type: :default) ⇒ Object
377 378 379 |
# File 'lib/fluent/log.rb', line 377 def info_backtrace(backtrace=$!.backtrace, type: :default) dump_stacktrace(type, backtrace, LEVEL_INFO) end |
#log_type(args) ⇒ Object
295 296 297 298 299 300 301 |
# File 'lib/fluent/log.rb', line 295 def log_type(args) if LOG_TYPES.include?(args.first) args.shift else LOG_TYPE_DEFAULT end end |
#logdev=(logdev) ⇒ Object
193 194 195 196 197 |
# File 'lib/fluent/log.rb', line 193 def logdev=(logdev) @out = logdev @logger.instance_variable_set(:@logdev, logdev) nil end |
#on_debug ⇒ Object
339 340 341 342 |
# File 'lib/fluent/log.rb', line 339 def on_debug return if @level > LEVEL_DEBUG yield end |
#on_error ⇒ Object
402 403 404 405 |
# File 'lib/fluent/log.rb', line 402 def on_error return if @level > LEVEL_ERROR yield end |
#on_fatal ⇒ Object
423 424 425 426 |
# File 'lib/fluent/log.rb', line 423 def on_fatal return if @level > LEVEL_FATAL yield end |
#on_info ⇒ Object
360 361 362 363 |
# File 'lib/fluent/log.rb', line 360 def on_info return if @level > LEVEL_INFO yield end |
#on_trace ⇒ Object
317 318 319 320 |
# File 'lib/fluent/log.rb', line 317 def on_trace return if @level > LEVEL_TRACE yield end |
#on_warn ⇒ Object
381 382 383 384 |
# File 'lib/fluent/log.rb', line 381 def on_warn return if @level > LEVEL_WARN yield end |
#puts(msg) ⇒ Object
444 445 446 447 448 449 450 451 |
# File 'lib/fluent/log.rb', line 444 def puts(msg) @logger << msg + "\n" @out.flush msg rescue # FIXME nil end |
#reopen! ⇒ Object
240 241 242 243 |
# File 'lib/fluent/log.rb', line 240 def reopen! @out.reopen(@path, "a") if @path && @path != "-" nil end |
#reset ⇒ Object
464 465 466 |
# File 'lib/fluent/log.rb', line 464 def reset @out.reset if @out.respond_to?(:reset) end |
#skipped_type?(type) ⇒ Boolean
TODO: skip :worker0 logs when Fluentd gracefully restarted
304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'lib/fluent/log.rb', line 304 def skipped_type?(type) case type when LOG_TYPE_DEFAULT false when LOG_TYPE_WORKER0 !@show_worker0_log when LOG_TYPE_SUPERVISOR !@show_supervisor_log else raise "BUG: unknown log type:#{type}" end end |
#stdout? ⇒ Boolean
236 237 238 |
# File 'lib/fluent/log.rb', line 236 def stdout? @out == $stdout end |
#suppress_stacktrace?(backtrace) ⇒ Boolean
504 505 506 507 508 |
# File 'lib/fluent/log.rb', line 504 def suppress_stacktrace?(backtrace) cached_log = Thread.current[:last_repeated_stacktrace] return false if cached_log.nil? cached_log.msg == backtrace end |
#trace(*args, &block) ⇒ Object Also known as: TRACE
322 323 324 325 326 327 328 329 330 331 332 |
# File 'lib/fluent/log.rb', line 322 def trace(*args, &block) return if @level > LEVEL_TRACE type = log_type(args) return if skipped_type?(type) args << block.call if block time, msg = event(:trace, args) return if time.nil? puts [@color_trace, @formatter.call(type, time, LEVEL_TRACE, msg), @color_reset].join rescue # logger should not raise an exception. This rescue prevents unexpected behaviour. end |
#trace_backtrace(backtrace = $!.backtrace, type: :default) ⇒ Object
335 336 337 |
# File 'lib/fluent/log.rb', line 335 def trace_backtrace(backtrace=$!.backtrace, type: :default) dump_stacktrace(type, backtrace, LEVEL_TRACE) end |
#warn(*args, &block) ⇒ Object Also known as: WARN
386 387 388 389 390 391 392 393 394 395 |
# File 'lib/fluent/log.rb', line 386 def warn(*args, &block) return if @level > LEVEL_WARN type = log_type(args) return if skipped_type?(type) args << block.call if block time, msg = event(:warn, args) return if time.nil? puts [@color_warn, @formatter.call(type, time, LEVEL_WARN, msg), @color_reset].join rescue end |
#warn_backtrace(backtrace = $!.backtrace, type: :default) ⇒ Object
398 399 400 |
# File 'lib/fluent/log.rb', line 398 def warn_backtrace(backtrace=$!.backtrace, type: :default) dump_stacktrace(type, backtrace, LEVEL_WARN) end |
#write(data) ⇒ Object Also known as: <<
453 454 455 |
# File 'lib/fluent/log.rb', line 453 def write(data) @out.write(data) end |