Class: Bridgetown::LogWriter
- Inherits:
-
Logger
- Object
- Logger
- Bridgetown::LogWriter
- Defined in:
- bridgetown-core/lib/bridgetown-core/log_writer.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#add(severity, message = nil, progname = nil) ⇒ Object
-
#close ⇒ Object
-
#enable_prefix ⇒ Object
-
#error(progname = nil) ⇒ Object
Log an
ERROR
message. -
#initialize ⇒ LogWriter
constructor
A new instance of LogWriter.
-
#warn(progname = nil) ⇒ Object
Log a
WARN
message.
Constructor Details
#initialize ⇒ LogWriter
Returns a new instance of LogWriter.
5 6 7 |
# File 'bridgetown-core/lib/bridgetown-core/log_writer.rb', line 5 def initialize super($stdout, formatter: proc { |_, _, _, msg| msg.to_s }) end |
Instance Method Details
#add(severity, message = nil, progname = nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'bridgetown-core/lib/bridgetown-core/log_writer.rb', line 15 def add(severity, = nil, progname = nil) severity ||= UNKNOWN @logdev = logdevice(severity) return true if @logdev.nil? || severity < @level progname ||= @progname if .nil? if block_given? = yield else = progname progname = @progname end end @logdev.puts( (format_severity(severity), Time.now, progname, ) ) true end |
#close ⇒ Object
46 47 48 |
# File 'bridgetown-core/lib/bridgetown-core/log_writer.rb', line 46 def close # No LogDevice in use end |
#enable_prefix ⇒ Object
9 10 11 12 13 |
# File 'bridgetown-core/lib/bridgetown-core/log_writer.rb', line 9 def enable_prefix self.formatter = proc do |_, _, _, msg| "\e[32m[Bridgetown]\e[0m #{msg}" end end |
#error(progname = nil) ⇒ Object
Log an ERROR
message
42 43 44 |
# File 'bridgetown-core/lib/bridgetown-core/log_writer.rb', line 42 def error(progname = nil, &) add(ERROR, nil, progname.red, &) end |
#warn(progname = nil) ⇒ Object
Log a WARN
message
37 38 39 |
# File 'bridgetown-core/lib/bridgetown-core/log_writer.rb', line 37 def warn(progname = nil, &) add(WARN, nil, progname.yellow, &) end |