Class: Perennial::Logger
Constant Summary collapse
- LEVELS =
{ :fatal => 7, :error => 6, :warn => 4, :info => 3, :debug => 0 }
- PREFIXES =
{}
- COLOURS =
{ :fatal => "red", :error => "yellow", :warn => "magenta", :info => "green", :debug => "blue" }
- @@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
- .warn(message) ⇒ Object
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.
77 78 79 80 81 82 83 |
# File 'lib/perennial/logger.rb', line 77 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+") @file.sync = true if @file.respond_to?(:sync=) end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
75 76 77 |
# File 'lib/perennial/logger.rb', line 75 def file @file end |
#level ⇒ Object
Returns the value of attribute level.
75 76 77 |
# File 'lib/perennial/logger.rb', line 75 def level @level end |
#verbose ⇒ Object
Returns the value of attribute verbose.
75 76 77 |
# File 'lib/perennial/logger.rb', line 75 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
48 49 50 51 |
# File 'lib/perennial/logger.rb', line 48 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 |
.warn(message) ⇒ Object
43 44 45 46 |
# File 'lib/perennial/logger.rb', line 43 def warn() self.setup @@logger.warn() end |
Instance Method Details
#close! ⇒ Object
85 86 87 |
# File 'lib/perennial/logger.rb', line 85 def close! @file.close end |
#log_exception(exception) ⇒ Object
100 101 102 103 104 105 |
# File 'lib/perennial/logger.rb', line 100 def log_exception(exception) error "Exception: #{exception}" exception.backtrace.each do |l| error ">> #{l}" end end |
#verbose? ⇒ Boolean
107 108 109 |
# File 'lib/perennial/logger.rb', line 107 def verbose? !!@verbose end |