Module: OnlyofficeLoggerHelper

Defined in:
lib/onlyoffice_logger_helper/logger_helper.rb,
lib/onlyoffice_logger_helper/version.rb

Overview

Module for output stuff in console

Constant Summary collapse

NAME =

Returns name of gem.

Returns:

  • (String)

    name of gem

'onlyoffice_logger_helper'
VERSION =

Returns version of gem.

Returns:

  • (String)

    version of gem

'1.3.0'
GREEN_COLOR_CODE =

Green color code

32
RED_COLOR_CODE =

Red color code

31

Class Method Summary collapse

Class Method Details

.colorize(text, color_code) ⇒ Object

Add color code to text

Parameters:

  • text (String)

    text to add color

  • color_code (Integer)

    code of color



23
24
25
# File 'lib/onlyoffice_logger_helper/logger_helper.rb', line 23

def self.colorize(text, color_code)
  "\e[#{color_code}m#{text}\e[0m"
end

.green_log(entry) ⇒ void

This method returns an undefined value.

Colorize log in green

Parameters:

  • entry (String)

    line to output



30
31
32
# File 'lib/onlyoffice_logger_helper/logger_helper.rb', line 30

def self.green_log(entry)
  log(entry, GREEN_COLOR_CODE)
end

.log(entry, color_code = nil) ⇒ Object

Output log entry to terminal

Parameters:

  • entry (String)

    line to output

  • color_code (Integer) (defaults to: nil)

    code of color



13
14
15
16
17
18
# File 'lib/onlyoffice_logger_helper/logger_helper.rb', line 13

def self.log(entry, color_code = nil)
  caller_name = caller(1..1).first.to_s[/\w+.rb/].chomp('.rb')
  time_stamp = Time.now.strftime('%T/%d.%m.%y')
  message = "#{time_stamp}    [#{caller_name}] #{entry}"
  color_code ? puts(colorize(message, color_code)) : puts(message)
end

.red_log(entry) ⇒ void

This method returns an undefined value.

Colorize log in red

Parameters:

  • entry (String)

    line to output



37
38
39
# File 'lib/onlyoffice_logger_helper/logger_helper.rb', line 37

def self.red_log(entry)
  log(entry, RED_COLOR_CODE)
end

.sleep_and_log(reason, seconds) ⇒ void

This method returns an undefined value.

Sleep for some time and output log

Parameters:

  • reason (String)

    message to output

  • seconds (Integer)

    time to sleep



45
46
47
48
49
# File 'lib/onlyoffice_logger_helper/logger_helper.rb', line 45

def self.sleep_and_log(reason, seconds)
  log("Start sleeping for #{seconds} seconds because of `#{reason}`")
  sleep(seconds)
  log("Stopped sleeping for #{seconds} seconds because of `#{reason}`")
end