From c99ca26a8d14c8f0a91c9e11363bc2bad0d131de Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Wed, 28 Oct 2009 00:03:25 -0500 Subject: [PATCH] Better log rotation for Passenger Touch the tmp/restart.txt file, when rotatingthe log files. Otherwise, multiple workers may try to rotate the log files at the same time, with sub-optimal results. Also, an aesthetic tweak to the url_generator. --- config/environment.rb | 1 + lib/logging_stuff.rb | 20 ++++++++++++++++++++ lib/url_generator.rb | 2 +- 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 lib/logging_stuff.rb diff --git a/config/environment.rb b/config/environment.rb index bb0bef2f..fa8aa4c4 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -59,6 +59,7 @@ require_dependency 'instiki_errors' #require 'jcode' require 'caching_stuff' +require 'logging_stuff' #Additional Mime-types mime_types = YAML.load_file(File.join(File.dirname(__FILE__), 'mime_types.yml')) diff --git a/lib/logging_stuff.rb b/lib/logging_stuff.rb new file mode 100644 index 00000000..2178edb2 --- /dev/null +++ b/lib/logging_stuff.rb @@ -0,0 +1,20 @@ +class Logger + class LogDevice + + private + def shift_log_age + #For Passenger, restart the server when rotating log files. + FileUtils.touch Rails.root.join("tmp", "restart.txt") if defined?(PhusionPassenger) + (@shift_age-3).downto(0) do |i| + if FileTest.exist?("#{@filename}.#{i}") + File.rename("#{@filename}.#{i}", "#{@filename}.#{i+1}") + end + end + @dev.close + File.rename("#{@filename}", "#{@filename}.0") + @dev = create_logfile(@filename) + return true + end + + end +end diff --git a/lib/url_generator.rb b/lib/url_generator.rb index 9d64c88e..25b7f757 100644 --- a/lib/url_generator.rb +++ b/lib/url_generator.rb @@ -177,7 +177,7 @@ class UrlGenerator < AbstractUrlGenerator def wikilink_for(mode, name, text, web_address) web = Web.find_by_address(web_address) - action = web.published? && !(web == @web && ![:publish, :s5].include?(mode) ) ? 'published' : 'show' + action = web.published? && (web != @web || [:publish, :s5].include?(mode) ) ? 'published' : 'show' href = @controller.url_for :controller => 'wiki', :web => web_address, :action => action, :id => name, :only_path => true %{#{text}}