Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6087859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:55:05+00:00 2026-05-23T11:55:05+00:00

Synchronous logging incurs a large performance penalty as it may block. Is there a

  • 0

Synchronous logging incurs a large performance penalty as it may block. Is there a standalone Ruby library that does asynchronous logging (log4r doesn’t seem to)? Can I modify the standard library logger to log asynchronously? I’m looking for something like log4j’s AsyncAppender – but preferably an implementation that makes use of Ruby’s code blocks to shift as much work to the background thread as possible.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:55:06+00:00Added an answer on May 23, 2026 at 11:55 am

    I know you shouldn’t really answer your own question, but it seems everything is easy in ruby:

    require 'thread'
    require 'singleton'
    require 'delegate'
    require 'monitor'
    
    class Async
      include Singleton
    
      def initialize
        @queue = Queue.new
        Thread.new { loop { @queue.pop.call } }
      end
    
      def run(&blk)
        @queue.push blk
      end
    end
    
    class Work < Delegator
      include MonitorMixin
    
      def initialize(&work)
        super work; @work, @done, @lock = work, false, new_cond
      end
    
      def calc
        synchronize {
          @result, @done = @work.call, true; 
          @lock.signal
        }
      end
    
      def __getobj__
        synchronize { @lock.wait_while { !@done } }
        @result
      end
    end
    
    Module.class.class_exec {
      def async(*method_names) 
        method_names.each do |method_name|
          original_method = instance_method(method_name)
          define_method(method_name) do |*args,&blk|
            work = Work.new { original_method.bind(self).call(*args,&blk) }
            Async.instance.run { work.calc }
            return work
          end
        end
      end
    }
    

    And for my logging example:

    require 'Logger'
    class Logger
      async :debug
    end
    log = Logger.new STDOUT
    log.debug "heloo"
    

    As return values work, you can use this for just about anything:

    require "test/unit"
    class ReturnValues < Test::Unit::TestCase
      def do_it
        5 + 7
      end
      async :do_it
      def test_simple
        assert_equal 10, do_it - 2
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any difference in performance ( speed wise ) between a synchronous request
Documentation for logging module says that If you are implementing asynchronous signal handlers using
Is there a synchronous wait function that won't tie up the UI-thread in .NET
Is Javamail asynchronous or synchronous? That is, if I send off an email, do
By default, log4net is a synchronous logging mechanism, and I was wondering if there
I'm writing a synchronous method that calls an asynchronous method on another server. The
I have a synchronous web service call that returns a message. I need to
I'm looking to implement a synchronous and asynchronous version of a method within a
I wrote some naive code(in the sense that it's synchronous calls) for a tableview
Providing Synchronous and Asynchronous versions of Method in c# asks how to provide an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.