Class: Ramaze::Logger::RotatingInformer
- Inherits:
-
Object
- Object
- Ramaze::Logger::RotatingInformer
- Includes:
- Innate::Traited, Ramaze::Logging
- Defined in:
- lib/ramaze/log/rotatinginformer.rb
Overview
A customized logger (based on Informer) that creates multiple log files based on current date.
Instance Attribute Summary (collapse)
-
- (Object) base_dir
Returns the value of attribute base_dir.
-
- (Object) log_levels
Returns the value of attribute log_levels.
-
- (Object) time_format
Returns the value of attribute time_format.
Instance Method Summary (collapse)
-
- (Boolean) closed?
Is @out closed?.
-
- (RotatingInformer) initialize(base_dir, time_format = '%Y-%m-%d.log', log_levels = [:debug, :error, :info, :warn])
constructor
Create a new instance of RotatingInformer.
-
- (Object) log(tag, *messages)
Integration to Logging.
-
- (Object) log_interpolate(prefix, text, time = timestamp)
Takes the prefix (tag), text and timestamp and applies it to the :format trait.
-
- (Object) shutdown
Close the file we log to if it isn't closed already.
-
- (Object) timestamp
This uses timestamp trait or a date in the format of.
-
- (Object) write(message)
Method that is called by Rack::CommonLogger when logging data to a file.
Methods included from Ramaze::Logging
#debug, #debug?, #dev, #error, #info, #tag_log, #warn
Constructor Details
- (RotatingInformer) initialize(base_dir, time_format = '%Y-%m-%d.log', log_levels = [:debug, :error, :info, :warn])
Create a new instance of RotatingInformer.
base_dir is the directory where all log files will be stored
time_format is the time format used to name the log files. Possible formats are identical to those accepted by Time.strftime
log_levelse is an array describing what kind of messages that the log receives. The array may contain any or all of the symbols :debug, :error, :info and/or :warn
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ramaze/log/rotatinginformer.rb', line 54 def initialize(base_dir, time_format = '%Y-%m-%d.log', log_levels = [:debug, :error, :info, :warn]) # Verify and set base directory send :base_dir=, base_dir, true @time_format = time_format @log_levels = log_levels # Keep track of log shutdown (to prevent StackErrors due to recursion) @in_shutdown = false end |
Instance Attribute Details
- (Object) base_dir
Returns the value of attribute base_dir
14 15 16 |
# File 'lib/ramaze/log/rotatinginformer.rb', line 14 def base_dir @base_dir end |
- (Object) log_levels
Returns the value of attribute log_levels
13 14 15 |
# File 'lib/ramaze/log/rotatinginformer.rb', line 13 def log_levels @log_levels end |
- (Object) time_format
Returns the value of attribute time_format
13 14 15 |
# File 'lib/ramaze/log/rotatinginformer.rb', line 13 def time_format @time_format end |
Instance Method Details
- (Boolean) closed?
Is @out closed?
169 170 171 |
# File 'lib/ramaze/log/rotatinginformer.rb', line 169 def closed? @out.respond_to?(:closed?) && @out.closed? end |
- (Object) log(tag, *messages)
Integration to Logging.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/ramaze/log/rotatinginformer.rb', line 122 def log tag, * return unless @log_levels.include?(tag) # Update current log update_current_log .flatten! prefix = tag.to_s.upcase.ljust(5) .each do || @out.puts(log_interpolate(prefix, )) end @out.flush if @out.respond_to?(:flush) end |
- (Object) log_interpolate(prefix, text, time = timestamp)
Takes the prefix (tag), text and timestamp and applies it to the :format trait.
147 148 149 150 151 152 153 154 |
# File 'lib/ramaze/log/rotatinginformer.rb', line 147 def log_interpolate prefix, text, time = = class_trait[:format].dup vars = { '%time' => time, '%prefix' => prefix, '%text' => text } vars.each{|from, to| .gsub!(from, to) } end |
- (Object) shutdown
Close the file we log to if it isn't closed already.
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/ramaze/log/rotatinginformer.rb', line 105 def shutdown if @out.respond_to?(:close) unless @in_shutdown @in_shutdown = true Log.debug("close, #{@out.inspect}") @in_shutdown = false end @out.close end end |
- (Object) timestamp
This uses timestamp trait or a date in the format of
%Y-%m-%d %H:%M:%S
# => "2007-01-19 21:09:32"
161 162 163 164 |
# File 'lib/ramaze/log/rotatinginformer.rb', line 161 def mask = class_trait[:timestamp] Time.now.strftime(mask || "%Y-%m-%d %H:%M:%S") end |
- (Object) write(message)
Method that is called by Rack::CommonLogger when logging data to a file.
179 180 181 |
# File 'lib/ramaze/log/rotatinginformer.rb', line 179 def write log(:info, ) end |