Created
November 26, 2012 03:00
-
-
Save pasela/4146385 to your computer and use it in GitHub Desktop.
[ruby] Logger: Use filepath if progname was omitted.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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