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