Class: HireFire::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/hirefire/logger.rb

Class Method Summary collapse

Class Method Details

.colorize(string, code) ⇒ String

Wraps the provided string in colorizing tags to provide easier to view output to the client

Parameters:

  • string (String)

Returns:

  • (String)

    the provided string in special tags to color it red in the console



93
94
95
# File 'lib/hirefire/logger.rb', line 93

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

.error(string) ⇒ nil

Outputs an error to the console

Parameters:

  • string (String)

    prints a string to the console (red color)

Returns:

  • (nil)


20
21
22
# File 'lib/hirefire/logger.rb', line 20

def self.error(string)
  puts loggify(string, :red)
end

.green(string) ⇒ String

Invokes the #colorize method with the provided string and the color code “32” (for green)

Parameters:

  • string (String)

Returns:

  • (String)

    the provided string in special tags to color it green in the console



66
67
68
# File 'lib/hirefire/logger.rb', line 66

def self.green(string)
  colorize(string, 32)
end

.loggify(string, color = false) ⇒ String

Builds the string in a log format with the date/time, the type (colorized) based on whether it’s a message, notice or error, and the message itself.

Parameters:

  • string (String)

    the string to print to the console

  • color (Symbol, false) (defaults to: false)

    the color to print the string in

Returns:

  • (String)

    the log-like formatted string



49
50
51
52
# File 'lib/hirefire/logger.rb', line 49

def self.loggify(string, color = false)
  return "[#{time}][HireFire] #{string}" unless color
  "[#{time}][#{send(color, 'HireFire')}] #{string}"
end

.message(string) ⇒ nil

Outputs a messages to the console

Parameters:

  • string (String)

    prints a string to the console (green color)

Returns:

  • (nil)


11
12
13
# File 'lib/hirefire/logger.rb', line 11

def self.message(string)
  puts loggify(string, :green)
end

.normal(string) ⇒ nil

Outputs the data as if it were a regular ‘puts’ command

Parameters:

  • string (String)

    prints a string to the console (standard color)

Returns:

  • (nil)


38
39
40
# File 'lib/hirefire/logger.rb', line 38

def self.normal(string)
  puts string
end

.red(string) ⇒ Object

Invokes the #colorize method the with provided string and the color code “31” (for red)



83
84
85
# File 'lib/hirefire/logger.rb', line 83

def self.red(string)
  colorize(string, 31)
end

.timeTime

Returns the time in [YYYY-MM-DD HH:MM:SS] format.

Returns:

  • (Time)

    the time in [YYYY-MM-DD HH:MM:SS] format



56
57
58
# File 'lib/hirefire/logger.rb', line 56

def self.time
  Time.now.strftime("%Y-%m-%d %H:%M:%S")
end

.warn(string) ⇒ nil

Outputs a notice to the console

Parameters:

  • string (String)

    prints a string to the console (yellow color)

Returns:

  • (nil)


29
30
31
# File 'lib/hirefire/logger.rb', line 29

def self.warn(string)
  puts loggify(string, :yellow)
end

.yellow(string) ⇒ String

Invokes the #colorize method with the provided string and the color code “33” (for yellow)

Parameters:

  • string (String)

Returns:

  • (String)

    the provided string in special tags to color it yellow in the console



76
77
78
# File 'lib/hirefire/logger.rb', line 76

def self.yellow(string)
  colorize(string, 33)
end