Class: Siding::Logger
- Inherits:
-
Object
- Object
- Siding::Logger
- Defined in:
- lib/siding/logger.rb
Defined Under Namespace
Classes: Event
Constant Summary collapse
- TERMINAL =
"/dev/tty"- OFF_VALUES =
["0", "false", "no", "off", ""].freeze
Instance Attribute Summary collapse
-
#events ⇒ Object
readonly
Returns the value of attribute events.
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
- #debug(message) ⇒ Object
-
#initialize(env: ENV, log_path: nil) ⇒ Logger
constructor
A new instance of Logger.
- #notice(message) ⇒ Object
- #record(level, message) ⇒ Object
- #terminal_available? ⇒ Boolean
- #verbose? ⇒ Boolean
Constructor Details
#initialize(env: ENV, log_path: nil) ⇒ Logger
Returns a new instance of Logger.
12 13 14 15 16 17 |
# File 'lib/siding/logger.rb', line 12 def initialize(env: ENV, log_path: nil) @verbose = self.class.verbose?(env) @log_path = log_path @events = [] @terminal = :unopened end |
Instance Attribute Details
#events ⇒ Object (readonly)
Returns the value of attribute events.
10 11 12 |
# File 'lib/siding/logger.rb', line 10 def events @events end |
Class Method Details
.verbose?(env) ⇒ Boolean
19 20 21 22 23 24 |
# File 'lib/siding/logger.rb', line 19 def self.verbose?(env) value = env["SIDING_LOG"] return false if value.nil? !OFF_VALUES.include?(value.strip.downcase) end |
Instance Method Details
#close ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/siding/logger.rb', line 46 def close @terminal.close if @terminal.is_a?(IO) && !@terminal.closed? rescue IOError, SystemCallError nil ensure @terminal = nil end |
#debug(message) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/siding/logger.rb', line 33 def debug() return unless verbose? record(:debug, ) write_to_terminal() || write_to_log() end |
#notice(message) ⇒ Object
28 29 30 31 |
# File 'lib/siding/logger.rb', line 28 def notice() record(:notice, ) write_to_terminal() end |
#record(level, message) ⇒ Object
40 41 42 |
# File 'lib/siding/logger.rb', line 40 def record(level, ) @events << Event.new(at: Time.now, level: level, message: ) end |
#terminal_available? ⇒ Boolean
44 |
# File 'lib/siding/logger.rb', line 44 def terminal_available? = !terminal.nil? |
#verbose? ⇒ Boolean
26 |
# File 'lib/siding/logger.rb', line 26 def verbose? = @verbose |