Module: Ghaki::Logger::CoreExt::LogDevice

Included in:
Logger::LogDevice
Defined in:
lib/ghaki/logger/core_ext/logdev.rb

Overview

Adds features to the LogDevice class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#filenameObject (readonly) Also known as: file_name

Returns the value of attribute filename.



11
12
13
# File 'lib/ghaki/logger/core_ext/logdev.rb', line 11

def filename
  @filename
end

#shift_ageObject

Returns the value of attribute shift_age.



11
12
13
# File 'lib/ghaki/logger/core_ext/logdev.rb', line 11

def shift_age
  @shift_age
end

#shift_sizeObject

Returns the value of attribute shift_size.



11
12
13
# File 'lib/ghaki/logger/core_ext/logdev.rb', line 11

def shift_size
  @shift_size
end

Instance Method Details

#bounceObject



48
49
50
51
52
53
54
55
56
57
# File 'lib/ghaki/logger/core_ext/logdev.rb', line 48

def bounce
  unless @filename.nil?
    @mutex.synchronize do
      @dev.flush
      @dev.close
      @dev = open_logfile(@filename)
      @dev.sync = true
    end
  end
end

#re_open(opts = {}) ⇒ Object

Reopen the logger using the new opts.



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/ghaki/logger/core_ext/logdev.rb', line 61

def re_open opts={}
  @mutex.synchronize do
    log = opts[:file_handle] || opts[:file_name]
    @dev = @filename = @shift_age = @shift_size = nil
    if log.respond_to?(:write) and log.respond_to?(:close)
      @dev = log
    else
      _open_and_assign( log, opts )
    end
  end
end

#re_stderrObject



80
81
82
83
84
# File 'lib/ghaki/logger/core_ext/logdev.rb', line 80

def re_stderr
  @mutex.synchronize do
    $stderr.reopen(@dev)
  end
end

#re_stdoutObject



86
87
88
89
90
# File 'lib/ghaki/logger/core_ext/logdev.rb', line 86

def re_stdout
  @mutex.synchronize do
    $stdout.reopen(@dev)
  end
end

#re_stdsObject



73
74
75
76
77
78
# File 'lib/ghaki/logger/core_ext/logdev.rb', line 73

def re_stds
  @mutex.synchronize do
    $stderr.reopen(@dev)
    $stdout.reopen(@dev)
  end
end

#rotateObject

Forces log rotation.



40
41
42
43
44
45
46
# File 'lib/ghaki/logger/core_ext/logdev.rb', line 40

def rotate
  if @shift_age.is_a?(Integer) and not @filename.nil?
    @mutex.synchronize do
      shift_log_age
    end
  end
end

#with_file(&block) ⇒ Object

Allow mutex wrapped file handle access.



20
21
22
23
24
# File 'lib/ghaki/logger/core_ext/logdev.rb', line 20

def with_file &block
  @mutex.synchronize do
    block.call( @dev )
  end
end