Class: Compass::Logger
- Inherits:
-
Object
- Object
- Compass::Logger
- Defined in:
- lib/compass/logger.rb
Constant Summary collapse
- DEFAULT_ACTIONS =
[:directory, :exists, :remove, :create, :overwrite, :compile, :error, :identical]
- ACTION_COLORS =
{ :error => :red, :compile => :green, :overwrite => :yellow, :create => :green, :remove => :yellow, :exists => :green, :directory => :green, :identical => :green }
- COLORS =
{ :clear => 0, :red => 31, :green => 32, :yellow => 33 }
Instance Attribute Summary collapse
-
#actions ⇒ Object
Returns the value of attribute actions.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#action_padding(action) ⇒ Object
add padding to the left of an action that was performed.
- #color(c) ⇒ Object
- #emit(msg) ⇒ Object
-
#initialize(*actions) ⇒ Logger
constructor
A new instance of Logger.
-
#log(msg) ⇒ Object
Emit a log message.
-
#max_action_length ⇒ Object
the maximum length of all the actions known to the logger.
-
#record(action, *arguments) ⇒ Object
Record an action that has occurred.
Constructor Details
#initialize(*actions) ⇒ Logger
Returns a new instance of Logger.
21 22 23 24 25 |
# File 'lib/compass/logger.rb', line 21 def initialize(*actions) self. = actions.last.is_a?(Hash) ? actions.pop : {} @actions = DEFAULT_ACTIONS.dup @actions += actions end |
Instance Attribute Details
#actions ⇒ Object
Returns the value of attribute actions.
19 20 21 |
# File 'lib/compass/logger.rb', line 19 def actions @actions end |
#options ⇒ Object
Returns the value of attribute options.
19 20 21 |
# File 'lib/compass/logger.rb', line 19 def @options end |
Instance Method Details
#action_padding(action) ⇒ Object
add padding to the left of an action that was performed.
51 52 53 |
# File 'lib/compass/logger.rb', line 51 def action_padding(action) ' ' * [(max_action_length - action.to_s.length), 0].max end |
#color(c) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/compass/logger.rb', line 34 def color(c) if c && COLORS.has_key?(c.to_sym) "\e[#{COLORS[c.to_sym]}m" else "" end end |
#emit(msg) ⇒ Object
42 43 44 |
# File 'lib/compass/logger.rb', line 42 def emit(msg) print msg end |
#log(msg) ⇒ Object
Emit a log message
46 47 48 |
# File 'lib/compass/logger.rb', line 46 def log(msg) puts msg end |
#max_action_length ⇒ Object
the maximum length of all the actions known to the logger.
56 57 58 |
# File 'lib/compass/logger.rb', line 56 def max_action_length @max_action_length ||= actions.inject(0){|memo, a| [memo, a.to_s.length].max} end |
#record(action, *arguments) ⇒ Object
Record an action that has occurred
28 29 30 31 32 |
# File 'lib/compass/logger.rb', line 28 def record(action, *arguments) emit color(ACTION_COLORS[action]) if Compass.configuration.color_output log "#{action_padding(action)}#{action} #{arguments.join(' ')}" emit color(:clear) if Compass.configuration.color_output end |