0

I am developing Java web application for Glassfish server. I have problem with setting path for File appender. I would like to use variable which is defined in web.xml.

Web.xml:

<context-param>
    <param-name>webAppRootKey</param-name>
    <param-value>app.myApp-client.home</param-value>
</context-param>

Logback.xml (in src/main/resurces)

    <appender name="FILE" class="ch.qos.logback.core.FileAppender">        
    <file>${app.myApp-client.home}/WEB-INF/app-log/client.log</file>        
    <encoder>
        <pattern>%date %level [%file:%line] %msg%n</pattern>
    </encoder>
</appender>

After deploy my application on Glassfish log file with name

/app.myApp-client.home_IS_UNDEFINED/WEB-INF/app-log/client.log

is created. Why parameter app.myApp-client.home is undefined? Is there any better option for put application path to file appender?

Thank you.

user2329752
  • 77
  • 2
  • 7

3 Answers3

3

It is possible to set variables to values obtained via JNDI. In your case, you would write:

  <insertFromJNDI env-entry-name="java:comp/env/webAppRootKey" as="webAppRootKey" />

  <appender name="FILE" class="ch.qos.logback.core.FileAppender">        
    <file>${webAppRootKey}/WEB-INF/app-log/client.log</file>        
    <encoder>
      <pattern>%date %level [%file:%line] %msg%n</pattern>
    </encoder>
  </appender>

The above should work nicely. In addition, you might also find it useful to set a default value for ${webAppRootKey}.

Ceki
  • 26,753
  • 7
  • 62
  • 71
0

You are trying to reference the value instead of the param name...

Try it like this:

<file>${webAppRootKey}/WEB-INF/app-log/client.log</file> 

But I guess this will give you /app.myApp-client.home/WEB-INF/app-log/client.log and that is also not what you expected? :)

unwichtich
  • 13,712
  • 4
  • 53
  • 66
  • You are right. I would like to put path of my application on server (for example /home/glassfish/domains/domain1/j2ee-modules/MyApplication on something else) - is there any constant/variable for it? – user2329752 Apr 30 '13 at 07:49
  • What about `${application.home}` as in the [play logging docs](http://www.playframework.com/documentation/2.0/SettingsLogger) – Carl G May 14 '14 at 20:40
0

There is some info about configuring logback via JNDI here: http://logback.qos.ch/manual/loggingSeparation.html

Also there is discussion of ways to do it here: http://logback.10977.n7.nabble.com/Externalized-Logback-configuration-for-web-applications-td3629.html

David Roussel
  • 5,788
  • 1
  • 30
  • 35