Sha256: 24208aabb5d1cd63e8c333467791b39ac616e85d2af6075be16b3a0e59bfae9c

Contents?: true

Size: 1.1 KB

Versions: 48

Compression:

Stored size: 1.1 KB

Contents

module Main
  ### because active_record fubars the hell out of Logger ;-(
  class Logger < ::Logger
    def self.new *a, &b
      super(*a, &b).instance_eval{ @default_formatter = @formatter = Formatter.new; self }
    end
    def format_message(severity, datetime, progname, msg)
      (@formatter || @default_formatter).call(severity, datetime, progname, msg)
    end

    def device
      @logdev.instance_eval{ @dev }
    end

    def tty?
      device.respond_to?('tty?') and device.tty?
    end

    def turn which
      @logdev.extend OnOff unless OnOff === @logdev
      @logdev.turn which
    end

    def on
      turn :on
    end
    alias_method "on!", "on"
    def self.on *a, &b
      new(*a, &b).instance_eval{ turn :on; self }
    end

    def off
      turn :off
    end
    alias_method "off!", "off"
    def self.off *a, &b
      new(*a, &b).instance_eval{ turn :off; self }
    end

    module OnOff
      def turn which
        @turned = which.to_s =~ %r/on/i ? :on : :off
      end

      def write message 
        return message.to_s.size if @turned == :off
        super
      end
    end
  end
end

Version data entries

48 entries across 47 versions & 5 rubygems

Version Path
main-6.3.0 lib/main/logger.rb
main-6.2.3 lib/main/logger.rb
main-6.2.2 lib/main/logger.rb
main-6.2.1 lib/main/logger.rb
main-6.2.0 lib/main/logger.rb
asana2flowdock-1.0.0 vendor/bundle/ruby/1.9.1/gems/main-6.0.0/lib/main/logger.rb
asana2flowdock-1.0.0 vendor/bundle/ruby/1.9.1/gems/main-6.1.0/lib/main/logger.rb
main-6.1.0 lib/main/logger.rb
ThiagoLelis-backgroundjob-1.0.4 lib/main/logger.rb
ahoward-main-2.9.0 lib/main/logger.rb
main-6.0.0 lib/main/logger.rb
main-5.3.2 lib/main/logger.rb
main-5.3.1 lib/main/logger.rb
main-5.2.0 lib/main/logger.rb
main-5.1.1 lib/main/logger.rb
main-5.1.0 lib/main/logger.rb
main-5.0.1 lib/main/logger.rb
main-5.0.0 lib/main/logger.rb
main-4.8.1 lib/main/logger.rb
main-4.8.0 lib/main/logger.rb