Browse files

initial commit

  • Loading branch information...
0 parents commit f1c1b57a5cc803c906dd4ae63cf3eadb41d77e97 @jt committed Apr 16, 2011
Showing with 135 additions and 0 deletions.
  1. +4 −0 .gitignore
  2. +2 −0 Gemfile
  3. +19 −0 LICENSE
  4. +22 −0 README.md
  5. +2 −0 Rakefile
  6. +29 −0 itslog.gemspec
  7. +3 −0 lib/itslog.rb
  8. +44 −0 lib/itslog/formatter.rb
  9. +7 −0 lib/itslog/railtie.rb
  10. +3 −0 lib/itslog/version.rb
4 .gitignore
@@ -0,0 +1,4 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
2 Gemfile
@@ -0,0 +1,2 @@
+source :rubygems
+gemspec
19 LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2011 by John Thomas Marino
+
+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.
22 README.md
@@ -0,0 +1,22 @@
+itslog
+======
+
+`itslog` is a log formatter designed to aid development.
+
+The formatting will prepend all log statements with a colored header.
+
+ [timestamp] [rails module] [normal log], example:
+ 15:16:32 action_view Rendered layouts/_head.haml (8.5ms)
+
+Install
+-------
+
+Add to your Gemfile in Rails:
+
+ gem 'itslog'
+
+or to a group
+
+ group :development, :test do
+ gem 'itslog'
+ end
2 Rakefile
@@ -0,0 +1,2 @@
+require 'bundler'
+Bundler::GemHelper.install_tasks
29 itslog.gemspec
@@ -0,0 +1,29 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path('../lib', __FILE__)
+require 'itslog/version'
+
+Gem::Specification.new do |s|
+ s.name = 'itslog'
+ s.version = Itslog::VERSION
+ s.platform = Gem::Platform::RUBY
+ s.authors = ['John Thomas Marino']
+ s.email = 'writejm@gmail.com'
+ s.homepage = 'http://github.com/johmas/itslog'
+ s.summary = 'itslog makes logs more useful for development'
+ s.description = %q{
+ `itslog` is a log formatter designed to aid development.
+
+ The formatting will prepend all log statements with a colored header.
+
+ [timestamp] [rails library] [normal log], example:
+ 15:16:32 action_view Rendered layouts/_head.haml (8.5ms)
+ }
+
+ s.rubyforge_project = 'itslog'
+
+ s.files = %w( README.md Rakefile LICENSE )
+ s.files += Dir.glob("lib/**/*")
+ s.files += Dir.glob("bin/**/*")
+
+ s.require_paths = ['lib']
+end
3 lib/itslog.rb
@@ -0,0 +1,3 @@
+require 'rails'
+require 'itslog/railtie'
+require 'itslog/formatter'
44 lib/itslog/formatter.rb
@@ -0,0 +1,44 @@
+module Itslog
+ module BufferedLoggerExtension
+ extend ActiveSupport::Concern
+ attr_accessor :namespace
+
+ def namespace
+ @namespace ||= 'unknown'
+ end
+
+ def add_with_format(severity, message = nil, progname = nil, &block)
+ return if @level > severity
+ colors = ["\e[36m","\e[32m","\e[33m","\e[31m","\e[31m","\e[37m"]
+ time = Time.now.to_s(:db)
+
+ msg = ''
+ msg << colors[severity]
+ msg << "#{time.split.first} " unless Rails.env.development? || Rails.env.test?
+ msg << "#{time.split.last} "
+ msg << "#{namespace}: "
+ msg << colors[5]
+ msg << message.strip
+
+ add_without_format(severity, msg, progname, &block)
+ end
+
+ included do
+ alias_method_chain :add, :format
+ end
+ end
+
+ module LogSubscriberExtension
+ extend ActiveSupport::Concern
+
+ def call_with_namespace(message, *args)
+ logger.namespace = message.split('.').last if logger
+ call_without_namespace(message, *args)
+ end
+
+ included do
+ puts '~> itslog enabled'
+ alias_method_chain :call, :namespace
+ end
+ end
+end
7 lib/itslog/railtie.rb
@@ -0,0 +1,7 @@
+class Railtie < Rails::Railtie
+ config.before_initialize do
+ ActiveSupport::BufferedLogger.send(:include, Itslog::BufferedLoggerExtension)
+ ActiveSupport::LogSubscriber.send(:include, Itslog::LogSubscriberExtension)
+ ActiveSupport::LogSubscriber.colorize_logging = false
+ end
+end
3 lib/itslog/version.rb
@@ -0,0 +1,3 @@
+module Itslog
+ VERSION = '0.0.1'
+end

0 comments on commit f1c1b57

Please sign in to comment.