Sha256: e9422cb43e4d48a0d5441678cbeb0e3248155de673bbd0a1d78d583afdc8dc69

Contents?: true

Size: 1.03 KB

Versions: 28

Compression:

Stored size: 1.03 KB

Contents

class Bj
  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

    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

    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
  end
end

Version data entries

28 entries across 26 versions & 12 rubygems

Version Path
ThiagoLelis-backgroundjob-1.0.3 lib/bj/logger.rb
ThiagoLelis-backgroundjob-1.0.4 lib/bj/logger.rb
ThiagoLelis-bj-utc-1.0.1 lib/bj/logger.rb
ThiagoLelis-bj-utc-1.0.2 lib/bj/logger.rb
ambethia-bj-1.2.1 lib/bj/logger.rb
averell23-bj-1.0.2 lib/bj/logger.rb
bricooke-bj-1.0.2 lib/bj/logger.rb
jcnetdev-bj-1.0.33 lib/bj/logger.rb
jcnetdev-bj-1.0.38 lib/bj/logger.rb
sevenwire-bj-1.0.1 lib/bj/logger.rb
sevenwire-bj-1.0.2 lib/bj/logger.rb
sevenwire-bj-1.0.4 lib/bj/logger.rb
blackhoundjob-1.0.2 lib/bj/logger.rb
bj_fixed_for_rails3-1.0.4 lib/bj/logger.rb
bj_fixed_for_rails3-1.0.3 lib/bj/logger.rb
bj_fixed_for_rails3-1.0.2 lib/bj/logger.rb
vibes-bj-1.2.2 spec/rails_root/vendor/plugins/bj/lib/bj/logger.rb
vibes-bj-1.2.2 lib/bj/logger.rb
vibes-bj-1.2.1 spec/rails_root/vendor/plugins/bj/lib/bj/logger.rb
vibes-bj-1.2.1 lib/bj/logger.rb