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

  • SEARCH
  • Home
  • 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 7736839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:50:44+00:00 2026-06-01T07:50:44+00:00

Is it possible to dynamically change the LogDevice of Ruby Logger ? If so,

  • 0

Is it possible to dynamically change the LogDevice of Ruby Logger?

If so, it would allow for some un-obtrusive changes to my existing codebase.

Currently Ruby Logger uses StringIO as the LogDevice:

@logDevice = StringIO.new("", "r+")
@log = Logger.new(@logDevice) // a reference to this is used by many objects
// both are instance vars

...

@log.info('some log') // Logging activity

...

// Before program ends, transmit logs to a server

Can LogDevice be dynamically changed to continue logging to a file?
(dynamic change because initially the filename is not known.)

Or if log device cannot be change can the StringIO object start writing to a file?

Instead of doing the above, I could write to a temporary log file, but wanted to check if the above can be done because it would be a less obstrusive change to the existing codebase.

  • 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-01T07:50:45+00:00Added an answer on June 1, 2026 at 7:50 am

    The object you give to the logger just has to implement the ‘write’ and ‘close’ methods, so you can easily write your own ‘io’:

    class MyIO
      def initialize
        @file = nil
        @history = StringIO.new "", "w"
      end
    
      def file=(filename)
        @file = File.open(filename, 'a+')
        @file.write @history.string if @history
        @history = nil
      end
    
      def write(data)
        @history.write(data) if @history
        @file.write(data) if @file
      end
    
      def close
        @file.close if @file
      end
    

    end

    create the logger with an instance of that and keep a reference to the instance. Then, whenever you know the filename, just set it with the ‘file=’ method.

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

Sidebar

Related Questions

Is it possible to make changes to a CSS rule-set dynamically (i.e. some JS
Possible Duplicate: change layout and template in zend dynamically according to the device(android tab,iphone,ipad)
Is it possible to dynamically change the masterpage on the whole project dependent on
Without inherit but only with reflection is it possible to dynamically change the code
Is it possible to dynamically change a JsonStore's model in Sencha Touch, I've tried
Is it possible to have vector shapes and dynamically change the background image by
I’m having some difficulties trying to dynamically change an image. <a href=#no-reload id=dropMenuButton49 class=dropMenuButton>
Is it possible to dynamically change the loaded stylesheet for a ckeditor instance? i.e.
Is it possible to dynamically ( not in the project's options) change the dimensions
I was wondering if it was possible to change text dynamically in jQuery. I

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.