Something like this maybe?
require 'log4r'
class PaddedLogger
attr_accessor :logger, :padding
def initialize(args)
@logger = Log4r::Logger.new args[:name]
@padding = args[:padding]
end
[:debug, :info, :warn, :error, :fatal].each do |reason|
define_method reason do |system, message|
system = "[#{system}]"
@logger.send reason, "#{system.ljust(@padding)}#{message}"
end
end
end
And while you're at it, why not collapse the two lines in the define_method
block to one?
@logger.send reason, "[#{system}]".ljust(@padding) + message