# How to instantiate a logger in an Engine only once and then use only that object?

**URL:** <https://www.ruby-forum.com/t/how-to-instantiate-a-logger-in-an-engine-only-once-and-then-use-only-that-object/235337>\
**Category:** Rails\
**Created:** [June 14, 2013, 10:15am UTC](https://www.ruby-forum.com/t/how-to-instantiate-a-logger-in-an-engine-only-once-and-then-use-only-that-object/235337 "2013-06-14T10:15:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![alcina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@alcina](https://www.ruby-forum.com/u/alcina)\
**Post date:** [June 14, 2013, 10:15am UTC](https://www.ruby-forum.com/t/how-to-instantiate-a-logger-in-an-engine-only-once-and-then-use-only-that-object/235337/1 "2013-06-14T10:15:02Z")

</div>

I found this old thread: [How to set logging level for Rails Engines - Engines - Ruby-Forum](http://www.ruby-forum.com/topic/151906)

One commentator says:

> To minimize engines polluting our logs, we just changed the logger for  
> the engines plugin like this:

> In engines.rb, update the logger method:

> def logger  
> #RAILS\_DEFAULT\_LOGGER  
> Logger.new(RAILS\_ROOT + “/log/engines.log”)  
> end

> And then create an “engines.log” under your /log directory. Now all  
> engines related logging will be directed to that file instead of your  
> development.log.

My question is, how to use it then? Wouldn’t it instantiate a new Logger  
instance every time I call it?

def some\_foo\_method

# I want to log something, I call the logger method

logger.debug(“I did something”)  
end

So, the “logger” method instantiates a new Logger instance every time.  
It is not good to have dozens logger instances in memory. How to avoid  
it? How to instantiate only once and then just use that one instance?
