Module: ServerEngine::DaemonLogger::RotationAware

Defined in:
lib/serverengine/daemon_logger.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(obj) ⇒ Object



137
138
139
# File 'lib/serverengine/daemon_logger.rb', line 137

def self.extended(obj)
  obj.update_ino
end

Instance Method Details

#reopen(log = nil) ⇒ Object



148
149
150
151
# File 'lib/serverengine/daemon_logger.rb', line 148

def reopen(log = nil)
  super(log)
  update_ino
end

#reopen!Object



153
154
155
156
# File 'lib/serverengine/daemon_logger.rb', line 153

def reopen!
  super
  update_ino
end

#update_inoObject



141
142
143
144
145
146
# File 'lib/serverengine/daemon_logger.rb', line 141

def update_ino
  (@ino_mutex ||= Mutex.new).synchronize do
    @ino = File.stat(filename).ino rescue nil
    @last_ino_time = Time.now
  end
end

#write(message) ⇒ Object



158
159
160
161
162
163
164
165
166
167
168
# File 'lib/serverengine/daemon_logger.rb', line 158

def write(message)
  reopen_needed = false
  @ino_mutex.synchronize do
    if (Time.now - @last_ino_time).abs > 1
      ino = File.stat(filename).ino rescue nil
      reopen_needed = true if ino && ino != @ino
    end
  end
  reopen! if reopen_needed
  super(message)
end