From fd279e47f44bf3ba7f4046cb7edf9baa047cca10 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 27 Sep 2011 15:58:42 -0400 Subject: [PATCH] collect where logs are put, for later use --- lib/apache/config.rb | 4 ++++ lib/apache/logging.rb | 19 +++++++++++++++++-- spec/apache/logging_spec.rb | 2 ++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/apache/config.rb b/lib/apache/config.rb index 642ec22..915cca9 100644 --- a/lib/apache/config.rb +++ b/lib/apache/config.rb @@ -120,6 +120,10 @@ module Apache @line_indent = 0 @is_disabled = 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 # Indent the string by the current @line_indent level diff --git a/lib/apache/logging.rb b/lib/apache/logging.rb index 125a1a4..368b4ac 100644 --- a/lib/apache/logging.rb +++ b/lib/apache/logging.rb @@ -16,19 +16,32 @@ module Apache # Both variations check to make sure the log file diretory exists during generation. # The rotate_ variations need @rotate_logs_path set to work. module Logging + class << self + def log_paths + @log_paths ||= {} + end + + def reset! + @log_paths = {} + end + end + [ :custom, :error, :script, :rewrite ].each do |type| class_eval <<-EOT def #{type}_log(*opts) handle_log :tag => '#{type.to_s.capitalize}Log', :path => opts.first, - :additional_options => opts[1..-1] + :additional_options => opts[1..-1], + :type => :#{type} end def rotate_#{type}_log(*opts) handle_log :tag => '#{type.to_s.capitalize}Log', :path => opts.first, :real_path => rotatelogs(*opts[0..1]), - :additional_options => opts[2..-1] + :additional_options => opts[2..-1], + :type => :#{type} + end EOT end @@ -47,6 +60,8 @@ module Apache real_path = (info[:real_path] || path).quoteize + (Apache::Logging.log_paths[info[:type]] ||= []) << path + self << "#{info[:tag]} #{[real_path, info[:additional_options]].flatten * " "}" end end diff --git a/spec/apache/logging_spec.rb b/spec/apache/logging_spec.rb index 95333d5..5450105 100644 --- a/spec/apache/logging_spec.rb +++ b/spec/apache/logging_spec.rb @@ -11,10 +11,12 @@ describe Apache::Config, "logging directives" do apache.reset! apache.send("#{type}_log".to_sym, 'test', 'test2') apache.to_a.should == [ %{#{type.to_s.capitalize}Log "test" test2} ] + Apache::Logging.log_paths[type].should == [ "test" ] apache.reset! 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::Logging.log_paths[type].should == [ "test" ] end end