Skip to content

Instantly share code, notes, and snippets.

@kyanny
Created July 27, 2011 10:30
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyanny/1109108 to your computer and use it in GitHub Desktop.
Save kyanny/1109108 to your computer and use it in GitHub Desktop.
Log::Minimal - convenient logger wrapper for your rails app inspired by Log::Minimal CPAN module
module Log
module Minimal
[:fatal, :error, :warn, :info, :debug].each do |method|
define_method "#{method}f" do |message|
time = Time.now.iso8601
level = method.to_s.upcase
caller = "%s#%s:%s" % [self.class, action_name, caller(1)[0].scan(/:(\d+):/)]
logger.send(method, "%s [%s] %s %s" % [time, level, caller, message])
end
end
end
end
@kyanny
Copy link
Author

kyanny commented Jul 27, 2011

How to use it:

in application.rb or application_controller.rb

class ApplicationController < ActionController::Base
  include Log::Minimal
end

in your foo_controller.rb

class FooController < ApplicationController
  def index
    infof("foo bar baz")
  end
end

then you can get informative log message :)

2011-07-27T19:17:38+09:00 [INFO] FooController#index::14: foo bar baz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment