Class: HireFire::Logger
- Inherits:
-
Object
- Object
- HireFire::Logger
- Defined in:
- lib/hirefire/logger.rb
Class Method Summary collapse
-
.colorize(string, code) ⇒ String
Wraps the provided string in colorizing tags to provide easier to view output to the client.
-
.error(string) ⇒ nil
Outputs an error to the console.
-
.green(string) ⇒ String
Invokes the #colorize method with the provided string and the color code “32” (for green).
-
.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.
-
.message(string) ⇒ nil
Outputs a messages to the console.
-
.normal(string) ⇒ nil
Outputs the data as if it were a regular ‘puts’ command.
-
.red(string) ⇒ Object
Invokes the #colorize method the with provided string and the color code “31” (for red).
-
.time ⇒ Time
The time in [YYYY-MM-DD HH:MM:SS] format.
-
.warn(string) ⇒ nil
Outputs a notice to the console.
-
.yellow(string) ⇒ String
Invokes the #colorize method with the provided string and the color code “33” (for yellow).
Class Method Details
.colorize(string, code) ⇒ String
Wraps the provided string in colorizing tags to provide easier to view output to the client
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
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)
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.
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
11 12 13 |
# File 'lib/hirefire/logger.rb', line 11 def self.(string) puts loggify(string, :green) end |
.normal(string) ⇒ nil
Outputs the data as if it were a regular ‘puts’ command
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 |
.time ⇒ Time
Returns 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
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)
76 77 78 |
# File 'lib/hirefire/logger.rb', line 76 def self.yellow(string) colorize(string, 33) end |