You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Jacob Kjome <ho...@visi.com> on 2009/04/11 06:36:58 UTC
Re: Beginners question: log4j implementation, variable log4j properties
Please don't post user questions to the dev list. I've sent this to the user
list, Bcc'ing the dev list, just in case you are not subscribed to the user list
yet. See comments below...
On 4/10/2009 7:03 AM, mb77 wrote:
> Hello everybody,
>
> Beginners question here, hope all will be clear enough and log4j specific
> enough.
>
> I'm co-building an application that consists of around thirty java classes
> that all use log4j.
> We have a class called MyLogger.java that is imported by all these classes.
> In MyLogger we have this line :
> public static final org.apache.log4j.Logger log =
> Logger.getLogger("MyLogger.class");
>
> We use a log4jproperties file for now ,but the finished application will
> take care that every user's log4j properties are read from his/her own
> inifile (using PropertyConfigurator). At a certain point in our code we
> determine which user we are dealing with , but until that time we would like
> to use a default inifile.
>
> As stated above , the logging object is created like this:
> public static final org.apache.log4j.Logger log =
> Logger.getLogger(RemLogger.class);
> As far as i understand this object is created the first time one of our
> classes imports the MyLogger class.
>
> Would it be possible somehow to tweak this code so that the constructor of
> MyLogger is called?
No. All that happens when you pass a class into getLogger() is it gets the name
of the class by calling Class.getName().
> In the constructor i would place something like this:
> URL url = Loader.getResource("default.ini");
> PropertyConfigurator.configure(url);
I really don't recommend that. General application code should not perform
configuration. Leave that to specialized startup classes. Either place
log4j.properties or log4j.xml in the root of the classpath for Log4j
auto-configuration or run manual configuration from something like a
ServletContextListener or a Main class.
You will find nothing but grief by reconfiguring the current logger repository
(generally the default one unless you are using repository selector.... which I
bet you are not) multiple times as you think you want; once per ever time you call
Logger.getLogger(SomeClass.class). You'll end up doubling up appenders, getting
duplicate, triplicate, quadruplicate, etc... logging.
Remember. It is not really the job of the library developer to decide which stuff
gets logged. It is the application deployer (possibly in consulation with
developers). Individual libraries my provide information by logging it, but it's
the person(s) who read the log that ought to control what actually gets logged.
>
> Hope i made my question clear and would appreciate any help immensely!!
> Thanks in advance,
> Mark
>
>
Jake
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: Hibernate and Logback
Posted by Jacob Kjome <ho...@visi.com>.
I'm glad you figured out issue out, but I suggest two things:
1. Please don't email developers directly, only the list. While you did send to
the list, you CC'd my individual email. That's bad form.
2. Unless your issue is with Log4j, you probably shouldn't be posting the Log4j
user list. You state that your issue is with Logback. Logback is *not* part of
the Log4j project. I suggest that you post to Logback's user list for Logback
related issues in the future.
Jake
On 4/10/2009 11:59 PM, Joe White wrote:
>
>
> I figured it out.
>
> <logger name="org.hibernate">
> <level value="error"/>
> <appender-ref ref="FILE"/>
> </logger>
>
> Quoting Joe White <jw...@asidejob.com>:
>
>>
>>
>> I'm using Hibernate with logback, and it appears that Hibernate is
>> stuck in DEBUG logging mode. The documentation states that it works
>> (Hibernate that is) with logback, but I don't know how to turn it to
>> error only.
>>
>> Here is my logback.xml file.
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <configuration>
>>
>> <appender name="FILE" class="ch.qos.logback.core.FileAppender">
>> <file>myApp.log</file>
>>
>> <layout class="ch.qos.logback.classic.PatternLayout">
>> <Pattern>%date %level [%thread] %logger{10} [%file:%line]
>> %msg%n</Pattern>
>> </layout>
>> </appender>
>>
>> <appender name="STDOUT"
>> class="ch.qos.logback.core.ConsoleAppender">
>> <layout class="ch.qos.logback.classic.PatternLayout">
>> <Pattern>%msg%n</Pattern>
>> </layout>
>> </appender>
>>
>> <root level="info">
>> <appender-ref ref="FILE" />
>> <appender-ref ref="STDOUT" />
>> </root>
>> </configuration>
>
> --
> "We are what we repeatedly do. Excellence, then, is not an act, but a
> habit."
> Aristotle
>
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: Hibernate and Logback
Posted by Joe White <jw...@asidejob.com>.
I figured it out.
<logger name="org.hibernate">
<level value="error"/>
<appender-ref ref="FILE"/>
</logger>
Quoting Joe White <jw...@asidejob.com>:
>
>
> I'm using Hibernate with logback, and it appears that Hibernate is
> stuck in DEBUG logging mode. The documentation states that it works
> (Hibernate that is) with logback, but I don't know how to turn it to
> error only.
>
> Here is my logback.xml file.
>
> <?xml version="1.0" encoding="UTF-8"?>
> <configuration>
>
> <appender name="FILE" class="ch.qos.logback.core.FileAppender">
> <file>myApp.log</file>
>
> <layout class="ch.qos.logback.classic.PatternLayout">
> <Pattern>%date %level [%thread] %logger{10} [%file:%line]
> %msg%n</Pattern>
> </layout>
> </appender>
>
> <appender name="STDOUT"
> class="ch.qos.logback.core.ConsoleAppender">
> <layout class="ch.qos.logback.classic.PatternLayout">
> <Pattern>%msg%n</Pattern>
> </layout>
> </appender>
>
> <root level="info">
> <appender-ref ref="FILE" />
> <appender-ref ref="STDOUT" />
> </root>
> </configuration>
--
"We are what we repeatedly do. Excellence, then, is not an act, but a habit."
Aristotle
Hibernate and Logback
Posted by Joe White <jw...@asidejob.com>.
I'm using Hibernate with logback, and it appears that Hibernate is
stuck in DEBUG logging mode. The documentation states that it works
(Hibernate that is) with logback, but I don't know how to turn it to
error only.
Here is my logback.xml file.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>myApp.log</file>
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%date %level [%thread] %logger{10} [%file:%line]
%msg%n</Pattern>
</layout>
</appender>
<appender name="STDOUT"
class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%msg%n</Pattern>
</layout>
</appender>
<root level="info">
<appender-ref ref="FILE" />
<appender-ref ref="STDOUT" />
</root>
</configuration>