Created
July 19, 2011 07:00
-
-
Save indirect/1091527 to your computer and use it in GitHub Desktop.
Revisions
-
André Arko revised this gist
Dec 12, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,7 +19,7 @@ def add(severity, message = nil, progname = nil, &block) return if @level > severity message = (message || (block && block.call) || progname).to_s # Prepend pid and severity to the written message log = "[%s] %-5.5s %s" % [$$, SEVERITIES[severity], message.gsub(/^\n+/, '')] # If a newline is necessary then create a new message ending with a newline. log << "\n" unless log[-1] == ?\n buffer << log -
André Arko revised this gist
Dec 1, 2011 . 1 changed file with 21 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,41 +1,48 @@ # You must require this file in application.rb, above the Application # definition, for this to work. For example: # # # Syslog-like Rails logs # if Rails.env.production? # require File.expand_path('../../lib/better_logger', __FILE__) # end # # module MyApp # class Application < Rails::Application require 'active_support/buffered_logger' class BetterLogger < ActiveSupport::BufferedLogger SEVERITIES = Severity.constants.sort_by{|c| Severity.const_get(c) } def add(severity, message = nil, progname = nil, &block) return if @level > severity message = (message || (block && block.call) || progname).to_s # Prepend pid and severity to the written message log = "[#{$$}] #{SEVERITIES[severity]} #{message.gsub(/^\n+/, '')}" # If a newline is necessary then create a new message ending with a newline. log << "\n" unless log[-1] == ?\n buffer << log auto_flush message end class Railtie < ::Rails::Railtie # overwrite Rails' initializer to set up our own instead initializer :initialize_logger do |app| Rails.logger = begin logger = BetterLogger.new(app.config.paths.log.to_a.first) level_name = app.config.log_level.to_s.upcase logger.level = ActiveSupport::BufferedLogger.const_get(level_name) logger.auto_flushing = false if Rails.env.production? logger end ActiveSupport::Dependencies.logger = Rails.logger # cache has no callback of its own, but is set before this callback ActiveSupport.on_load(:before_initialize) do Rails.cache.logger = Rails.logger end ActiveSupport.on_load(:active_record) do ActiveRecord::Base.logger = Rails.logger end @@ -46,6 +53,7 @@ class Railtie < ::Rails::Railtie ActionMailer::Base.logger = Rails.logger end end end end -
Andre Arko revised this gist
Sep 10, 2011 . 1 changed file with 5 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,9 +18,11 @@ class PidLogger < ActiveSupport::BufferedLogger def add(severity, message = nil, progname = nil, &block) return if @level > severity message = (message || (block && block.call) || progname).to_s # Insert a newline before the log line if there was one in the first place. log = (message[0] == ?\n) ? "\n" : "" # Prepend pid and severity to the written message log << "[#{$$}] #{SEVERITIES[severity]} #{message.gsub(/^\n+/, '')}" # If a newline is necessary then end with a newline. log << "\n" unless log[-1] == ?\n buffer << log auto_flush @@ -46,4 +48,4 @@ class Railtie < ::Rails::Railtie end end end -
Andre Arko revised this gist
Sep 10, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,7 +24,7 @@ def add(severity, message = nil, progname = nil, &block) log << "\n" unless log[-1] == ?\n buffer << log auto_flush log end class Railtie < ::Rails::Railtie -
Andre Arko revised this gist
Sep 7, 2011 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -29,7 +29,9 @@ def add(severity, message = nil, progname = nil, &block) class Railtie < ::Rails::Railtie initializer "swap in PidLogger" do path = Rails.application.config.paths.log.first level = Rails.logger.level Rails.logger = PidLogger.new(path, level) ActiveSupport::Dependencies.logger = Rails.logger Rails.cache.logger = Rails.logger ActiveSupport.on_load(:active_record) do -
Andre Arko revised this gist
Aug 18, 2011 . 1 changed file with 39 additions and 40 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,48 +1,47 @@ # You must require this file in application.rb, above the Application # definition, for this to work. For example: # # # PIDs prepended to logs # if Rails.env.production? # require File.expand_path('../../lib/pid_logger', __FILE__) # end # # module MyApp # class Application < Rails::Application require 'active_support/buffered_logger' class PidLogger < ActiveSupport::BufferedLogger SEVERITIES = Severity.constants.sort_by{|c| Severity.const_get(c) } def add(severity, message = nil, progname = nil, &block) return if @level > severity message = (message || (block && block.call) || progname).to_s # Prepend pid and severity to the written message log = "[#{$$}] #{SEVERITIES[severity]} #{message.gsub(/^\n+/, '')}" # If a newline is necessary then create a new message ending with a newline. log << "\n" unless log[-1] == ?\n buffer << log auto_flush message end class Railtie < ::Rails::Railtie initializer "swap in PidLogger" do Rails.logger = PidLogger.new(Rails.application.config.paths.log.first) ActiveSupport::Dependencies.logger = Rails.logger Rails.cache.logger = Rails.logger ActiveSupport.on_load(:active_record) do ActiveRecord::Base.logger = Rails.logger end ActiveSupport.on_load(:action_controller) do ActionController::Base.logger = Rails.logger end ActiveSupport.on_load(:action_mailer) do ActionMailer::Base.logger = Rails.logger end end end end -
Andre Arko revised this gist
Aug 18, 2011 . 1 changed file with 40 additions and 41 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,49 +1,48 @@ # You must require this file in application.rb, above the Application # definition, for this to work. For example: # # # PIDs prepended to logs # if Rails.env.production? # require File.expand_path('../../lib/pid_logger', __FILE__) # end # # module MyApp # class Application < Rails::Application require 'active_support/buffered_logger' class PidLogger < ActiveSupport::BufferedLogger SEVERITIES = Severity.constants.sort_by{|c| Severity.const_get(c) } def add(severity, message = nil, progname = nil, &block) return if @level > severity message = (message || (block && block.call) || progname).to_s # Prepend pid and severity to the written message log = "[#{$$}] #{SEVERITIES[severity]} #{message.gsub(/^\n+/, '')}" # If a newline is necessary then create a new message ending with a newline. log << "\n" unless log[-1] == ?\n buffer << log auto_flush message end class Railtie < ::Rails::Railtie initializer "swap in PidLogger" do Rails.logger = PidLogger.new(Rails.application.config.paths.log.first) ActiveSupport::Dependencies.logger = Rails.logger Rails.cache.logger = Rails.logger ActiveSupport.on_load(:active_record) do ActiveRecord::Base.logger = Rails.logger end ActiveSupport.on_load(:action_controller) do ActionController::Base.logger = Rails.logger end ActiveSupport.on_load(:action_mailer) do ActionMailer::Base.logger = Rails.logger end end end end -
Andre Arko revised this gist
Aug 3, 2011 . 1 changed file with 4 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,9 +18,10 @@ class BetterLogger < ActiveSupport::BufferedLogger def add(severity, message = nil, progname = nil, &block) return if @level > severity message = (message || (block && block.call) || progname).to_s # (Optional) timestamp, not needed if you feed your logs to syslog or equivalent #log = Time.now.to_formatted_s(:db)} + " " # Add severity and pid log = "[#{$$}] #{SEVERITIES[severity]} #{message.gsub(/^\n+/, '')}" # If a newline is necessary then create a new message ending with a newline. log << "\n" unless log[-1] == ?\n buffer << log -
Andre Arko revised this gist
Jul 19, 2011 . 1 changed file with 0 additions and 48 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,48 +0,0 @@ -
Andre Arko revised this gist
Jul 19, 2011 . 1 changed file with 48 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ # You must require this file in application.rb, above the Application # definition, for this to work. For example: # # # Syslog-like Rails logs # if Rails.env.production? # require File.expand_path('../../lib/better_logger', __FILE__) # end # # module MyApp # class Application < Rails::Application require 'active_support/buffered_logger' class BetterLogger < ActiveSupport::BufferedLogger SEVERITIES = Severity.constants.sort_by{|c| Severity.const_get(c) } def add(severity, message = nil, progname = nil, &block) return if @level > severity message = (message || (block && block.call) || progname).to_s # Add timestamp, severity, and pid, kinda like syslog log = "#{Time.now.to_formatted_s(:db)} #{SEVERITIES[severity]}" log << " [#{$$}] #{message.gsub(/^\n+/, '')}" # If a newline is necessary then create a new message ending with a newline. log << "\n" unless log[-1] == ?\n buffer << log auto_flush message end class Railtie < ::Rails::Railtie initializer "swap in BetterLogger" do Rails.logger = BetterLogger.new(Rails.application.config.paths.log.first) ActiveSupport::Dependencies.logger = Rails.logger Rails.cache.logger = Rails.logger ActiveSupport.on_load(:active_record) do ActiveRecord::Base.logger = Rails.logger end ActiveSupport.on_load(:action_controller) do ActionController::Base.logger = Rails.logger end ActiveSupport.on_load(:action_mailer) do ActionMailer::Base.logger = Rails.logger end end end end -
Andre Arko revised this gist
Jul 19, 2011 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,9 @@ # definition, for this to work. For example: # # # Syslog-like Rails logs # if Rails.env.production? # require File.expand_path('../../lib/better_logger', __FILE__) # end # # module MyApp # class Application < Rails::Application -
Andre Arko revised this gist
Jul 19, 2011 . 1 changed file with 2 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,10 +18,9 @@ def add(severity, message = nil, progname = nil, &block) message = (message || (block && block.call) || progname).to_s # Add timestamp, severity, and pid, kinda like syslog log = "#{Time.now.to_formatted_s(:db)} #{SEVERITIES[severity]}" log << " [#{$$}] #{message.gsub(/^\n+/, '')}" # If a newline is necessary then create a new message ending with a newline. log << "\n" unless log[-1] == ?\n buffer << log auto_flush message -
Andre Arko created this gist
Jul 19, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ # You must require this file in application.rb, above the Application # definition, for this to work. For example: # # # Syslog-like Rails logs # require File.expand_path('../../lib/better_logger', __FILE__) # # module MyApp # class Application < Rails::Application require 'active_support/buffered_logger' class BetterLogger < ActiveSupport::BufferedLogger SEVERITIES = Severity.constants.sort_by{|c| Severity.const_get(c) } def add(severity, message = nil, progname = nil, &block) return if @level > severity message = (message || (block && block.call) || progname).to_s # Add timestamp, severity, and pid, kinda like syslog log = "#{Time.now.to_formatted_s(:db)} #{SEVERITIES[severity]}" log << " [#{$$}] #{message}" # If a newline is necessary then create a new message ending with a newline. # Ensures that the original message is not mutated. log << "\n" unless message[-1] == ?\n buffer << log auto_flush message end class Railtie < ::Rails::Railtie initializer "swap in BetterLogger" do Rails.logger = BetterLogger.new(Rails.application.config.paths.log.first) ActiveSupport::Dependencies.logger = Rails.logger Rails.cache.logger = Rails.logger ActiveSupport.on_load(:active_record) do ActiveRecord::Base.logger = Rails.logger end ActiveSupport.on_load(:action_controller) do ActionController::Base.logger = Rails.logger end ActiveSupport.on_load(:action_mailer) do ActionMailer::Base.logger = Rails.logger end end end end