t/lib.perl: fix Perl integration tests w/o installation
[unicorn.git] / examples / logger_mp_safe.rb
blobf2c05002c0b1245f23f3627443f72a13b8d2519d
1 # frozen_string_literal: false
2 # Multi-Processing-safe monkey patch for Logger
4 # This monkey patch fixes the case where "preload_app true" is used and
5 # the application spawns a background thread upon being loaded.
7 # This removes all lock from the Logger code and solely relies on the
8 # underlying filesystem to handle write(2) system calls atomically when
9 # O_APPEND is used.  This is safe in the presence of both multiple
10 # threads (native or green) and multiple processes when writing to
11 # a filesystem with POSIX O_APPEND semantics.
13 # It should be noted that the original locking on Logger could _never_ be
14 # considered reliable on non-POSIX filesystems with multiple processes,
15 # either, so nothing is lost in that case.
17 require 'logger'
18 class Logger::LogDevice
19   def write(message)
20     @dev.syswrite(message)
21   end
23   def close
24     @dev.close
25   end
26 end