Method: Common::Color#print_log

Defined in:
lib/common/color.rb

Print a message in log.

Parameters:

  • msg_type

    The type of message

  • msg

    The message to write in log

  • stdout (defaults to: STDOUT)

    The output standard.

Author:

  • tmarmin



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/common/color.rb', line 178

def print_log(msg_type, msg, stdout = STDOUT)
  date = "[" + Time.now.strftime("%Y-%m-%d %H:%M:%S") + "] "

  msg_length = date.length + msg.length

  msg = date + msg

  right_margin = 5
  max_consolelength = 80
  console_length=`tput cols`
  if console_length.to_i > max_consolelength
    console_length = max_consolelength
  end
  msg_length = 8 + right_margin + msg_length % console_length.to_i
  stdout.printf(color_white(msg, 1))
  printf_normal(align_right(msg_length, console_length), stdout)

  case msg_type
    when "OK", "ok"
      echo_ok
    when "FAIL", "fail"
      echo_fail
    when "WARN", "warn"
      echo_warn
  end
end