users@glassfish.java.net

Re: Log4j is not logging

From: Jan Luehe <Jan.Luehe_at_Sun.COM>
Date: Wed, 06 Sep 2006 13:27:06 -0700

Hi Jason,

I've taken your log4.xml, changed its log file location to "mylog.txt",
wrapped it in a JAR file, and included this JAR file in the lib directory
of my test EAR file (which also includes both commons-logging and
log4j), which I've attached.

Can you deploy the attached EAR file and then access

  http://<host>:<port>/123/TestServlet

Each access to this servlet will print a line to

  $INSTALL/domains/domain1/config/mylog.txt

The reason the file will be created in this directory is because the
startserv script in your domain's bin directory has this statement:

  cd "$INSTANCE_ROOT/config"

Of course, you may also specify an absolute log file location in
log4.xml, but I wanted the attached EAR file to work for you
out-of-the-box.

I did see mylog.txt getting created and updated even after copying the
commons-logging and log4j JAR files to my domain's lib directory
(which is what you've done).

I did notice, however, that after undeploying test.ear, changing the
log file location in log4j.xml, repackaging and redeploying test.ear,
the log messages were still getting written to the old log file. I had
to stop and restart the appserver in order for the log messages to
appear in the new location. I assume log4j stores the log file
location as a system property, but I would need to verify this.

Please try the attached test.ear and let me know.

Thanks,

Jan


Jason Lee wrote On 09/05/06 06:50,:

>Obviously, I'm doing something wrong, as logging is still not working
>for me. I have log4.[xml|properties] in $EAR/lib/logging-config.jar,
>but the logging is still going to the system log. I've bundled
>commons-logging and log4j with my app, but they are also available in
>the server's classpath. Is that going to make a difference?
>
>-----
>Jason Lee
>Programmer/Analyst
>http://www.iecokc.com
>
>
>
>
>>-----Original Message-----
>>From: Jan.Luehe_at_Sun.COM [mailto:Jan.Luehe_at_Sun.COM]
>>Sent: Wednesday, August 30, 2006 2:18 PM
>>To: users_at_glassfish.dev.java.net
>>Subject: Re: Log4j is not logging
>>
>>Jason,
>>
>>Jason Lee wrote On 08/30/06 06:24,:
>>
>>
>>
>>>Jan, I can try that, though I'm not relishing giving up XML.
>>>
>>>
>>:) I have
>>
>>
>>>run into problems with log4j's XML and validating parsers
>>>
>>>
>>(for example,
>>
>>
>>>I can't run my unit tests at the moment for that very
>>>
>>>
>>reason), but if
>>
>>
>>>the .properties solves that problem, then I'm all for it. I've
>>>attached my (cmoplete, but very simple) log4j config.
>>>
>>>
>>Thanks for the tip.
>>
>>
>>>
>>>
>>>
>>>
>>I've wrapped your attached log4j.xml in a JAR (after changing
>>the log file location), placed the JAR in my EAR's lib
>>directory, and was able to see my servlet's log messages
>>getting logged to the log file specified in the log4j.xml.
>>
>>(Looks like the earlier log4j.xml I was using had some problems.)
>>
>>So I think the only reason why you were unable to see any log
>>messages was because you hadn't placed the JAR containing
>>your log4j.xml in your EAR's classpath (under your EAR's /lib dir).
>>
>>Let me know if you still run into any problems.
>>
>>
>>Jan
>>
>>
>>
>>>-----
>>>Jason Lee
>>>Programmer/Analyst
>>>http://www.iecokc.com
>>>
>>>
>>>
>>>
>>>
>>>
>>>>-----Original Message-----
>>>>From: Jan.Luehe_at_Sun.COM [mailto:Jan.Luehe_at_Sun.COM]
>>>>Sent: Tuesday, August 29, 2006 9:17 PM
>>>>To: users_at_glassfish.dev.java.net
>>>>Subject: Re: Log4j is not logging
>>>>
>>>>Hi Jason,
>>>>Can you send me your complete log4j.xml, including its DOCTYPE
>>>>declaration?
>>>>Do you see any errors in the server.log?
>>>>
>>>>When I tried using a log4j.xml config file, I saw this error in
>>>>server.log:
>>>>
>>>> log4j:ERROR DOM element is - not a <log4j:configuration> element.
>>>>
>>>>I'll need to investigate.
>>>>
>>>>Using a log4j.properties works for me, though.
>>>>
>>>>Can you switch from using log4j.xml to using
>>>>
>>>>
>>log4j.properties for the
>>
>>
>>>>time being?
>>>>
>>>>Thanks,
>>>>
>>>>
>>>>Jan
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>>-----
>>>>>Jason Lee
>>>>>Programmer/Analyst
>>>>>http://www.iecokc.com <http://www.iecokc.com/>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>------------------------------------------------------------
>>>>
>>>>
>>---------
>>
>>
>>>>To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
>>>>For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>>>>
>>>>
>>>>
>>>>
>>>>------------------------------------------------------------
>>>>
>>>>
>>----------
>>
>>
>>>>--
>>>>
>>>><?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE
>>>>
>>>>
>>log4j:configuration
>>
>>
>>>>SYSTEM "log4j.dtd">
>>>>
>>>><log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
>>>> <appender name="stdout"
>>>>
>>>>
>>class="org.apache.log4j.ConsoleAppender">
>>
>>
>>>> <param name="Target" value="System.out" />
>>>> <layout class="org.apache.log4j.PatternLayout">
>>>> <param name="ConversionPattern"
>>>>
>>>>
>>value="%d{DATE} %5p %c{1}:%L - %m%n" />
>>
>>
>>>> </layout>
>>>> </appender>
>>>>
>>>> <appender name="file"
>>>>
>>>>
>>class="org.apache.log4j.RollingFileAppender">
>>
>>
>>>> <param name="File"
>>>>
>>>>
>>value="d:/java/logs/Oprah/OrderTransfer.log" />
>>
>>
>>>> <param name="MaxFileSize" value="10MB" />
>>>> <param name="MaxBackupIndex" value="5" />
>>>> <layout class="org.apache.log4j.PatternLayout">
>>>> <param name="ConversionPattern"
>>>>
>>>>
>>value="%d{DATE} %5p %c{1}:%L - %m%n" />
>>
>>
>>>> </layout>
>>>> </appender>
>>>>
>>>> <category name="com.iecokc">
>>>> <priority value="debug" />
>>>> <appender-ref ref="file" />
>>>> </category>
>>>>
>>>> <root>
>>>> <priority value="error" />
>>>> <appender-ref ref="stdout" />
>>>> <appender-ref ref="file" />
>>>> </root>
>>>>
>>>></log4j:configuration>
>>>>
>>>>
>>>>------------------------------------------------------------
>>>>
>>>>
>>----------
>>
>>
>>>>--
>>>>
>>>>------------------------------------------------------------
>>>>
>>>>
>>---------
>>
>>
>>>>To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
>>>>For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>>>>
>>>>
>>>>
>>>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
>>For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>>
>>
>>
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
>For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>
>