diff --git a/async.gemspec b/async.gemspec index 9d7412d1..ae7b6f01 100644 --- a/async.gemspec +++ b/async.gemspec @@ -25,7 +25,7 @@ Gem::Specification.new do |spec| spec.required_ruby_version = ">= 3.1.1" - spec.add_dependency "console", "~> 1.10" + spec.add_dependency "console", ["~> 1.25", ">= 1.25.2"] spec.add_dependency "fiber-annotation" spec.add_dependency "io-event", ["~> 1.5", ">= 1.5.1"] spec.add_dependency "timers", "~> 4.1" diff --git a/examples/capture/capture.rb b/examples/capture/capture.rb index ccbd619a..4df41f3f 100755 --- a/examples/capture/capture.rb +++ b/examples/capture/capture.rb @@ -83,7 +83,7 @@ def strace(pid, duration = 60) _, status = Process.waitpid2(pid) - Console.logger.error(status) do |buffer| + Console.error(status) do |buffer| buffer.puts first_line end unless status.success? @@ -92,28 +92,28 @@ def strace(pid, duration = 60) pids.each do |pid| start_times = getrusage(pid) - Console.logger.info("Process #{pid} start times:", start_times) + Console.info("Process #{pid} start times:", start_times) # sleep 60 summary = strace(pid) - Console.logger.info("strace -p #{pid}") do |buffer| + Console.info("strace -p #{pid}") do |buffer| summary.each do |fields| buffer.puts fields.inspect end end end_times = getrusage(pid) - Console.logger.info("Process #{pid} end times:", end_times) + Console.info("Process #{pid} end times:", end_times) if total = summary[:total] process_duration = end_times.utime - start_times.utime wait_duration = summary[:total][:seconds] - Console.logger.info("Process Waiting: #{wait_duration.round(4)}s out of #{process_duration.round(4)}s") do |buffer| + Console.info("Process Waiting: #{wait_duration.round(4)}s out of #{process_duration.round(4)}s") do |buffer| buffer.puts "Wait percentage: #{(wait_duration / process_duration * 100.0).round(2)}%" end else - Console.logger.warn("No system calls detected.") + Console.warn("No system calls detected.") end end diff --git a/examples/hup-test/child.rb b/examples/hup-test/child.rb index a98c4f1f..171647ff 100755 --- a/examples/hup-test/child.rb +++ b/examples/hup-test/child.rb @@ -10,7 +10,7 @@ Async do |task| while true task.async do - Console.logger.info("Child running.") + Console.info("Child running.") sleep 0.1 end.wait end diff --git a/examples/hup-test/main.rb b/examples/hup-test/main.rb index 3a989431..b3851bcd 100755 --- a/examples/hup-test/main.rb +++ b/examples/hup-test/main.rb @@ -8,10 +8,10 @@ while true pid = Process.spawn("./child.rb") - Console.logger.info("Spawned child.", pid: pid) + Console.info("Spawned child.", pid: pid) sleep 2 - Console.logger.info("Sending HUP to child.", pid: pid) + Console.info("Sending HUP to child.", pid: pid) Process.kill(:HUP, pid) status = Process.waitpid(pid) - Console.logger.info("Child exited.", pid: pid, status: status) + Console.info("Child exited.", pid: pid, status: status) end diff --git a/guides/event-loop/readme.md b/guides/event-loop/readme.md index e9f02c16..bc2a8225 100644 --- a/guides/event-loop/readme.md +++ b/guides/event-loop/readme.md @@ -49,7 +49,7 @@ Most methods of the reactor and related tasks are not thread-safe, so you'd typi ~~~ ruby require 'async' -Console.logger.debug! +Console.debug! reactor = Async::Reactor.new # Run the reactor for 1 second: diff --git a/lib/async/barrier.md b/lib/async/barrier.md index d20667c7..13fe102a 100644 --- a/lib/async/barrier.md +++ b/lib/async/barrier.md @@ -9,7 +9,7 @@ require 'async/barrier' barrier = Async::Barrier.new Sync do - Console.logger.info("Barrier Example: sleep sort.") + Console.info("Barrier Example: sleep sort.") # Generate an array of 10 numbers: numbers = 10.times.map{rand(10)} @@ -26,7 +26,7 @@ Sync do # Wait for all the numbers to be sorted: barrier.wait - Console.logger.info("Sorted", sorted) + Console.info("Sorted", sorted) ensure # Ensure all the tasks are stopped when we exit: barrier.stop diff --git a/lib/async/condition.md b/lib/async/condition.md index 5d9b3072..d853a178 100644 --- a/lib/async/condition.md +++ b/lib/async/condition.md @@ -9,14 +9,14 @@ Sync do condition = Async::Condition.new Async do - Console.logger.info "Waiting for condition..." + Console.info "Waiting for condition..." value = condition.wait - Console.logger.info "Condition was signalled: #{value}" + Console.info "Condition was signalled: #{value}" end Async do |task| task.sleep(1) - Console.logger.info "Signalling condition..." + Console.info "Signalling condition..." condition.signal("Hello World") end end diff --git a/lib/async/scheduler.rb b/lib/async/scheduler.rb index 3b2703f1..8a5bdd4f 100644 --- a/lib/async/scheduler.rb +++ b/lib/async/scheduler.rb @@ -369,7 +369,7 @@ def run(...) return initial_task ensure - Console.logger.debug(self) {"Exiting run-loop because #{$! ? $! : 'finished'}."} + Console.debug(self) {"Exiting run-loop because #{$! ? $! : 'finished'}."} end # Start an asynchronous task within the specified reactor. The task will be @@ -395,7 +395,7 @@ def async(*arguments, **options, &block) # - Avoid scheduler overhead if no blocking operation is performed. task.run(*arguments) - # Console.logger.debug "Initial execution of task #{fiber} complete (#{result} -> #{fiber.alive?})..." + # Console.debug "Initial execution of task #{fiber} complete (#{result} -> #{fiber.alive?})..." return task end diff --git a/lib/async/semaphore.md b/lib/async/semaphore.md index 38ee4630..2524693d 100644 --- a/lib/async/semaphore.md +++ b/lib/async/semaphore.md @@ -17,9 +17,9 @@ Sync do # Search for the terms: terms.each do |term| semaphore.async do |task| - Console.logger.info("Searching for #{term}...") + Console.info("Searching for #{term}...") response = Net::HTTP.get(URI "https://www.google.com/search?q=#{term}") - Console.logger.info("Got response #{response.size} bytes.") + Console.info("Got response #{response.size} bytes.") end end end diff --git a/lib/async/task.rb b/lib/async/task.rb index 97a6f00d..c38d6470 100644 --- a/lib/async/task.rb +++ b/lib/async/task.rb @@ -8,6 +8,7 @@ # Copyright, 2023, by Math Ieu. require 'fiber' +require 'console/event/failure' require_relative 'node' require_relative 'condition' @@ -335,15 +336,15 @@ def failed!(exception = false, propagate = true) raise exception elsif @finished.nil? # If no one has called wait, we log this as a warning: - Console.logger.warn(self, "Task may have ended with unhandled exception.", exception) + Console::Event::Failure.for(exception).emit(self, "Task may have ended with unhandled exception.", severity: :warn) else - Console.logger.debug(self, exception) + Console::Event::Failure.for(exception).emit(self, severity: :debug) end end end def stopped! - # Console.logger.info(self, status:) {"Task #{self} was stopped with #{@children&.size.inspect} children!"} + # Console.info(self, status:) {"Task #{self} was stopped with #{@children&.size.inspect} children!"} @status = :stopped stopped = false @@ -374,7 +375,7 @@ def schedule(&block) begin completed!(yield) - # Console.logger.debug(self) {"Task was completed with #{@children.size} children!"} + # Console.debug(self) {"Task was completed with #{@children.size} children!"} rescue Stop stopped! rescue StandardError => error @@ -382,7 +383,7 @@ def schedule(&block) rescue Exception => exception failed!(exception, true) ensure - # Console.logger.info(self) {"Task ensure $! = #{$!} with #{@children&.size.inspect} children!"} + # Console.info(self) {"Task ensure $! = #{$!} with #{@children&.size.inspect} children!"} finish! end end diff --git a/lib/async/waiter.md b/lib/async/waiter.md index e5d49dc2..3a1270cb 100644 --- a/lib/async/waiter.md +++ b/lib/async/waiter.md @@ -38,7 +38,7 @@ Sync do # Stop all tasks which we don't care about: barrier.stop - Console.logger.info("Smallest", numbers) + Console.info("Smallest", numbers) end ~~~ diff --git a/test/async/task.rb b/test/async/task.rb index 82d5c7b8..850e18e2 100644 --- a/test/async/task.rb +++ b/test/async/task.rb @@ -761,7 +761,7 @@ def sleep_forever expect(task.result).to be_nil - Console.logger.debug(self) {"Stopping task..."} + Console.debug(self) {"Stopping task..."} task.stop expect(task.result).to be_nil diff --git a/test/kernel/sync.rb b/test/kernel/sync.rb index ce2948f5..8851d555 100644 --- a/test/kernel/sync.rb +++ b/test/kernel/sync.rb @@ -36,7 +36,7 @@ end it "can propagate error without logging them" do - expect(Console.logger).not.to receive(:error) + expect(Console).not.to receive(:error) expect do Sync do