Class: YamlBot::LoggingBot
- Inherits:
-
Object
- Object
- YamlBot::LoggingBot
- Defined in:
- lib/yaml_bot/logging_bot.rb
Defined Under Namespace
Classes: LoggingError
Constant Summary collapse
- ESCAPES =
{ green: "\033[32m", yellow: "\033[33m", red: "\033[31m", reset: "\033[0m" }.freeze
- LOGLEVEL =
{ info: [:info, :warn, :error], warn: [:warn, :error], error: [:error] }.freeze
Instance Attribute Summary collapse
-
#log_file ⇒ Object
Returns the value of attribute log_file.
-
#log_level ⇒ Object
Returns the value of attribute log_level.
Instance Method Summary collapse
- #close_log ⇒ Object
- #error(message) ⇒ Object
- #info(message) ⇒ Object
-
#initialize(log_file, level: :info, no_color: false) ⇒ LoggingBot
constructor
A new instance of LoggingBot.
- #log(message, level) ⇒ Object
- #warn(message) ⇒ Object
Constructor Details
#initialize(log_file, level: :info, no_color: false) ⇒ LoggingBot
Returns a new instance of LoggingBot.
19 20 21 22 23 |
# File 'lib/yaml_bot/logging_bot.rb', line 19 def initialize(log_file, level: :info, no_color: false) @log_file = log_file @log_level = level.to_sym unless valid_log_level(level) @no_color = no_color end |
Instance Attribute Details
#log_file ⇒ Object
Returns the value of attribute log_file.
17 18 19 |
# File 'lib/yaml_bot/logging_bot.rb', line 17 def log_file @log_file end |
#log_level ⇒ Object
Returns the value of attribute log_level.
17 18 19 |
# File 'lib/yaml_bot/logging_bot.rb', line 17 def log_level @log_level end |
Instance Method Details
#close_log ⇒ Object
45 46 47 |
# File 'lib/yaml_bot/logging_bot.rb', line 45 def close_log log_file.close end |
#error(message) ⇒ Object
35 36 37 38 |
# File 'lib/yaml_bot/logging_bot.rb', line 35 def error() log(, :error) emit(message: , color: :red) end |
#info(message) ⇒ Object
25 26 27 28 |
# File 'lib/yaml_bot/logging_bot.rb', line 25 def info() log(, :info) emit(message: , color: :green) end |
#log(message, level) ⇒ Object
40 41 42 43 |
# File 'lib/yaml_bot/logging_bot.rb', line 40 def log(, level) = level.to_s.upcase + ': ' + + "\n" log_file.write() if LOGLEVEL[log_level].include?(level) end |
#warn(message) ⇒ Object
30 31 32 33 |
# File 'lib/yaml_bot/logging_bot.rb', line 30 def warn() log(, :warn) emit(message: , color: :yellow) end |