Class: Perennial::Logger
Constant Summary collapse
- LEVELS =
{ :fatal => 7, :error => 6, :warn => 4, :info => 3, :debug => 0 }
- PREFIXES =
{}
- COLOURS =
{ :fatal => 31, # red :error => 33, # yellow :warn => 35, # magenta :info => 32, # green :debug => 34 # white }
- @@log_name =
"perennial.log"- @@setup =
false
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#level ⇒ Object
Returns the value of attribute level.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Class Method Summary collapse
- .method_missing(name, *args, &blk) ⇒ Object
- .respond_to?(symbol, include_private = false) ⇒ Boolean
- .setup ⇒ Object
- .setup! ⇒ Object
- .setup? ⇒ Boolean
Instance Method Summary collapse
- #close! ⇒ Object
-
#initialize(path, level = :info, verbose = Settings.verbose?) ⇒ Logger
constructor
A new instance of Logger.
- #log_exception(exception) ⇒ Object
- #verbose? ⇒ Boolean
Constructor Details
#initialize(path, level = :info, verbose = Settings.verbose?) ⇒ Logger
Returns a new instance of Logger.
62 63 64 65 66 67 |
# File 'lib/perennial/logger.rb', line 62 def initialize(path, level = :info, verbose = Settings.verbose?) @level = level.to_sym @verbose = verbose FileUtils.mkdir_p(File.dirname(path)) @file = File.open(path, "a+") end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
60 61 62 |
# File 'lib/perennial/logger.rb', line 60 def file @file end |
#level ⇒ Object
Returns the value of attribute level.
60 61 62 |
# File 'lib/perennial/logger.rb', line 60 def level @level end |
#verbose ⇒ Object
Returns the value of attribute verbose.
60 61 62 |
# File 'lib/perennial/logger.rb', line 60 def verbose @verbose end |
Class Method Details
.method_missing(name, *args, &blk) ⇒ Object
28 29 30 31 |
# File 'lib/perennial/logger.rb', line 28 def method_missing(name, *args, &blk) self.setup # Ensure the logger is setup @@logger.send(name, *args, &blk) end |
.respond_to?(symbol, include_private = false) ⇒ Boolean
33 34 35 36 |
# File 'lib/perennial/logger.rb', line 33 def respond_to?(symbol, include_private = false) self.setup super(symbol, include_private) || @@logger.respond_to?(symbol, include_private) end |
.setup ⇒ Object
17 18 19 20 |
# File 'lib/perennial/logger.rb', line 17 def setup return if setup? setup! end |
.setup! ⇒ Object
22 23 24 25 26 |
# File 'lib/perennial/logger.rb', line 22 def setup! log_path = Settings.root / "log" / @@log_name.to_str @@logger = new(log_path, Settings.log_level, Settings.verbose?) @@setup = true end |
.setup? ⇒ Boolean
13 14 15 |
# File 'lib/perennial/logger.rb', line 13 def setup? !!@@setup end |
Instance Method Details
#close! ⇒ Object
69 70 71 |
# File 'lib/perennial/logger.rb', line 69 def close! @file.close end |
#log_exception(exception) ⇒ Object
84 85 86 87 88 89 |
# File 'lib/perennial/logger.rb', line 84 def log_exception(exception) error "Exception: #{exception}" exception.backtrace.each do |l| error ">> #{l}" end end |
#verbose? ⇒ Boolean
91 92 93 |
# File 'lib/perennial/logger.rb', line 91 def verbose? !!@verbose end |