Re: log4j questions
Re: log4j questions
- Subject: Re: log4j questions
- From: William Hatch <email@hidden>
- Date: Tue, 14 Sep 2004 13:23:51 -0400
After following Jean-Francois's excellent (thank you) advice below, I now
have the following code:
In Application.java
Logger appLogger;
//constructor ...
WOResourceManager rm = resourceManager();
java.net.URL url = rm.pathURLForResourceNamed("log4j.properties", null,
null);
if (url != null) {
String log4jConfigFilePath = url.toString();
PropertyConfigurator.configureAndWatch(log4jConfigFilePath,
5);
appLogger = Logger.getLogger("appLogger");
appLogger.setAdditivity(false);
In Application's appendToResponse
appLogger.debug("Debug");
appLogger.info("Info");
appLogger.warn("Warn");
appLogger.error("Error");
appLogger.fatal("Fatal");
super.appendToResponse(r, c);
In log4j.properties
log4j.rootCategory=INFO, appAppender
log4j.appender.appAppender=org.apache.log4j.ConsoleAppender
log4j.appender.appAppender.layouot=org.apache.log4j.PatternLayout
log4j.appender.appAppender.layout.ConversionPattern=%-4r [%t] %-5p %c %x -
%m%n
Now, when I run the application I always get everything from info and up,
but never debug and it doesn't use the Conversion Patter specified in the
properties file. It seems as if the file is not being picked up, but when
checking the url with System.out.... It prints the correct path/url. The
properties file was added to the appserver target. What the heck am I still
doing wrong?
Jean-François Veillette9/10/04 2:25 email@hidden
> I have never done my log4j in my code as you do, but here is what I
> have in my application constructor.
>
> // <Log4J setup ...>
> WOResourceManager rm = resourceManager();
> java.net.URL url = rm.pathURLForResourceNamed("log4j.properties",
> null, null);
> if (url != null) {
> String log4jConfigFilePath = url.toString();
> PropertyConfigurator.configureAndWatch(log4jConfigFilePath,
> 5);
> }
> // </Log4J setup ...>
>
> as you can see, I ask the PropertyConfigurator to watch my config file
> so that changes get picked up. I don't know if it _has_ to be that
> way, but it's working, at run-time, I can change a log4j properties in
> that file, and the change is automatically picked-up.
>
> - jfv
>
> Le 04-09-10, à 14:16, William Hatch a écrit :
>
>> Sako!9/10/04 1:58 email@hidden
>>
>>> You start ur application,
>>> You change the level.
>>> No changes happens.
>>> You do that in this sequence?
>>>
>>
>> Yes, that's exactly right. I run the app, make some changes to the
>> properties file and no changes happen; I still get info and up.
>>>
>>> ----- Original Message -----
>>> From: "William Hatch" <email@hidden>
>>> To: "Apple WO-Dev" <email@hidden>
>>> Sent: Friday, September 10, 2004 7:41 PM
>>> Subject: log4j questions
>>>
>>>
>>>> Hi, I'm just converting my logging to log4j and have a few questions.
>>> I've
>>>> created a log4j.properties file and added it to the appserver
>>>> target. I
>>> get
>>>> console output as expected, but any changes I make to the properties
>>>> file
>>>> during run (in development mode) don't seem to change anything; I'm
>>>> starting simple and tried changing the levels from "info" to "debug"
>>>> etc,
>>>> but it stays at info no matter what, which leads me to believe that
>>>> the
>>>> properties file isn't be read. Here's what I have in the Application
>>> class:
>>>>
>>>> Logger appLogger;
>>>> Appender appAppender;
>>>> SimpleLayout appLayout;
>>>>
>>>> In main of the Application class, I have:
>>>>
>>>> PropertyConfigurator.configure(argv[0]); //not at all sure about
>>>> this
>>> here
>>>>
>>>> And then in the Application constructor I have:
>>>>
>>>> //instantiate logger, appender, and layout
>>>> appLayout = new SimpleLayout();
>>>> appAppender = new ConsoleAppender(appLayout);
>>>> AppLogger = Logger.getLogger("appLogger");
>>>> appLogger.addAppender(appAppender);
>>>>
>>>>
>>>> In the log4j.properties file I have (probably wrongly)
>>>>
>>>> log4j.rootAppender=WARN, appAppender
>>>>
>>>> So now the questions:
>>>>
>>>> (1) I feel like my properties is probably wrong. If it is, what is
>>> wrong?
>>>>
>>>> (2) Getting past number 1, how do you change these properties at
>>>> runtime?
>>>> Using the "Additional Arguments" in Monitor, directly editing the
>>>> .properties file, or some CLI way?
>>>>
>>>> Sorry for the basic questions and thanks for any suggestions.
>>>> --
>>>> William Hatch
>>>> Eng. Visual Media Collection
>>>> Cornell Lab of Ornithology
>>>> Macaulay Library
>>>> Voice (607) 254-2116
>>>> Fax (607) 254-2439
>>>> _______________________________________________
>>>> webobjects-dev mailing list | email@hidden
>>>> Help/Unsubscribe/Archives:
>>> http://www.lists.apple.com/mailman/listinfo/webobjects-dev
>>>> Do not post admin requests to the list. They will be ignored.
>>>>
>>>>
>>>
>>
>> --
>> William Hatch
>> Eng. Visual Media Collection
>> Cornell Lab of Ornithology
>> Macaulay Library
>> Voice (607) 254-2116
>> Fax (607) 254-2439
>> _______________________________________________
>> webobjects-dev mailing list | email@hidden
>> Help/Unsubscribe/Archives:
>> http://www.lists.apple.com/mailman/listinfo/webobjects-dev
>> Do not post admin requests to the list. They will be ignored.
>>
>
--
William Hatch
Eng. Visual Media Collection
Cornell Lab of Ornithology
Macaulay Library
Voice (607) 254-2116
Fax (607) 254-2439
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden