Class: TTY::Logger
Overview
A class providing logging system
Constant Summary collapse
- ALL =
0
- INFO =
1
- DEBUG =
2
- WARN =
3
- ERROR =
4
- FATAL =
5
- OFF =
6
- MAX_LEVELS =
7
Instance Attribute Summary collapse
-
#level ⇒ Object
Returns the value of attribute level.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#timestamp_format ⇒ Object
readonly
Returns the value of attribute timestamp_format.
Attributes included from Equatable
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Logger
constructor
Initialize a Logger.
-
#log(message) ⇒ Object
Print formatted log to output.
- #timestamp ⇒ Object
- #validate_level(level) ⇒ Object
Methods included from Equatable
#attr_reader, included, #inherited
Constructor Details
#initialize(options = {}) ⇒ Logger
Initialize a Logger
36 37 38 39 40 41 |
# File 'lib/tty/logger.rb', line 36 def initialize(={}) @namespace = .fetch(:namespace) { raise ArgumentError, "Logger must have namespace", caller } @output = .fetch(:output) { $stderr } @level = .fetch(:level) { ALL } @timestamp_format = .fetch(:timestamp_format) { '%Y-%m-%d %T' } end |
Instance Attribute Details
#level ⇒ Object
Returns the value of attribute level.
21 22 23 |
# File 'lib/tty/logger.rb', line 21 def level @level end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
19 20 21 |
# File 'lib/tty/logger.rb', line 19 def namespace @namespace end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
23 24 25 |
# File 'lib/tty/logger.rb', line 23 def output @output end |
#timestamp_format ⇒ Object (readonly)
Returns the value of attribute timestamp_format.
25 26 27 |
# File 'lib/tty/logger.rb', line 25 def @timestamp_format end |
Class Method Details
Instance Method Details
#log(message) ⇒ Object
Print formatted log to output
66 67 68 |
# File 'lib/tty/logger.rb', line 66 def log() output.print + ' - ' + end |
#timestamp ⇒ Object
49 50 51 |
# File 'lib/tty/logger.rb', line 49 def Time.now.strftime() end |
#validate_level(level) ⇒ Object
53 54 55 56 57 |
# File 'lib/tty/logger.rb', line 53 def validate_level(level) unless valid_level?(level) raise ArgumentError, "Log level must be 0..#{MAX_LEVELS}", caller end end |