# Ruby's Logger conflict with Log4r's Logger

**URL:** <https://www.ruby-forum.com/t/rubys-logger-conflict-with-log4rs-logger/49973>\
**Category:** Ruby\
**Created:** [December 11, 2005, 9:53am UTC](https://www.ruby-forum.com/t/rubys-logger-conflict-with-log4rs-logger/49973 "2005-12-11T09:53:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![capitain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/54ee81/32.png) [@capitain](https://www.ruby-forum.com/u/capitain)\
**Post date:** [December 11, 2005, 9:53am UTC](https://www.ruby-forum.com/t/rubys-logger-conflict-with-log4rs-logger/49973/1 "2005-12-11T09:53:03Z")

</div>

Both of them has a class named “Logger”

I used to include Log4r in my code so I can use Logger as a shortcut of  
Log4r::Logger .  
It works ok when useing “Logger[name]” to get logger

Today I add the library “bluecloth” to my application. I found that  
when requiring bluecloth,BlueCloth required ‘logger’ in its  
“bluecloth.rb”, So Ruby’s internal Logger class overwrite the  
Log4r::Logger in context, and doing ‘include Log4r’ again didn’t make  
the Logger turn back. The Logger is always ruby’s internal Logger and  
mine "Logger[name]’ can’t execute now (maybe the priority of “include  
Log4r” is less than “require ‘logger’ ?”)

Is there any solution except replacing every “Logger” to  
“Log4r::Logger” in my code?

---

<div class="post-metadata">

**Author:** ![capitain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/54ee81/32.png) [@capitain](https://www.ruby-forum.com/u/capitain)\
**Post date:** [December 11, 2005, 12:24pm UTC](https://www.ruby-forum.com/t/rubys-logger-conflict-with-log4rs-logger/49973/2 "2005-12-11T12:24:26Z")

</div>

On Sunday 11 December 2005 09:52, cap wrote:

> Both of them has a class named “Logger”
> 
> I used to include Log4r in my code so I can use Logger as a  
> shortcut of Log4r::Logger .  
> It works ok when useing “Logger[name]” to get logger

I know it doesn’t help now: As a general suggestion: Never  
include a module at the top level only to get shorter names!

Ruby’s include is _not_ like “import” in Java or “using” in  
C# or “from xy import \*” in Python.

> Today I add the library “bluecloth” to my application. I found that  
> when requiring bluecloth,BlueCloth required ‘logger’ in its  
> “bluecloth.rb”, So Ruby’s internal Logger class overwrite the  
> Log4r::Logger in context, and doing ‘include Log4r’ again didn’t  
> make the Logger turn back. The Logger is always ruby’s internal  
> Logger and mine "Logger[name]’ can’t execute now (maybe the  
> priority of “include Log4r” is less than “require ‘logger’ ?”)
> 
> Is there any solution except replacing every “Logger” to  
> “Log4r::Logger” in my code?

If it is possible to wrap your code in a module:

```
module MyNamespace
    include Log4r

     # Now Logger will always reference Log4r::Logger
end

```

Or even better:

```
module MyNamespace
    # don't include other Log4r methods and constants,
    # just create a shortcut for Log4r::Logger
    Logger = Log4r::Logger

    # define classes, modules, ...
end

```

Regards,  
Stefan

---

<div class="post-metadata">

**Author:** ![capitain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/54ee81/32.png) [@capitain](https://www.ruby-forum.com/u/capitain)\
**Post date:** [December 11, 2005, 4:36pm UTC](https://www.ruby-forum.com/t/rubys-logger-conflict-with-log4rs-logger/49973/3 "2005-12-11T16:36:10Z")

</div>

thanks for your help , I prefer the second way 🙂

---

<div class="post-metadata">

**Author:** ![capitain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/54ee81/32.png) [@capitain](https://www.ruby-forum.com/u/capitain)\
**Post date:** [December 11, 2005, 5:08pm UTC](https://www.ruby-forum.com/t/rubys-logger-conflict-with-log4rs-logger/49973/4 "2005-12-11T17:08:36Z")

</div>

On Dec 11, 2005, at 2:52 AM, cap wrote:

> Log4r::Logger in context, and doing ‘include Log4r’ again didn’t make  
> the Logger turn back. The Logger is always ruby’s internal Logger and  
> mine "Logger[name]’ can’t execute now (maybe the priority of “include  
> Log4r” is less than “require ‘logger’ ?”)
> 
> Is there any solution except replacing every “Logger” to  
> “Log4r::Logger” in my code?

Sure, what about doing something like this:

# …

require “bluecloth”  
Logger = Log4r::Logger

# …

James Edward G. II
