Module: Confiner::Logger
Class Method Summary collapse
-
.log_to ⇒ Object
Where to output the log.
- .log_to=(file) ⇒ Object
Instance Method Summary collapse
-
#log(level, message, indentation = 1) ⇒ Object
Log something with a specific level.
- #run(action) ⇒ Object
Class Method Details
.log_to ⇒ Object
Where to output the log
19 20 21 |
# File 'lib/confiner/logger.rb', line 19 def self.log_to @out_file end |
.log_to=(file) ⇒ Object
23 24 25 26 27 |
# File 'lib/confiner/logger.rb', line 23 def self.log_to=(file) file = File.open(file.strip, 'a+t') if file.is_a?(String) @out_file = file end |
Instance Method Details
#log(level, message, indentation = 1) ⇒ Object
Log something with a specific level
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/confiner/logger.rb', line 6 def log(level, , indentation = 1) color = "\e[0;35m" # default purple color = "\e[0;33m" if %i[warn warning].include?(level) # yellow color = "\e[0;31m" if %i[err error fatal].include?(level) # red raise ArgumentError, 'Level must be less than 12 characters' if level.size > 12 output = "(#{Time.now.strftime('%F %H:%M:%S')})\t#{color}#{level.to_s.upcase}#{' ' * (12 - level.size)}\e[m#{"\t" * indentation}#{}" Logger.log_to.puts(output) end |
#run(action) ⇒ Object
29 30 31 32 33 |
# File 'lib/confiner/logger.rb', line 29 def run(action) log :plugin, "#{self.class}##{action}" super log :plugin, "#{self.class}##{action} Done" end |