lib/rflow/child_process.rb in rflow-1.2.0 vs lib/rflow/child_process.rb in rflow-1.3.0a1
- old
+ new
@@ -2,10 +2,12 @@
class RFlow
class ChildProcess
attr_reader :pid, :name
+ SIGINFO = 29
+
def initialize(name, role = name)
@name = name
@role = role
end
@@ -62,21 +64,13 @@
self
end
def register_logging_context
# arrange for child's name to appear in log messages
- Log4r::NDC.push sprintf("%-#{RFlow.logger.context_width}s", @name)
+ RFlow.logger.add_logging_context sprintf("%-#{RFlow.logger.context_width}s", @name)
end
- def clone_logging_context
- Log4r::NDC.clone_stack
- end
-
- def apply_logging_context(context)
- Log4r::NDC.inherit(context)
- end
-
def update_process_name
# set the visible process name to match the child's name
$0 += " #{@name}"
end
@@ -101,23 +95,27 @@
end
trap_signal 'SIGUSR2' do
RFlow.logger.toggle_log_level
end
+
+ trap_signal SIGINFO do
+ RFlow.logger.dump_threads
+ end
end
def unhandle_signals
- ['SIGTERM', 'SIGINT', 'SIGQUIT', 'SIGCHLD', 'SIGUSR1', 'SIGUSR2'].each do |signal|
+ ['SIGTERM', 'SIGINT', 'SIGQUIT', 'SIGCHLD', 'SIGUSR1', 'SIGUSR2', SIGINFO].each do |signal|
Signal.trap signal, 'DEFAULT'
end
end
def trap_signal(signal)
# Log4r and traps don't mix, so we need to put it in another thread
- context = clone_logging_context
+ context = RFlow.logger.clone_logging_context
Signal.trap signal do
Thread.new do
- apply_logging_context context
+ RFlow.logger.apply_logging_context context
yield
end.join
end
end
end