Of course the easiest solution would be to use __LINE__ and __FILE__ in your code
as part of your message, but I presume you want to change the formatting options of your logger. I'm not aware of a direct way to do it in the Logger formatter, however, if you wnat to filter the logs using some custom rules, TaggedLogging in Active upport helps in doing exactly that by stamping log lines with subdomains, request ids, and anything else to aid debugging such applications. Instead of tags you could use __FILE__ and __LINE__ variables
here is a example:
logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))
logger.tagged("BCX") { logger.info "Stuff" } # Logs "[BCX] Stuff"
logger.tagged("BCX", "Jason") { logger.info "Stuff" } # Logs "[BCX] [Jason] Stuff"
logger.tagged("BCX") { logger.tagged("Jason") { logger.info "Stuff" } } # Logs "[BCX [Jason] Stuff
I also suggest changin the formatter as in the below example:
Log = Logger.new(STDOUT)
Log.formatter = proc { |severity, datetime, progname, msg|
"#{severity} #{caller[4]} #{msg}\n"
}
now each time you call Log.INFO( 'some message') you should have the file and line number of the 'caller' of the log method