Class: Loops::Logger
- Inherits:
-
Delegator
- Object
- Delegator
- Loops::Logger
- Defined in:
- lib/loops/logger.rb
Defined Under Namespace
Classes: LoggerImplementation
Instance Attribute Summary collapse
-
#colorful_logs ⇒ Boolean
A value inidicating whether critical errors should be highlighted with ANSI colors in the log.
-
#write_to_console ⇒ Boolean
A value indicating whether all logging output should be also duplicated to the console.
Instance Method Summary collapse
-
#__getobj__ ⇒ Object
Send everything else to @implementation.
- #__setobj__(obj) ⇒ Object
-
#default_logfile=(logfile) ⇒ String, IO
Sets the default log file (see #logfile=).
-
#initialize(logfile = $stdout, level = ::Logger::INFO, number_of_files = 10, max_file_size = 100 * 1024 * 1024, write_to_console = false) ⇒ Logger
constructor
Initializes a new instance of the Logger class.
-
#level=(level) ⇒ Integer
Remember the level at the proxy level.
-
#logfile=(logfile) ⇒ String, IO
Sets the log file.
-
#method_missing(m, *args, &block) ⇒ Object
Delegator’s method_missing ignores the &block argument (!!!?).
Constructor Details
#initialize(logfile = $stdout, level = ::Logger::INFO, number_of_files = 10, max_file_size = 100 * 1024 * 1024, write_to_console = false) ⇒ Logger
Initializes a new instance of the Loops::Logger class.
33 34 35 36 37 38 39 |
# File 'lib/loops/logger.rb', line 33 def initialize(logfile = $stdout, level = ::Logger::INFO, number_of_files = 10, max_file_size = 100 * 1024 * 1024, write_to_console = false) @number_of_files, @level, @max_file_size, @write_to_console = number_of_files, level, max_file_size, write_to_console self.logfile = logfile super(@implementation) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
Delegator’s method_missing ignores the &block argument (!!!?)
138 139 140 141 142 143 144 145 |
# File 'lib/loops/logger.rb', line 138 def method_missing(m, *args, &block) target = self.__getobj__ unless target.respond_to?(m) super(m, *args, &block) else target.__send__(m, *args, &block) end end |
Instance Attribute Details
#colorful_logs ⇒ Boolean
Returns A value inidicating whether critical errors should be highlighted with ANSI colors in the log.
14 15 16 |
# File 'lib/loops/logger.rb', line 14 def colorful_logs @colorful_logs end |
#write_to_console ⇒ Boolean
Returns A value indicating whether all logging output should be also duplicated to the console.
9 10 11 |
# File 'lib/loops/logger.rb', line 9 def write_to_console @write_to_console end |
Instance Method Details
#__getobj__ ⇒ Object
Send everything else to @implementation.
128 129 130 |
# File 'lib/loops/logger.rb', line 128 def __getobj__ @implementation or raise "Logger implementation not initialized" end |
#__setobj__(obj) ⇒ Object
132 133 134 |
# File 'lib/loops/logger.rb', line 132 def __setobj__(obj) @implementation = obj end |
#default_logfile=(logfile) ⇒ String, IO
Sets the default log file (see #logfile=).
48 49 50 51 |
# File 'lib/loops/logger.rb', line 48 def default_logfile=(logfile) @default_logfile = logfile self.logfile = logfile end |
#level=(level) ⇒ Integer
Remember the level at the proxy level.
93 94 95 96 97 |
# File 'lib/loops/logger.rb', line 93 def level=(level) @level = level @implementation.level = @level if @implementation level end |
#logfile=(logfile) ⇒ String, IO
Sets the log file.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/loops/logger.rb', line 63 def logfile=(logfile) logfile = @default_logfile || $stdout if logfile == 'default' coerced_logfile = case logfile when 'stdout' then $stdout when 'stderr' then $stderr when IO, StringIO then logfile else if Loops.root logfile =~ /^\// ? logfile : Loops.root.join(logfile).to_s else logfile end end # Ensure logging directory does exist FileUtils.mkdir_p(File.dirname(coerced_logfile)) if String === coerced_logfile # Create a logger implementation. @implementation = LoggerImplementation.new(coerced_logfile, @number_of_files, @max_file_size, @write_to_console, @colorful_logs) @implementation.level = @level logfile end |