yahns.git  about / heads / tags
sleepy, multi-threaded, non-blocking application server for Ruby
blob 569d6613d7aef05b0844316a00a2a18689c56c45 958 bytes (raw)
$ git show v0.0.0:examples/logger_mp_safe.rb	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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

git clone git://yhbt.net/yahns.git
git clone https://yhbt.net/yahns.git