Class: Slugforge::Logger
- Inherits:
-
Object
- Object
- Slugforge::Logger
- Defined in:
- lib/slugforge/models/logger.rb
Instance Method Summary collapse
-
#initialize(thor_shell, log_level = :info) ⇒ Logger
constructor
A new instance of Logger.
- #log(message = "", opts = {}) ⇒ Object
- #say(message = "", color = nil, force_new_line = (message.to_s !~ /( |\t)\z/)) ⇒ Object
- #say_json(message) ⇒ Object
- #say_status(status, message, log_status = true) ⇒ Object
Constructor Details
#initialize(thor_shell, log_level = :info) ⇒ Logger
Returns a new instance of Logger.
3 4 5 6 |
# File 'lib/slugforge/models/logger.rb', line 3 def initialize(thor_shell, log_level = :info) @thor_shell = thor_shell @log_level = log_level end |
Instance Method Details
#log(message = "", opts = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/slugforge/models/logger.rb', line 8 def log(="", opts={}) return if @log_level != :verbose && opts[:log_level] == :verbose if opts[:status] say_status opts[:status], , opts[:color] else if opts[:force_new_line] say , opts[:color], true else say , opts[:color] end end end |
#say(message = "", color = nil, force_new_line = (message.to_s !~ /( |\t)\z/)) ⇒ Object
21 22 23 24 |
# File 'lib/slugforge/models/logger.rb', line 21 def say(="", color=nil, force_new_line=(.to_s !~ /( |\t)\z/)) return if [:quiet, :json].include?(@log_level) @thor_shell.say , color, force_new_line end |
#say_json(message) ⇒ Object
31 32 33 34 |
# File 'lib/slugforge/models/logger.rb', line 31 def say_json() return unless @log_level == :json @thor_shell.say .to_json end |
#say_status(status, message, log_status = true) ⇒ Object
26 27 28 29 |
# File 'lib/slugforge/models/logger.rb', line 26 def say_status(status, , log_status=true) return if [:quiet, :json].include?(@log_level) @thor_shell.say_status status, , log_status end |