title: Increasing the DRYness with a Simple Wrapping Class in Ruby
body: <p>There has to be a better way to do this:</p>
  
  <pre><code>require 'log4r'
  
  class PaddedLogger
  
    attr_accessor :logger, :padding
  
    def initialize(args)
      @logger = Log4r::Logger.new args[:name]
      @padding = args[:padding]
    end
  
    def debug(system, message)
      system = "[#{system}]"
      @logger.debug "#{system.ljust(@padding)}#{message}"
    end
  
    def info(system, message)
      system = "[#{system}]"
      @logger.info "#{system.ljust(@padding)}#{message}"
    end
  
    def warn(system, message)
      system = "[#{system}]"
      @logger.warn "#{system.ljust(@padding)}#{message}"
    end
  
    def error(system, message)
      system = "[#{system}]"
      @logger.error "#{system.ljust(@padding + 3)}#{message}"
    end
  
    def fatal(system, message)
      system = "[#{system}]"
      @logger.fatal "#{system.ljust(@padding + 3)}#{message}"
    end
  end
  </code></pre>
  
  <p>It's just a wrapping class to help me get my log4r logs appearing in a specific format, and it works exactly as I need it too, but surely Ruby's meta-programming magic can simplify this so I don't have to constantly repeat myself.</p>