Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@kyanny 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