logging-rails-0.6.0/ 0000755 0000041 0000041 00000000000 13160655352 014311 5 ustar www-data www-data logging-rails-0.6.0/Rakefile 0000644 0000041 0000041 00000000647 13160655352 015765 0 ustar www-data www-data begin
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.6.0/script/ 0000755 0000041 0000041 00000000000 13160655352 015615 5 ustar www-data www-data logging-rails-0.6.0/script/bootstrap 0000755 0000041 0000041 00000000273 13160655352 017562 0 ustar www-data www-data #!/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.6.0/version.txt 0000644 0000041 0000041 00000000006 13160655352 016533 0 ustar www-data www-data 0.6.0
logging-rails-0.6.0/History.txt 0000644 0000041 0000041 00000001147 13160655352 016516 0 ustar www-data www-data == 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.6.0/lib/ 0000755 0000041 0000041 00000000000 13160655352 015057 5 ustar www-data www-data logging-rails-0.6.0/lib/logging/ 0000755 0000041 0000041 00000000000 13160655352 016505 5 ustar www-data www-data logging-rails-0.6.0/lib/logging/rails/ 0000755 0000041 0000041 00000000000 13160655352 017617 5 ustar www-data www-data logging-rails-0.6.0/lib/logging/rails/generators/ 0000755 0000041 0000041 00000000000 13160655352 021770 5 ustar www-data www-data logging-rails-0.6.0/lib/logging/rails/generators/templates/ 0000755 0000041 0000041 00000000000 13160655352 023766 5 ustar www-data www-data logging-rails-0.6.0/lib/logging/rails/generators/templates/logging.rb.erb 0000644 0000041 0000041 00000010615 13160655352 026513 0 ustar www-data www-data Logging::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.6.0/lib/logging/rails/generators/USAGE 0000644 0000041 0000041 00000000466 13160655352 022565 0 ustar www-data www-data Description:
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.6.0/lib/logging/rails/generators/install_generator.rb 0000644 0000041 0000041 00000002017 13160655352 026031 0 ustar www-data www-data module 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.6.0/lib/logging/rails/mixin.rb 0000644 0000041 0000041 00000002537 13160655352 021277 0 ustar www-data www-data module 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.6.0/lib/logging/rails/railtie.rb 0000644 0000041 0000041 00000004104 13160655352 021574 0 ustar www-data www-data module 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_view.logger', :before => 'action_view.logger' do
ActiveSupport.on_load(:action_view) { 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
if ActiveSupport::Dependencies.respond_to? :logger= then
initializer 'logging.active_support.dependencies.logger' do
ActiveSupport::Dependencies.logger = ::Logging::Logger[ActiveSupport::Dependencies]
end
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.6.0/lib/logging/rails.rb 0000644 0000041 0000041 00000004337 13160655352 020153 0 ustar www-data www-data require '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.6.0/lib/logging-rails.rb 0000644 0000041 0000041 00000000072 13160655352 020141 0 ustar www-data www-data require File.expand_path('../logging/rails.rb', __FILE__)
logging-rails-0.6.0/.gitignore 0000644 0000041 0000041 00000000451 13160655352 016301 0 ustar www-data www-data # git-ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
announcement.txt
coverage/
doc/
pkg/
tmp/
vendor/
.rvmrc
logging-rails-0.6.0/logging-rails.gemspec 0000644 0000041 0000041 00000003763 13160655352 020425 0 ustar www-data www-data # -*- encoding: utf-8 -*-
# stub: logging-rails 0.5.0 ruby lib
Gem::Specification.new do |s|
s.name = "logging-rails"
s.version = "0.5.0"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.require_paths = ["lib"]
s.authors = ["Tim Pease"]
s.date = "2015-03-30"
s.description = "A Railtie for for integrating the [Logging](https://github.com/TwP/logging)\nframework into your Rails 3 application."
s.email = "tim.pease@gmail.com"
s.extra_rdoc_files = ["History.txt", "lib/logging/rails/generators/USAGE", "lib/logging/rails/generators/templates/logging.rb.erb"]
s.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"]
s.homepage = "http://rubygems.org/gems/logging-rails"
s.rdoc_options = ["--main", "README.md"]
s.rubyforge_project = "logging-rails"
s.rubygems_version = "2.2.2"
s.summary = "A Railtie for for integrating the [Logging](https://github."
if s.respond_to? :specification_version then
s.specification_version = 4
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q, [">= 1.8"])
s.add_development_dependency(%q, ["~> 1.3"])
s.add_development_dependency(%q, ["~> 4"])
s.add_development_dependency(%q, [">= 3.8.3"])
else
s.add_dependency(%q, [">= 1.8"])
s.add_dependency(%q, ["~> 1.3"])
s.add_dependency(%q, ["~> 4"])
s.add_dependency(%q, [">= 3.8.3"])
end
else
s.add_dependency(%q, [">= 1.8"])
s.add_dependency(%q, ["~> 1.3"])
s.add_dependency(%q, ["~> 4"])
s.add_dependency(%q, [">= 3.8.3"])
end
end
logging-rails-0.6.0/README.md 0000644 0000041 0000041 00000010637 13160655352 015577 0 ustar www-data www-data logging-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.