logging-rails-0.5.0/0000755000076400007640000000000012564657520013322 5ustar pravipravilogging-rails-0.5.0/version.txt0000644000076400007640000000000612564657520015544 0ustar pravipravi0.5.0 logging-rails-0.5.0/History.txt0000644000076400007640000000114712564657520015527 0ustar pravipravi== 0.4.0 / 2012-04-04 Enhancements - Compatibility with Ruby 1.8.7 [issue #2] - Showing logging configuration is now optional Bug Fixes - Update "logging" depedency to any 1.X gem release == 0.3.0 / 2011-09-19 Enhancements - Appending default "log_to" destinations to the configuration files - Remove the LogTail middleware if present - Removing the Rails version check == 0.2.0 / 2011-09-16 Enhancements - Using the ActionMailer smtp settings - Sanity checks for Rails and Rails.version - Handling difference in "config.paths" between Rails 3.0 and Rails 3.1 == 0.1.0 / 2011-09-16 Enhancements - Birthday! logging-rails-0.5.0/script/0000755000076400007640000000000012564657520014626 5ustar pravipravilogging-rails-0.5.0/script/bootstrap0000755000076400007640000000027312564657520016573 0ustar pravipravi#!/usr/bin/env sh function gem_install { gem list -i $1 >/dev/null 2>&1 rc=$? if [[ $rc != 0 ]]; then gem install $1 fi } gem_install 'bones' rake gem:install_dependencies logging-rails-0.5.0/README.md0000644000076400007640000001063712564657520014610 0ustar pravipravilogging-rails ============= A Railtie for for integrating the [Logging](https://github.com/TwP/logging) framework into your Rails 3 application. Features -------- The railtie provides only one feature - integration of the **Logging** framework into your Rails application. But this gives you quite a bit of flexibility to format your log messages and direct them to multiple logging destinations: stdout with colors, a rolling log file, email, or even get a growl notification. Install ------- Add the ```logging-rails``` railtie gem to your Rails project's Gemfile and run ```bundle install```. ```ruby gem 'logging-rails', :require => 'logging/rails' ```` A generator is included with the railtie that will create a ```config/logging.rb``` configuration file for use in your Rails project. Please run this generator before attempting to use the **Logging** framework. ``` rails generate logging:install ``` Usage ----- Out of the box, the **Logging** framework is configured to behave in the same way as the standard Rails logger setup. The major exception is that the log file will be rolled daily - gone are the days of 2GB log files on production servers. The railtie adds a configuration option, ```log_to```, that determines where log messages will be sent. This is an array of appender names (an appender writes log messages to some destination such as a file, STDOUT, syslog, email, etc.). The appender configuration should be set in your environment specific configuration file. For example, in production we would want to log to a file and send emails on error: ```ruby config.log_to = %w[file email] ``` The **Logging** framework sets the global log level from the ```log_level``` configuration item. However, each class can be assigned its own log level. This is very useful when debugging a single controller or model in your Rails application. Consider the example below. The overall log level for the application is set to ```:info```, but the log level for the *User* model and controller is set to ```:debug```. ```ruby config.log_level = :info Logging.logger['User'].level = :debug Logging.logger['UserController'].level = :debug ``` When using the logging railtie, a small display of the current logging configuration will be displayed when Rails is in development mode (environment). A description of the display can be found [here](https://github.com/TwP/logging/blob/master/lib/logging.rb#L400). ``` root ............................................ *debug -T - - ActionController::Base ........................ debug +A -T ActiveRecord::Base ............................ debug +A -T ActiveSupport::Cache::FileStore ............... debug +A -T ActiveSupport::Dependencies ................... debug +A -T Logging ....................................... *off -A -T Rails ......................................... debug +A -T ``` This is useful for understanding more complex logging configurations. It can be annoying in day-to-day usage. To disable, set the ```show_log_configuration``` setting to false in the environment specific configuration file. ```ruby config.show_log_configuration = false ``` Author ------ Original author: [Elliot Winkler](https://github.com/mcmire) Contributors: * [Tim Pease](https://github.com/TwP) License ------- The MIT License Copyright © 2011-2012 by Tim Pease Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the *Software*), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. logging-rails-0.5.0/metadata.yml0000644000076400007640000000562112564657520015631 0ustar pravipravi--- !ruby/object:Gem::Specification name: logging-rails version: !ruby/object:Gem::Version version: 0.5.0 platform: ruby authors: - Tim Pease autorequire: bindir: bin cert_chain: [] date: 2015-03-30 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: logging requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '1.8' type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '1.8' - !ruby/object:Gem::Dependency name: bones-git requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.3' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.3' - !ruby/object:Gem::Dependency name: rails requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '4' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '4' - !ruby/object:Gem::Dependency name: bones requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: 3.8.3 type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: 3.8.3 description: |- A Railtie for for integrating the [Logging](https://github.com/TwP/logging) framework into your Rails 3 application. email: tim.pease@gmail.com executables: [] extensions: [] extra_rdoc_files: - History.txt - lib/logging/rails/generators/USAGE - lib/logging/rails/generators/templates/logging.rb.erb files: - ".gitignore" - History.txt - README.md - Rakefile - lib/logging-rails.rb - lib/logging/rails.rb - lib/logging/rails/generators/USAGE - lib/logging/rails/generators/install_generator.rb - lib/logging/rails/generators/templates/logging.rb.erb - lib/logging/rails/mixin.rb - lib/logging/rails/railtie.rb - script/bootstrap - version.txt homepage: http://rubygems.org/gems/logging-rails licenses: [] metadata: {} post_install_message: rdoc_options: - "--main" - README.md require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: logging-rails rubygems_version: 2.2.2 signing_key: specification_version: 4 summary: A Railtie for for integrating the [Logging](https://github. test_files: [] logging-rails-0.5.0/lib/0000755000076400007640000000000012564657520014070 5ustar pravipravilogging-rails-0.5.0/lib/logging-rails.rb0000644000076400007640000000007212564657520017152 0ustar pravipravirequire File.expand_path('../logging/rails.rb', __FILE__) logging-rails-0.5.0/lib/logging/0000755000076400007640000000000012564657520015516 5ustar pravipravilogging-rails-0.5.0/lib/logging/rails/0000755000076400007640000000000012564657520016630 5ustar pravipravilogging-rails-0.5.0/lib/logging/rails/railtie.rb0000644000076400007640000000350012564657520020604 0ustar pravipravimodule Logging::Rails # The Railtie is used to inject the Logging framework into the Rails # application. class Railtie < ::Rails::Railtie generators do require File.expand_path('../generators/install_generator', __FILE__) end config.before_configuration do config.log_to = %w[file] config.show_log_configuration = false end initializer 'logging.configure', :before => 'initialize_logger' do |app| file = ::Rails.root.join('config/logging.rb') load file if File.exists? file ::Logging::Rails.configuration.call(app.config) if ::Logging::Rails.configuration end initializer 'logging.initialize', :before => 'initialize_logger' do ::Rails.logger = ::Logging::Logger[::Rails] end initializer 'logging.active_record.logger', :before => 'active_record.logger' do ActiveSupport.on_load(:active_record) { self.__send__(:include, ::Logging::Rails::Mixin) } end initializer 'logging.action_controller.logger', :before => 'action_controller.logger' do ActiveSupport.on_load(:action_controller) { self.__send__(:include, ::Logging::Rails::Mixin) } end initializer 'logging.action_mailer.logger', :before => 'action_mailer.logger' do ActiveSupport.on_load(:action_mailer) { self.__send__(:include, ::Logging::Rails::Mixin) } end initializer 'logging.active_support.dependencies.logger' do ActiveSupport::Dependencies.logger = ::Logging::Logger[ActiveSupport::Dependencies] end initializer 'logging.initialize_cache', :after => 'initialize_cache' do ::Rails.cache.logger = ::Logging::Logger[::Rails.cache] end config.after_initialize do |app| if app.config.show_log_configuration and (STDIN.tty? or defined?(Rails::Console)) ::Logging.show_configuration(STDERR) end end end end logging-rails-0.5.0/lib/logging/rails/generators/0000755000076400007640000000000012564657520021001 5ustar pravipravilogging-rails-0.5.0/lib/logging/rails/generators/install_generator.rb0000644000076400007640000000201712564657520025042 0ustar pravipravimodule Logging::Rails module Generators class InstallGenerator < ::Rails::Generators::Base namespace 'logging:install' source_root File.expand_path('../templates', __FILE__) def generate_config template 'logging.rb.erb', 'config/logging.rb' end def insert_log_to_destinations comment = "\n # Set the logging destination(s)\n %s\n" insert_into_file 'config/environments/development.rb', comment % 'config.log_to = %w[stdout file]', :before => %r/^end\s*$/ insert_into_file 'config/environments/production.rb', comment % 'config.log_to = %w[file]', :before => %r/^end\s*$/ end def insert_show_log_configuration comment = "\n # Show the logging configuration on STDOUT\n config.show_log_configuration = %s\n" insert_into_file 'config/environments/development.rb', comment % 'true', :before => %r/^end\s*$/ insert_into_file 'config/environments/production.rb', comment % 'false', :before => %r/^end\s*$/ end end end end logging-rails-0.5.0/lib/logging/rails/generators/USAGE0000644000076400007640000000046612564657520021576 0ustar pravipraviDescription: Generates the configuration file used by the Logging framework. Example: rails generate logging:install This will create: config/logging.rb And it will append "log_to" destinations to: config/environments/development.rb config/environments/production.rb logging-rails-0.5.0/lib/logging/rails/generators/templates/0000755000076400007640000000000012564657520022777 5ustar pravipravilogging-rails-0.5.0/lib/logging/rails/generators/templates/logging.rb.erb0000644000076400007640000001061512564657520025524 0ustar pravipraviLogging::Rails.configure do |config| # Configure the Logging framework with the default log levels Logging.init %w[debug info warn error fatal] # Objects will be converted to strings using the :inspect method. Logging.format_as :inspect # The default layout used by the appenders. layout = Logging.layouts.pattern(:pattern => '[%d] %-5l %c : %m\n') # Setup a color scheme called 'bright' than can be used to add color codes # to the pattern layout. Color schemes should only be used with appenders # that write to STDOUT or STDERR; inserting terminal color codes into a file # is generally considered bad form. Logging.color_scheme( 'bright', :levels => { :info => :green, :warn => :yellow, :error => :red, :fatal => [:white, :on_red] }, :date => :blue, :logger => :cyan, :message => :magenta ) # Configure an appender that will write log events to STDOUT. A colorized # pattern layout is used to format the log events into strings before # writing. Logging.appenders.stdout( 'stdout', :auto_flushing => true, :layout => Logging.layouts.pattern( :pattern => '[%d] %-5l %c : %m\n', :color_scheme => 'bright' ) ) if config.log_to.include? 'stdout' # Configure an appender that will write log events to a file. The file will # be rolled on a daily basis, and the past 7 rolled files will be kept. # Older files will be deleted. The default pattern layout is used when # formatting log events into strings. Logging.appenders.rolling_file( 'file', :filename => config.paths<%= Rails.version < "3.1" ? ".log" : "['log']" %>.first, :keep => 7, :age => 'daily', :truncate => false, :auto_flushing => true, :layout => layout ) if config.log_to.include? 'file' =begin # NOTE: You will need to install the `logging-email` gem to use this appender # with loggging-2.0. The email appender was extracted into a plugin gem. That # is the reason this code is commented out. # # Configure an appender that will send an email for "error" and "fatal" log # events. All other log events will be ignored. Furthermore, log events will # be buffered for one minute (or 200 events) before an email is sent. This # is done to prevent a flood of messages. Logging.appenders.email( 'email', :from => "server@#{config.action_mailer.smtp_settings[:domain]}", :to => "developers@#{config.action_mailer.smtp_settings[:domain]}", :subject => "Rails Error [#{%x(uname -n).strip}]", :server => config.action_mailer.smtp_settings[:address], :domain => config.action_mailer.smtp_settings[:domain], :acct => config.action_mailer.smtp_settings[:user_name], :passwd => config.action_mailer.smtp_settings[:password], :authtype => config.action_mailer.smtp_settings[:authentication], :auto_flushing => 200, # send an email after 200 messages have been buffered :flush_period => 60, # send an email after one minute :level => :error, # only process log events that are "error" or "fatal" :layout => layout ) if config.log_to.include? 'email' =end # Setup the root logger with the Rails log level and the desired set of # appenders. The list of appenders to use should be set in the environment # specific configuration file. # # For example, in a production application you would not want to log to # STDOUT, but you would want to send an email for "error" and "fatal" # messages: # # => config/environments/production.rb # # config.log_to = %w[file email] # # In development you would want to log to STDOUT and possibly to a file: # # => config/environments/development.rb # # config.log_to = %w[stdout file] # Logging.logger.root.level = config.log_level Logging.logger.root.appenders = config.log_to unless config.log_to.empty? # Under Phusion Passenger smart spawning, we need to reopen all IO streams # after workers have forked. # # The rolling file appender uses shared file locks to ensure that only one # process will roll the log file. Each process writing to the file must have # its own open file descriptor for `flock` to function properly. Reopening # the file descriptors after forking ensures that each worker has a unique # file descriptor. if defined? PhusionPassenger PhusionPassenger.on_event(:starting_worker_process) do |forked| Logging.reopen if forked end end end logging-rails-0.5.0/lib/logging/rails/mixin.rb0000644000076400007640000000253712564657520020310 0ustar pravipravimodule Logging::Rails # Include this module into your ApplicationController to provide # per-controller log level configurability. You can also include this module # into your models or anywhere else you would like to control the log level. # # Alternatively, you can use the `include Logging.globally` trick to add a # `logger` method to every Object in the ruby interpreter. See # https://github.com/TwP/logging/blob/master/lib/logging.rb#L194 for more # details. module Mixin LOGGER_METHOD = RUBY_VERSION < '1.9' ? 'logger' : :logger # This method is called when the module is included into a class. It will # extend the including class so it also has a class-level `logger` method. def self.included( other ) other.__send__(:remove_method, LOGGER_METHOD.to_sym) if other.instance_methods.include? LOGGER_METHOD other.extend self end # This method is called when the modules is extended into another class or # module. It will remove any existing `logger` method and insert its own # version. def self.extended( other ) eigenclass = class << other; self; end eigenclass.__send__(:remove_method, LOGGER_METHOD.to_sym) if eigenclass.instance_methods.include? LOGGER_METHOD end # Returns the logger instance. def logger @logger ||= ::Logging::Logger[self] end end end logging-rails-0.5.0/lib/logging/rails.rb0000644000076400007640000000433712564657520017164 0ustar pravipravirequire 'logging' require 'rails' if !defined? Rails or Rails.version if Rails.version < '3' abort("The Logging Railtie only works with Rails 3 or higher - you are running Rails #{Rails.version}") end module Logging::Rails # :stopdoc: LIBPATH = ::File.expand_path('../..', __FILE__) + ::File::SEPARATOR PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR # :startdoc: class << self # Returns the version string for the library. def version @version ||= File.read(path('version.txt')).strip end # Stores the given Logging configuration block for later evalution by the # Railtie. This method is used in the 'config/logging.rb' configuration # file. def configure( &block ) @configuration = block end attr_reader :configuration # Returns the path for Mr Bones. If any arguments are given, # they will be joined to the end of the path using File.join. def path( *args ) rv = args.empty? ? PATH : ::File.join(PATH, args.flatten) if block_given? begin $LOAD_PATH.unshift PATH rv = yield ensure $LOAD_PATH.shift end end return rv end # Returns the lib path for Mr Bones. If any arguments are given, # they will be joined to the end of the path using File.join. def libpath( *args ) rv = args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten) if block_given? begin $LOAD_PATH.unshift LIBPATH rv = yield ensure $LOAD_PATH.shift end end return rv end end libpath { require 'logging/rails/railtie' require 'logging/rails/mixin' } end # Here we need to remove the Rails LogTailer from the list of middlewares. The # Logging framework is fully capable of sending log events to multiple logging # destinations. module Rails class Server < ::Rack::Server def middleware_without_log_tailer middlewares = middleware_with_log_tailer['anything'] middlewares.delete_if { |middleware| Rails::Rack::LogTailer == middleware.first } Hash.new(middlewares) end alias :middleware_with_log_tailer :middleware alias :middleware :middleware_without_log_tailer end end logging-rails-0.5.0/Rakefile0000644000076400007640000000064712564657520014776 0ustar pravipravibegin require 'bones' rescue LoadError abort '### Please install the "bones" gem ###' end task :default => 'gem' Bones { name 'logging-rails' authors 'Tim Pease' email 'tim.pease@gmail.com' url 'http://rubygems.org/gems/logging-rails' use_gmail depend_on 'logging', '>= 1.8' depend_on 'bones-git', '~> 1.3', :development => true depend_on 'rails', '~> 4', :development => true } logging-rails-0.5.0/.gitignore0000644000076400007640000000001412564657520015305 0ustar pravipravitmp/ vendor