diff --git a/examples/container.rb b/examples/container.rb index 50e8233..55e9217 100755 --- a/examples/container.rb +++ b/examples/container.rb @@ -12,16 +12,16 @@ container = Async::Container.new -Console.logger.debug "Spawning 2 containers..." +Console.debug "Spawning 2 containers..." 2.times do container.spawn do |task| - Console.logger.debug task, "Sleeping..." + Console.debug task, "Sleeping..." sleep(2) - Console.logger.debug task, "Waking up!" + Console.debug task, "Waking up!" end end -Console.logger.debug "Waiting for container..." +Console.debug "Waiting for container..." container.wait -Console.logger.debug "Finished." +Console.debug "Finished." diff --git a/examples/controller.rb b/examples/controller.rb index 992f083..afc5db3 100755 --- a/examples/controller.rb +++ b/examples/controller.rb @@ -11,9 +11,9 @@ class Controller < Async::Container::Controller def setup(container) container.run(count: 1, restart: true) do |instance| if container.statistics.failed? - Console.logger.debug(self, "Child process restarted #{container.statistics.restarts} times.") + Console.debug(self, "Child process restarted #{container.statistics.restarts} times.") else - Console.logger.debug(self, "Child process started.") + Console.debug(self, "Child process started.") end instance.ready! @@ -21,10 +21,10 @@ def setup(container) while true sleep 1 - Console.logger.debug(self, "Work") + Console.debug(self, "Work") if rand < 0.5 - Console.logger.debug(self, "Should exit...") + Console.debug(self, "Should exit...") sleep 0.5 exit(1) end @@ -35,7 +35,7 @@ def setup(container) Console.logger.debug! -Console.logger.debug(self, "Starting up...") +Console.debug(self, "Starting up...") controller = Controller.new diff --git a/guides/getting-started/readme.md b/guides/getting-started/readme.md index a9c6cb4..04ca895 100644 --- a/guides/getting-started/readme.md +++ b/guides/getting-started/readme.md @@ -29,14 +29,14 @@ Console.logger.debug! container = Async::Container.new container.spawn do |task| - Console.logger.debug task, "Sleeping..." + Console.debug task, "Sleeping..." sleep(1) - Console.logger.debug task, "Waking up!" + Console.debug task, "Waking up!" end -Console.logger.debug "Waiting for container..." +Console.debug "Waiting for container..." container.wait -Console.logger.debug "Finished." +Console.debug "Finished." ``` ## Controllers @@ -58,7 +58,7 @@ class Controller < Async::Container::Controller def setup(container) container.run count: 2, restart: true do |instance| while true - Console.logger.debug(instance, "Sleeping...") + Console.debug(instance, "Sleeping...") sleep(1) end end diff --git a/lib/async/container/controller.rb b/lib/async/container/controller.rb index 05618d6..055f2e9 100644 --- a/lib/async/container/controller.rb +++ b/lib/async/container/controller.rb @@ -109,9 +109,9 @@ def restart if @container @notify&.restarting! - Console.logger.debug(self) {"Restarting container..."} + Console.debug(self) {"Restarting container..."} else - Console.logger.debug(self) {"Starting container..."} + Console.debug(self) {"Starting container..."} end container = self.create_container @@ -125,9 +125,9 @@ def restart end # Wait for all child processes to enter the ready state. - Console.logger.debug(self, "Waiting for startup...") + Console.debug(self, "Waiting for startup...") container.wait_until_ready - Console.logger.debug(self, "Finished startup.") + Console.debug(self, "Finished startup.") if container.failed? @notify&.error!("Container failed to start!") @@ -143,7 +143,7 @@ def restart container = nil if old_container - Console.logger.debug(self, "Stopping old container...") + Console.debug(self, "Stopping old container...") old_container&.stop(@graceful_stop) end @@ -157,7 +157,7 @@ def restart def reload @notify&.reloading! - Console.logger.info(self) {"Reloading container: #{@container}..."} + Console.info(self) {"Reloading container: #{@container}..."} begin self.setup(@container) @@ -166,11 +166,11 @@ def reload end # Wait for all child processes to enter the ready state. - Console.logger.debug(self, "Waiting for startup...") + Console.debug(self, "Waiting for startup...") @container.wait_until_ready - Console.logger.debug(self, "Finished startup.") + Console.debug(self, "Finished startup.") if @container.failed? @notify.error!("Container failed to reload!") @@ -210,7 +210,7 @@ def run begin handler.call rescue SetupError => error - Console.logger.error(self) {error} + Console.error(self) {error} end else raise diff --git a/lib/async/container/generic.rb b/lib/async/container/generic.rb index 881e379..bf78d13 100644 --- a/lib/async/container/generic.rb +++ b/lib/async/container/generic.rb @@ -104,7 +104,7 @@ def status?(flag) # @returns [Boolean] The children all became ready. def wait_until_ready while true - Console.logger.debug(self) do |buffer| + Console.debug(self) do |buffer| buffer.puts "Waiting for ready:" @state.each do |child, state| buffer.puts "\t#{child.class}: #{state.inspect}" @@ -126,7 +126,7 @@ def stop(timeout = true) @group.stop(timeout) if @group.running? - Console.logger.warn(self) {"Group is still running after stopping it!"} + Console.warn(self) {"Group is still running after stopping it!"} end ensure @running = true @@ -140,7 +140,7 @@ def spawn(name: nil, restart: false, key: nil, &block) name ||= UNNAMED if mark?(key) - Console.logger.debug(self) {"Reusing existing child for #{key}: #{name}"} + Console.debug(self) {"Reusing existing child for #{key}: #{name}"} return false end @@ -161,10 +161,10 @@ def spawn(name: nil, restart: false, key: nil, &block) end if status.success? - Console.logger.debug(self) {"#{child} exited with #{status}"} + Console.debug(self) {"#{child} exited with #{status}"} else @statistics.failure! - Console.logger.error(self) {status} + Console.error(self) {status} end if restart diff --git a/lib/async/container/group.rb b/lib/async/container/group.rb index 5256891..7d28d1a 100644 --- a/lib/async/container/group.rb +++ b/lib/async/container/group.rb @@ -65,7 +65,7 @@ def wait # Interrupt all running processes. # This resumes the controlling fiber with an instance of {Interrupt}. def interrupt - Console.logger.debug(self, "Sending interrupt to #{@running.size} running processes...") + Console.debug(self, "Sending interrupt to #{@running.size} running processes...") @running.each_value do |fiber| fiber.resume(Interrupt) end @@ -74,7 +74,7 @@ def interrupt # Terminate all running processes. # This resumes the controlling fiber with an instance of {Terminate}. def terminate - Console.logger.debug(self, "Sending terminate to #{@running.size} running processes...") + Console.debug(self, "Sending terminate to #{@running.size} running processes...") @running.each_value do |fiber| fiber.resume(Terminate) end diff --git a/lib/async/container/notify/pipe.rb b/lib/async/container/notify/pipe.rb index 920585a..5c0b4f2 100644 --- a/lib/async/container/notify/pipe.rb +++ b/lib/async/container/notify/pipe.rb @@ -22,7 +22,7 @@ def self.open!(environment = ENV) self.new(::IO.for_fd(descriptor.to_i)) end rescue Errno::EBADF => error - Console.logger.error(self) {error} + Console.error(self) {error} return nil end diff --git a/lib/async/container/process.rb b/lib/async/container/process.rb index e40dfff..d05f4c7 100644 --- a/lib/async/container/process.rb +++ b/lib/async/container/process.rb @@ -74,7 +74,7 @@ def self.fork(**options) rescue Interrupt # Graceful exit. rescue Exception => error - Console.logger.error(self) {error} + Console.error(self) {error} exit!(1) end @@ -160,7 +160,7 @@ def wait end if @status.nil? - Console.logger.warn(self) {"Process #{@pid} is blocking, has it exited?"} + Console.warn(self) {"Process #{@pid} is blocking, has it exited?"} _, @status = ::Process.wait2(@pid) end end diff --git a/lib/async/container/thread.rb b/lib/async/container/thread.rb index a87d2f3..d0310b2 100644 --- a/lib/async/container/thread.rb +++ b/lib/async/container/thread.rb @@ -188,7 +188,7 @@ def to_s # Invoked by the @waiter thread to indicate the outcome of the child thread. def finished(error = nil) if error - Console.logger.error(self) {error} + Console.error(self) {error} end @status = Status.new(error)