diff options
author | Eric Wong <normalperson@yhbt.net> | 2013-10-18 10:28:18 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2013-10-18 10:28:18 +0000 |
commit | ab067831e707b191d6dfdcd01de1f1d85fc90d05 (patch) | |
tree | b02861eb1521fb325ee4e1d91e1a194ca73e7a9e /examples/logger_mp_safe.rb | |
download | yahns-ab067831e707b191d6dfdcd01de1f1d85fc90d05.tar.gz |
Diffstat (limited to 'examples/logger_mp_safe.rb')
-rw-r--r-- | examples/logger_mp_safe.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/examples/logger_mp_safe.rb b/examples/logger_mp_safe.rb new file mode 100644 index 0000000..569d661 --- /dev/null +++ b/examples/logger_mp_safe.rb @@ -0,0 +1,28 @@ +# To the extent possible under law, Eric Wong has waived all copyright and +# related or neighboring rights to this examples +# +# Multi-Processing-safe monkey patch for Logger +# +# This monkey patch fixes the case where "preload: true" is used and +# the application spawns a background thread upon being loaded. +# +# This removes all lock from the Logger code and solely relies on the +# underlying filesystem to handle write(2) system calls atomically when +# O_APPEND is used. This is safe in the presence of both multiple +# threads (native or green) and multiple processes when writing to +# a filesystem with POSIX O_APPEND semantics. +# +# It should be noted that the original locking on Logger could _never_ be +# considered reliable on non-POSIX filesystems with multiple processes, +# either, so nothing is lost in that case. + +require 'logger' +class Logger::LogDevice + def write(message) + @dev.syswrite(message) + end + + def close + @dev.close + end +end |