Class: Narou::ConcurrencyDefaultLogger

Inherits:
Logger
  • Object
show all
Defined in:
lib/narou_logger.rb

Overview

同時実行時のデフォルト側ロガー 変換中のキューを表示出来るようにする(キュー表示部分はログに保存しない)

Constant Summary collapse

FORMAT_TEXT =
"変換中:%<size>d"
FORMAT_STYLE =
"\e[%<left>dG<cyan>%<text>s</cyan>\e[1G"

Constants included from LoggerModule

LoggerModule::LOG_FORMAT_FILENAME, LoggerModule::LOG_FORMAT_TIMESTAMP

Instance Attribute Summary collapse

Attributes included from LoggerModule

#capturing, #format_filename, #format_timestamp, #format_timestamp_disabled, #log_postfix, #logging_enabled, #stream

Instance Method Summary collapse

Methods inherited from Logger

#tty?, #write

Methods included from LoggerModule

#append_log, #capture, #copy_instance, #create_log_dir, #disable_logging, #dup_with_disabled_logging, #embed_timestamp, #error, included, #init_logs, #log_filename, #log_filepath, #logging?, #save, #silence, #silent=, #silent?, #strip_color, #warn, #write_base

Constructor Details

#initializeConcurrencyDefaultLogger

Returns a new instance of ConcurrencyDefaultLogger.



245
246
247
248
249
250
251
# File 'lib/narou_logger.rb', line 245

def initialize
  super
  self.end_with_new_line = true
  concurrency = Inventory.load.group("concurrency")
  self.format_text = concurrency.format_queue_text || FORMAT_TEXT
  self.format_style = concurrency.format_queue_style || FORMAT_STYLE
end

Instance Attribute Details

#end_with_new_lineObject

Returns the value of attribute end_with_new_line.



240
241
242
# File 'lib/narou_logger.rb', line 240

def end_with_new_line
  @end_with_new_line
end

#format_styleObject

Returns the value of attribute format_style.



240
241
242
# File 'lib/narou_logger.rb', line 240

def format_style
  @format_style
end

#format_textObject

Returns the value of attribute format_text.



240
241
242
# File 'lib/narou_logger.rb', line 240

def format_text
  @format_text
end

Instance Method Details

#write_console(str, target) ⇒ Object



253
254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/narou_logger.rb', line 253

def write_console(str, target)
  str.each_line do |line|
    size = Worker.size
    if size > 0 && end_with_new_line
      text = format(format_text, size: size)
      text_width = text.display_width
      console_width = IO.console_size[1]
      left = console_width - text_width - 1
      stream.print format(format_style, left: left, text: text, space: " ").termcolor
    end
    super(line, target)
  end
  self.end_with_new_line = str.end_with?("\n")
end