Class: Ariel::Log
Overview
Very simple Log class. By default outputs to stdout and ignored messages below :info level. Should probably get rid of the usage of Singleton as it’s used very little, with the classes eigenclass/singleton class used mostly for the same purpose. Use Log.set_level to lower/raise the logging level.
Constant Summary collapse
- SEVERITY =
{:debug=>0, :info=>1, :warn=>2, :error=>3}
Class Method Summary collapse
- .current_level ⇒ Object
-
.log(message, level) ⇒ Object
Not intended to be used directly, preferred to use the methods corresponding to different serverity levels.
-
.output_to_file ⇒ Object
Sends all output to a file called debug.log in the current directory.
- .output_to_stdout ⇒ Object
-
.set_level(level) ⇒ Object
Set the log level to the given key from the SEVERITY constant.
Instance Method Summary collapse
-
#initialize ⇒ Log
constructor
Level defaults to :debug if $DEBUG is set and :info if not.
Constructor Details
#initialize ⇒ Log
Level defaults to :debug if $DEBUG is set and :info if not.
15 16 17 18 19 20 21 22 |
# File 'lib/ariel/log.rb', line 15 def initialize self.class.output_to_stdout if $DEBUG self.class.set_level :debug else self.class.set_level :info end end |
Class Method Details
.current_level ⇒ Object
38 39 40 |
# File 'lib/ariel/log.rb', line 38 def current_level @log_level end |
.log(message, level) ⇒ Object
Not intended to be used directly, preferred to use the methods corresponding to different serverity levels.
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ariel/log.rb', line 53 def log(, level) if SEVERITY[@log_level] <= SEVERITY[level] = "#{level}: #{}" if @output==:file File.open('debug.log', 'ab') {|f| f.puts } elsif @output==:stdout puts end return end return nil end |
.output_to_file ⇒ Object
Sends all output to a file called debug.log in the current directory.
47 48 49 |
# File 'lib/ariel/log.rb', line 47 def output_to_file @output=:file end |
.output_to_stdout ⇒ Object
42 43 44 |
# File 'lib/ariel/log.rb', line 42 def output_to_stdout @output=:stdout end |
.set_level(level) ⇒ Object
Set the log level to the given key from the SEVERITY constant.
30 31 32 33 34 35 36 |
# File 'lib/ariel/log.rb', line 30 def set_level(level) if SEVERITY.has_key? level @log_level=level else raise ArgumentError, "Invalid log level given" end end |