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
- .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.
71 72 73 74 75 76 |
# File 'lib/perennial/logger.rb', line 71 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.
69 70 71 |
# File 'lib/perennial/logger.rb', line 69 def file @file end |
#level ⇒ Object
Returns the value of attribute level.
69 70 71 |
# File 'lib/perennial/logger.rb', line 69 def level @level end |
#verbose ⇒ Object
Returns the value of attribute verbose.
69 70 71 |
# File 'lib/perennial/logger.rb', line 69 def verbose @verbose end |
Class Method Details
.default_logger_path ⇒ Object
28 29 30 |
# File 'lib/perennial/logger.rb', line 28 def default_logger_path @@default_logger_path ||= (Settings.root / "log" / @@log_name.to_str) end |
.default_logger_path=(value) ⇒ Object
22 23 24 25 26 |
# File 'lib/perennial/logger.rb', line 22 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
37 38 39 40 |
# File 'lib/perennial/logger.rb', line 37 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
42 43 44 45 |
# File 'lib/perennial/logger.rb', line 42 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
32 33 34 35 |
# File 'lib/perennial/logger.rb', line 32 def setup! @@logger = new(self.default_logger_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
78 79 80 |
# File 'lib/perennial/logger.rb', line 78 def close! @file.close end |
#log_exception(exception) ⇒ Object
93 94 95 96 97 98 |
# File 'lib/perennial/logger.rb', line 93 def log_exception(exception) error "Exception: #{exception}" exception.backtrace.each do |l| error ">> #{l}" end end |
#verbose? ⇒ Boolean
100 101 102 |
# File 'lib/perennial/logger.rb', line 100 def verbose? !!@verbose end |