Class: Vedeu::Logging::LocklessLogDevice Private

Inherits:
Logger::LogDevice
  • Object
show all
Defined in:
lib/vedeu/logging/lockless_log_device.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Ensures we can always write to the log file by creating a lock-less log device.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(log = nil) ⇒ Vedeu::Logging::LocklessLogDevice

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Vedeu::Logging::LocklessLogDevice.

Parameters:

  • log (void) (defaults to: nil)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/vedeu/logging/lockless_log_device.rb', line 18

def initialize(log = nil)
  @filename = nil
  @log      = log

  if writable? && closeable?
    @dev = log

  else
    @dev      = open_logfile(log)
    @dev.sync = true
    @filename = log

  end
end

Instance Attribute Details

#logString (readonly, protected)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)


53
54
55
# File 'lib/vedeu/logging/lockless_log_device.rb', line 53

def log
  @log
end

Instance Method Details

#closable?Boolean (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



58
59
60
# File 'lib/vedeu/logging/lockless_log_device.rb', line 58

def closable?
  log.respond_to?(:close)
end

#closevoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.



43
44
45
46
47
# File 'lib/vedeu/logging/lockless_log_device.rb', line 43

def close
  @dev.close
rescue
  nil
end

#open_logfile(log) ⇒ void (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Parameters:

  • log (String)


64
65
66
67
68
69
70
71
72
73
74
# File 'lib/vedeu/logging/lockless_log_device.rb', line 64

def open_logfile(log)
  if FileTest.exist?(log)
    open(log, (File::WRONLY | File::APPEND))

  else
    logdev = open(log, (File::WRONLY | File::APPEND | File::CREAT))
    logdev.sync = true
    logdev

  end
end

#writable?Boolean (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



77
78
79
# File 'lib/vedeu/logging/lockless_log_device.rb', line 77

def writable?
  log.respond_to?(:write)
end

#write(message) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Parameters:

  • message (String)


35
36
37
38
39
40
# File 'lib/vedeu/logging/lockless_log_device.rb', line 35

def write(message)
  @dev.write(message)

rescue StandardError => exception
  warn("log writing failed. #{exception}")
end