Class: Hookit::Logger
- Inherits:
-
Object
- Object
- Hookit::Logger
- Defined in:
- lib/hookit/logger.rb
Instance Attribute Summary collapse
-
#log_file ⇒ Object
readonly
Returns the value of attribute log_file.
-
#log_level ⇒ Object
readonly
Returns the value of attribute log_level.
Instance Method Summary collapse
- #debug(message) ⇒ Object
- #error(message) ⇒ Object
- #info(message) ⇒ Object
-
#initialize(file, level) ⇒ Logger
constructor
A new instance of Logger.
- #log(level, message) ⇒ Object
- #warn(message) ⇒ Object
Constructor Details
#initialize(file, level) ⇒ Logger
Returns a new instance of Logger.
7 8 9 10 11 |
# File 'lib/hookit/logger.rb', line 7 def initialize(file, level) @log_file = file || '/var/log/hookit/hookit.log' @log_level = level || :error ::FileUtils.mkdir_p(File.dirname(@log_file)) end |
Instance Attribute Details
#log_file ⇒ Object (readonly)
Returns the value of attribute log_file.
5 6 7 |
# File 'lib/hookit/logger.rb', line 5 def log_file @log_file end |
#log_level ⇒ Object (readonly)
Returns the value of attribute log_level.
5 6 7 |
# File 'lib/hookit/logger.rb', line 5 def log_level @log_level end |
Instance Method Details
#debug(message) ⇒ Object
38 39 40 |
# File 'lib/hookit/logger.rb', line 38 def debug() log! "[debug]: #{}\n" end |
#error(message) ⇒ Object
26 27 28 |
# File 'lib/hookit/logger.rb', line 26 def error() log! "[error]: #{}\n" end |
#info(message) ⇒ Object
34 35 36 |
# File 'lib/hookit/logger.rb', line 34 def info() log! "[info]: #{}\n" end |
#log(level, message) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/hookit/logger.rb', line 13 def log(level, ) if not = level level = :error end if level_to_int(level) <= level_to_int(log_level) send(level, ) end end |
#warn(message) ⇒ Object
30 31 32 |
# File 'lib/hookit/logger.rb', line 30 def warn() log! "[warn]: #{}\n" end |