Skip to content

Instantly share code, notes, and snippets.

@pasela
Created November 26, 2012 03:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pasela/4146385 to your computer and use it in GitHub Desktop.
Save pasela/4146385 to your computer and use it in GitHub Desktop.
[ruby] Logger: Use filepath if progname was omitted.
# encoding: utf-8
require 'pathname'
# Set filename if progname was omitted.
class Logger
alias_method :org_add, :add
def add(severity, message = nil, progname = nil, &block)
if message.nil? && !block_given?
message = progname
path = Pathname.new(caller(2).first[/^(.+):\d+:in /, 1])
if path.absolute?
path = path.relative_path_from(Pathname.getwd.expand_path)
end
progname = path.to_s
end
org_add(severity, message, progname, &block)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment