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 8584775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:51:05+00:00 2026-06-11T21:51:05+00:00

I want to write in simple logger for my that puts messages in memory

  • 0

I want to write in simple logger for my that puts messages in memory and, in background, every X seconds write it to a database.

Here is the buffered logger code:

module BufferedLogger
  def buffer
    @buffer ||= []
  end

  def log( message )
    buffer << message
  end

  def write_buffer  
    while message = buffer.shift do 
      # save the message in nosql
    end
  end

  def repeat_every( interval )
    Thread.new do
      loop do
        start_time = Time.now
        yield
        elapsed = Time.now - start_time
        sleep([interval - elapsed, 0].max)
      end
    end
  end

  extend self

  thread = repeat_every(10) do
    write_buffer
  end 

end

In development, this works fine, buffer() access to the same @buffer var in both log and write_buffer method. But as soon as I go to production or staging env, i.e. as soon as I’m behind passenger, this @buffer don’t seem to be shared anymore.

Any pointer?

  • 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-06-11T21:51:06+00:00Added an answer on June 11, 2026 at 9:51 pm

    Since passenger create separate process, and how these process will persists depends on passenger’s algorithm, I guess it will not work well as you expect. (btw, I had bad experience in this regard using global variables/class variables.)

    My suggestion to buffer the log is, use logger like fluentd as intermediate processor. Fluentd can monitor and gather the log. You can write a plugin to write the collected log to DB. I think this will suit your needs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a simple web proxy, for exercise. Here's the code I
I want to write a simple regular expression in Python that extracts a number
I want to write a simple task which will update and commit source code
I want to write a simple media player which displays lyrics that are retrieved
I want write a simple query which will fetch data from a table (which
I want to write simple script to copy/backup directory then remove on server startup.
I'm new to Java programming. I want to write simple Java network protocol. I
I want to write a simple chat application (for test use). The users and
I want to write a simple applet to put in a tray. Let's say
I want to write a simple web framework myself using WSGI, Python. I am

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.