Apache Geronimo > Discussion Forums  User List | Dev List | Wiki | Issue Tracker  

log4jResource setting in GBean: ApplicationLog4jConfigurationGBean

View: New views
10 Messages — Rating Filter:   Alert me  

log4jResource setting in GBean: ApplicationLog4jConfigurationGBean

by viola.lu :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

hi, i follow steps in http://cwiki.apache.org/GMOxDOC22/configuring-application-specific-logging-with-log4j.html, and add gbean information in geronimo-web.xml using log4jResource.

<dep:gbean class="org.apache.geronimo.system.logging.log4j.ApplicationLog4jConfigurationGBean" name="testlogLog4jConfiguration">
     
    <dep:attribute name="log4jResource">META-INF/log4j.properties</dep:attribute>
       
    </dep:gbean>

But "Can't find META-INF/log4j.properties " error always exists. if i use log4jFile setting like below:

<dep:gbean class="org.apache.geronimo.system.logging.log4j.ApplicationLog4jConfigurationGBean" name="testlogLog4jConfiguration">
      <dep:attribute name="log4jFile">var/log/log4j.properties</dep:attribute>
    <dep:reference name="ServerInfo"><dep:name>ServerInfo</dep:name></dep:reference>
    <!--<dep:attribute name="log4jResource">META-INF/log4j.properties</dep:attribute>-->      
    </dep:gbean>

it works well.

I looked into ApplicationLog4jConfigurationGBean code:
...
InputStream in;
        if (log4jFile != null) {
            File file = serverInfo.resolveServer(log4jFile);
            in = new FileInputStream(file);
        } else if (log4jResource != null) {
            in = classloader.getResourceAsStream(log4jResource);
            if (in == null) {
                throw new NullPointerException("No log4j properties resource found at " + log4jResource);
            }
        } else {
            return;
        }

...

in = classloader.getResourceAsStream(log4jResource);

ClassLoader will search this file from classpath, and my project structure is:

LogWeb
    ---src(testlog.java
    ---WebContent
          META-INF(log4j.properties)
          WEB-INF
          index.jsp
    ----

Why it can't find out file META-INF/log4j.properties?

Anyone can figure it out? Thanks.

Re: log4jResource setting in GBean: ApplicationLog4jConfigurationGBean

by djencks :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Jun 8, 2009, at 11:03 PM, viola.lu wrote:

>
> hi, i follow steps in
> http://cwiki.apache.org/GMOxDOC22/configuring-application-specific-logging-with-log4j.html 
> ,
> and add gbean information in geronimo-web.xml using log4jResource.
>
> <dep:gbean
> class
> =
> "org
> .apache
> .geronimo.system.logging.log4j.ApplicationLog4jConfigurationGBean"
> name="testlogLog4jConfiguration">
>
>    <dep:attribute
> name="log4jResource">META-INF/log4j.properties</dep:attribute>
>
>    </dep:gbean>
>
> But "Can't find META-INF/log4j.properties " error always exists. if  
> i use
> log4jFile setting like below:
>
> <dep:gbean
> class
> =
> "org
> .apache
> .geronimo.system.logging.log4j.ApplicationLog4jConfigurationGBean"
> name="testlogLog4jConfiguration">
>      <dep:attribute
> name="log4jFile">var/log/log4j.properties</dep:attribute>
>    <dep:reference
> name="ServerInfo"><dep:name>ServerInfo</dep:name></dep:reference>
>    <!--<dep:attribute
> name="log4jResource">META-INF/log4j.properties</dep:attribute>-->
>    </dep:gbean>
>
> it works well.
>
> I looked into ApplicationLog4jConfigurationGBean code:
> ...
> InputStream in;
>        if (log4jFile != null) {
>            File file = serverInfo.resolveServer(log4jFile);
>            in = new FileInputStream(file);
>        } else if (log4jResource != null) {
>            in = classloader.getResourceAsStream(log4jResource);
>            if (in == null) {
>                throw new NullPointerException("No log4j properties  
> resource
> found at " + log4jResource);
>            }
>        } else {
>            return;
>        }
>
> ...
>
> in = classloader.getResourceAsStream(log4jResource);
>
> ClassLoader will search this file from classpath, and my project  
> structure
> is:
>
> LogWeb
>    ---src(testlog.java
>    ---WebContent
>          META-INF(log4j.properties)
>          WEB-INF
>          index.jsp
>    ----
>
> Why it can't find out file META-INF/log4j.properties?

Because that's not in your classpath.

Try WEB-INF/classes/META-INF/log4j.properties.

thanks
david jencks

>
>
> Anyone can figure it out? Thanks.
> --
> View this message in context: http://www.nabble.com/log4jResource-setting-in-GBean%3A-ApplicationLog4jConfigurationGBean-tp23936783s134p23936783.html
> Sent from the Apache Geronimo - Users mailing list archive at  
> Nabble.com.
>

Re: log4jResource setting in GBean: ApplicationLog4jConfigurationGBean

by viola.lu :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks david.

 I moved folder META-INF/log4j.properties to WEB-INF/classes/, and then modify deployment plan with :
<dep:attribute name="log4jResource">META-INF/log4j.properties</dep:attribute>

It works oz it's in the classpath now.


viola.lu wrote:
hi, i follow steps in http://cwiki.apache.org/GMOxDOC22/configuring-application-specific-logging-with-log4j.html, and add gbean information in geronimo-web.xml using log4jResource.

<dep:gbean class="org.apache.geronimo.system.logging.log4j.ApplicationLog4jConfigurationGBean" name="testlogLog4jConfiguration">
     
    <dep:attribute name="log4jResource">META-INF/log4j.properties</dep:attribute>
       
    </dep:gbean>

But "Can't find META-INF/log4j.properties " error always exists. if i use log4jFile setting like below:

<dep:gbean class="org.apache.geronimo.system.logging.log4j.ApplicationLog4jConfigurationGBean" name="testlogLog4jConfiguration">
      <dep:attribute name="log4jFile">var/log/log4j.properties</dep:attribute>
    <dep:reference name="ServerInfo"><dep:name>ServerInfo</dep:name></dep:reference>
    <!--<dep:attribute name="log4jResource">META-INF/log4j.properties</dep:attribute>-->      
    </dep:gbean>

it works well.

I looked into ApplicationLog4jConfigurationGBean code:
...
InputStream in;
        if (log4jFile != null) {
            File file = serverInfo.resolveServer(log4jFile);
            in = new FileInputStream(file);
        } else if (log4jResource != null) {
            in = classloader.getResourceAsStream(log4jResource);
            if (in == null) {
                throw new NullPointerException("No log4j properties resource found at " + log4jResource);
            }
        } else {
            return;
        }

...

in = classloader.getResourceAsStream(log4jResource);

ClassLoader will search this file from classpath, and my project structure is:

LogWeb
    ---src(testlog.java
    ---WebContent
          META-INF(log4j.properties)
          WEB-INF
          index.jsp
    ----

Why it can't find out file META-INF/log4j.properties?

Anyone can figure it out? Thanks.

Re: log4jResource setting in GBean: ApplicationLog4jConfigurationGBean

by lvdpal :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm trying to do the same thing, but so far my application didn't have a deployment plan yet. Now I'm trying to add one, so I can add the GBean, but it's still not logging the way I want to. Any idea what I might be doing wrong? (I have of course put the properties file in the specified directory.)

<web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1"
xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2"
xmlns:name="http://geronimo.apache.org/xml/ns/naming-1.2"
xmlns:app="http://geronimo.apache.org/xml/ns/j2ee/application-2.0"
xmlns:sec="http://geronimo.apache.org/xml/ns/security-2.0"
xmlns:pers="http://java.sun.com/xml/ns/persistence">
<context-root>Lunaboek</context-root>

<gbean name="DirectoryLog4jConfiguration" class="org.apache.geronimo.system.logging.log4j.ApplicationLog4jConfigurationGBean">
<attribute name="log4jFile">var/lunaboek/log4j.properties</attribute>
<reference name="ServerInfo"><name>ServerInfo</name></reference>
</gbean>
</web-app>

Re: log4jResource setting in GBean: ApplicationLog4jConfigurationGBean

by viola.lu :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Can you attach your application here and your geronimo server version? thanks.
djencks wrote:
On Jun 8, 2009, at 11:03 PM, viola.lu wrote:

>
> hi, i follow steps in
> http://cwiki.apache.org/GMOxDOC22/configuring-application-specific-logging-with-log4j.html 
> ,
> and add gbean information in geronimo-web.xml using log4jResource.
>
> <dep:gbean
> class
> =
> "org
> .apache
> .geronimo.system.logging.log4j.ApplicationLog4jConfigurationGBean"
> name="testlogLog4jConfiguration">
>
>    <dep:attribute
> name="log4jResource">META-INF/log4j.properties</dep:attribute>
>
>    </dep:gbean>
>
> But "Can't find META-INF/log4j.properties " error always exists. if  
> i use
> log4jFile setting like below:
>
> <dep:gbean
> class
> =
> "org
> .apache
> .geronimo.system.logging.log4j.ApplicationLog4jConfigurationGBean"
> name="testlogLog4jConfiguration">
>      <dep:attribute
> name="log4jFile">var/log/log4j.properties</dep:attribute>
>    <dep:reference
> name="ServerInfo"><dep:name>ServerInfo</dep:name></dep:reference>
>    <!--<dep:attribute
> name="log4jResource">META-INF/log4j.properties</dep:attribute>-->
>    </dep:gbean>
>
> it works well.
>
> I looked into ApplicationLog4jConfigurationGBean code:
> ...
> InputStream in;
>        if (log4jFile != null) {
>            File file = serverInfo.resolveServer(log4jFile);
>            in = new FileInputStream(file);
>        } else if (log4jResource != null) {
>            in = classloader.getResourceAsStream(log4jResource);
>            if (in == null) {
>                throw new NullPointerException("No log4j properties  
> resource
> found at " + log4jResource);
>            }
>        } else {
>            return;
>        }
>
> ...
>
> in = classloader.getResourceAsStream(log4jResource);
>
> ClassLoader will search this file from classpath, and my project  
> structure
> is:
>
> LogWeb
>    ---src(testlog.java
>    ---WebContent
>          META-INF(log4j.properties)
>          WEB-INF
>          index.jsp
>    ----
>
> Why it can't find out file META-INF/log4j.properties?

Because that's not in your classpath.

Try WEB-INF/classes/META-INF/log4j.properties.

thanks
david jencks

>
>
> Anyone can figure it out? Thanks.
> --
> View this message in context: http://www.nabble.com/log4jResource-setting-in-GBean%3A-ApplicationLog4jConfigurationGBean-tp23936783s134p23936783.html
> Sent from the Apache Geronimo - Users mailing list archive at  
> Nabble.com.
>

Re: log4jResource setting in GBean: ApplicationLog4jConfigurationGBean

by viola.lu :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Can you attach your application here and your geronimo server version? thanks.
lvdpal wrote:
I'm trying to do the same thing, but so far my application didn't have a deployment plan yet. Now I'm trying to add one, so I can add the GBean, but it's still not logging the way I want to. Any idea what I might be doing wrong? (I have of course put the properties file in the specified directory.)

<web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1"
xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2"
xmlns:name="http://geronimo.apache.org/xml/ns/naming-1.2"
xmlns:app="http://geronimo.apache.org/xml/ns/j2ee/application-2.0"
xmlns:sec="http://geronimo.apache.org/xml/ns/security-2.0"
xmlns:pers="http://java.sun.com/xml/ns/persistence">
<context-root>Lunaboek</context-root>

<gbean name="DirectoryLog4jConfiguration" class="org.apache.geronimo.system.logging.log4j.ApplicationLog4jConfigurationGBean">
<attribute name="log4jFile">var/lunaboek/log4j.properties</attribute>
<reference name="ServerInfo"><name>ServerInfo</name></reference>
</gbean>
</web-app>

Re: log4jResource setting in GBean: ApplicationLog4jConfigurationGBean

by RunHua Chi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Ivpal, looks like the plan is correct.

So as you said "it's still not logging the way I want to."?  we'd like to know what's your expectation?
Can you deploy your application successfully? Can it be started successfully?
Is there any exception shown in geronimo.log file?

Jeff C

Re: log4jResource setting in GBean: ApplicationLog4jConfigurationGBean

by lvdpal :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Well attaching the whole application might be a bit overwhelming. It's a multi-module Maven project. I'm using an aspectJ library to weave in the logging code into several of my modules. This is working, because I am seeing the logging, only it is logging in geronimo.log and based on my log4j.properties I'm expecting it to log into a logfile of my own.

My Geronimo version is 2.1.4 based on Jetty.

This is my log4j.properties file:

# Set root logger level to DEBUG and its only appender to LOGFILE.
#log4j.rootLogger=INFO, CONSOLE
log4j.logger.nl.lunaris.bookdb=DEBUG, LOGFILE

# CONSOLE is set to be a ConsoleAppender
#log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
#log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
#log4j.appender.CONSOLE.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

# LOGFILE is set to be a FileAppender.
log4j.appender.LOGFILE=org.apache.log4j.FileAppender
log4j.appender.LOGFILE.File=C:/Projects/Boekenplank/logs/booklog.txt
log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.LOGFILE.layout.ConversionPattern=%d [%t] %-5p %c - %m%n


I had tried to log everything else to console first, but then I read that I can't use the rootLogger (because Geronimo uses that), so I commented that logger out.

Re: log4jResource setting in GBean: ApplicationLog4jConfigurationGBean

by kevan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Jul 10, 2009, at 2:43 AM, lvdpal wrote:

>
> Well attaching the whole application might be a bit overwhelming.

Thank You!!! ;-)

Viola,
I'd really we rather not request attachments (especially potentially  
large attachments) on our mailing lists. Would prefer that we either  
use Jira (Attach file) or other file sharing mechanisms...

--kevan


Re: log4jResource setting in GBean: ApplicationLog4jConfigurationGBean

by Sophia Tang :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks David and Viola.

 The document http://cwiki.apache.org/GMOxDOC22/configuring-application-specific-logging-with-log4j.html has been updated with this issue:


You can also use a log4j.properties file in your classpath, for example, in WEB-INF/classes/META-INF. (If you prefer not to place this file under WEB-INF/classes/, the path of this file must be added to your classpath). But this will obstruct anyone trying to configure logging as the file will remain packed in your application somewhere hard to find.

<gbean name="DirectoryLog4jConfiguration" class="org.apache.geronimo.system.logging.log4j.ApplicationLog4jConfigurationGBean">
<attribute name="log4jResource">META-INF/log4j.properties</attribute>
 </gbean>



Best Regards,

Ying Tang

2009/6/9 David Jencks <david_jencks@...>

On Jun 8, 2009, at 11:03 PM, viola.lu wrote:


hi, i follow steps in
http://cwiki.apache.org/GMOxDOC22/configuring-application-specific-logging-with-log4j.html,
and add gbean information in geronimo-web.xml using log4jResource.

<dep:gbean
class="org.apache.geronimo.system.logging.log4j.ApplicationLog4jConfigurationGBean"
name="testlogLog4jConfiguration">

  <dep:attribute
name="log4jResource">META-INF/log4j.properties</dep:attribute>

  </dep:gbean>

But "Can't find META-INF/log4j.properties " error always exists. if i use
log4jFile setting like below:

<dep:gbean
class="org.apache.geronimo.system.logging.log4j.ApplicationLog4jConfigurationGBean"
name="testlogLog4jConfiguration">
    <dep:attribute
name="log4jFile">var/log/log4j.properties</dep:attribute>
  <dep:reference
name="ServerInfo"><dep:name>ServerInfo</dep:name></dep:reference>
  <!--<dep:attribute
name="log4jResource">META-INF/log4j.properties</dep:attribute>-->
  </dep:gbean>

it works well.

I looked into ApplicationLog4jConfigurationGBean code:
...
InputStream in;
      if (log4jFile != null) {
          File file = serverInfo.resolveServer(log4jFile);
          in = new FileInputStream(file);
      } else if (log4jResource != null) {
          in = classloader.getResourceAsStream(log4jResource);
          if (in == null) {
              throw new NullPointerException("No log4j properties resource
found at " + log4jResource);
          }
      } else {
          return;
      }

...

in = classloader.getResourceAsStream(log4jResource);

ClassLoader will search this file from classpath, and my project structure
is:

LogWeb
  ---src(testlog.java
  ---WebContent
        META-INF(log4j.properties)
        WEB-INF
        index.jsp
  ----

Why it can't find out file META-INF/log4j.properties?

Because that's not in your classpath.

Try WEB-INF/classes/META-INF/log4j.properties.

thanks
david jencks




Anyone can figure it out? Thanks.
--
View this message in context: http://www.nabble.com/log4jResource-setting-in-GBean%3A-ApplicationLog4jConfigurationGBean-tp23936783s134p23936783.html
Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.