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- @@default_logger_path =
nil
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
- .default_logger_path ⇒ Object
- .default_logger_path=(value) ⇒ Object
- .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.
72 73 74 75 76 77 |
# File 'lib/perennial/logger.rb', line 72 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.
70 71 72 |
# File 'lib/perennial/logger.rb', line 70 def file @file end |
#level ⇒ Object
Returns the value of attribute level.
70 71 72 |
# File 'lib/perennial/logger.rb', line 70 def level @level end |
#verbose ⇒ Object
Returns the value of attribute verbose.
70 71 72 |
# File 'lib/perennial/logger.rb', line 70 def verbose @verbose end |
Class Method Details
.default_logger_path ⇒ Object
29 30 31 |
# File 'lib/perennial/logger.rb', line 29 def default_logger_path @@default_logger_path || (Settings.root / "log" / @@log_name.to_str) end |
.default_logger_path=(value) ⇒ Object
23 24 25 26 27 |
# File 'lib/perennial/logger.rb', line 23 def default_logger_path=(value) @@default_logger_path = value # Rereun setup if setup is already done. setup! if setup? end |
.method_missing(name, *args, &blk) ⇒ Object
38 39 40 41 |
# File 'lib/perennial/logger.rb', line 38 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
43 44 45 46 |
# File 'lib/perennial/logger.rb', line 43 def respond_to?(symbol, include_private = false) self.setup super(symbol, include_private) || @@logger.respond_to?(symbol, include_private) end |
.setup ⇒ Object
18 19 20 21 |
# File 'lib/perennial/logger.rb', line 18 def setup return if setup? setup! end |
.setup! ⇒ Object
33 34 35 36 |
# File 'lib/perennial/logger.rb', line 33 def setup! @@logger = new(self.default_logger_path, Settings.log_level, Settings.verbose?) @@setup = true end |
.setup? ⇒ Boolean
14 15 16 |
# File 'lib/perennial/logger.rb', line 14 def setup? !!@@setup end |
Instance Method Details
#close! ⇒ Object
79 80 81 |
# File 'lib/perennial/logger.rb', line 79 def close! @file.close end |
#log_exception(exception) ⇒ Object
94 95 96 97 98 99 |
# File 'lib/perennial/logger.rb', line 94 def log_exception(exception) error "Exception: #{exception}" exception.backtrace.each do |l| error ">> #{l}" end end |
#verbose? ⇒ Boolean
101 102 103 |
# File 'lib/perennial/logger.rb', line 101 def verbose? !!@verbose end |