Class: Bj::Logger

Inherits:
Logger show all
Defined in:
lib/bj/logger.rb

Defined Under Namespace

Modules: OnOff

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new(*a, &b) ⇒ Object



3
4
5
# File 'lib/bj/logger.rb', line 3

def self.new *a, &b
  super(*a, &b).instance_eval{ @default_formatter = @formatter = Formatter.new; self }
end

.off(*a, &b) ⇒ Object



46
47
48
# File 'lib/bj/logger.rb', line 46

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

.on(*a, &b) ⇒ Object



38
39
40
# File 'lib/bj/logger.rb', line 38

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

Instance Method Details

#deviceObject



10
11
12
# File 'lib/bj/logger.rb', line 10

def device
  @logdev.instance_eval{ @dev }
end

#format_message(severity, datetime, progname, msg) ⇒ Object



6
7
8
# File 'lib/bj/logger.rb', line 6

def format_message(severity, datetime, progname, msg)
  (@formatter || @default_formatter).call(severity, datetime, progname, msg)
end

#offObject



42
43
44
# File 'lib/bj/logger.rb', line 42

def off
  turn :off
end

#off!Object



45
46
47
# File 'lib/bj/logger.rb', line 45

def off
  turn :off
end

#onObject



34
35
36
# File 'lib/bj/logger.rb', line 34

def on
  turn :on
end

#on!Object



37
38
39
# File 'lib/bj/logger.rb', line 37

def on
  turn :on
end

#tty?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/bj/logger.rb', line 14

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

#turn(which) ⇒ Object



18
19
20
21
# File 'lib/bj/logger.rb', line 18

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