collect where logs are put, for later use

This commit is contained in:
John Bintz 2011-09-27 15:58:42 -04:00
parent dfe3e6784b
commit fd279e47f4
3 changed files with 23 additions and 2 deletions

View File

@ -120,6 +120,10 @@ module Apache
@line_indent = 0 @line_indent = 0
@is_disabled = false @is_disabled = false
@was_written = false @was_written = false
Apache.constants.collect { |c| Apache.const_get(c) }.find_all { |c| c != Apache::Config && c.kind_of?(Module) }.each do |mod|
mod.reset! if mod.respond_to?(:reset!)
end
end end
# Indent the string by the current @line_indent level # Indent the string by the current @line_indent level

View File

@ -16,19 +16,32 @@ module Apache
# Both variations check to make sure the log file diretory exists during generation. # Both variations check to make sure the log file diretory exists during generation.
# The rotate_ variations need @rotate_logs_path set to work. # The rotate_ variations need @rotate_logs_path set to work.
module Logging module Logging
class << self
def log_paths
@log_paths ||= {}
end
def reset!
@log_paths = {}
end
end
[ :custom, :error, :script, :rewrite ].each do |type| [ :custom, :error, :script, :rewrite ].each do |type|
class_eval <<-EOT class_eval <<-EOT
def #{type}_log(*opts) def #{type}_log(*opts)
handle_log :tag => '#{type.to_s.capitalize}Log', handle_log :tag => '#{type.to_s.capitalize}Log',
:path => opts.first, :path => opts.first,
:additional_options => opts[1..-1] :additional_options => opts[1..-1],
:type => :#{type}
end end
def rotate_#{type}_log(*opts) def rotate_#{type}_log(*opts)
handle_log :tag => '#{type.to_s.capitalize}Log', handle_log :tag => '#{type.to_s.capitalize}Log',
:path => opts.first, :path => opts.first,
:real_path => rotatelogs(*opts[0..1]), :real_path => rotatelogs(*opts[0..1]),
:additional_options => opts[2..-1] :additional_options => opts[2..-1],
:type => :#{type}
end end
EOT EOT
end end
@ -47,6 +60,8 @@ module Apache
real_path = (info[:real_path] || path).quoteize real_path = (info[:real_path] || path).quoteize
(Apache::Logging.log_paths[info[:type]] ||= []) << path
self << "#{info[:tag]} #{[real_path, info[:additional_options]].flatten * " "}" self << "#{info[:tag]} #{[real_path, info[:additional_options]].flatten * " "}"
end end
end end

View File

@ -11,10 +11,12 @@ describe Apache::Config, "logging directives" do
apache.reset! apache.reset!
apache.send("#{type}_log".to_sym, 'test', 'test2') apache.send("#{type}_log".to_sym, 'test', 'test2')
apache.to_a.should == [ %{#{type.to_s.capitalize}Log "test" test2} ] apache.to_a.should == [ %{#{type.to_s.capitalize}Log "test" test2} ]
Apache::Logging.log_paths[type].should == [ "test" ]
apache.reset! apache.reset!
apache.send("rotate_#{type}_log".to_sym, 'test', 86400, 'test2') apache.send("rotate_#{type}_log".to_sym, 'test', 86400, 'test2')
apache.to_a.should == [ %{#{type.to_s.capitalize}Log "|/path/to/rotatelogs test 86400" test2} ] apache.to_a.should == [ %{#{type.to_s.capitalize}Log "|/path/to/rotatelogs test 86400" test2} ]
Apache::Logging.log_paths[type].should == [ "test" ]
end end
end end