• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

log4h.configurationFile behaves differently than the log4j.configuration setting from 1.2

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Log4j 1.2, I used log4j.configuration to specify a log4j.server.properties. then, in the root of my classpath both a log4j.properties and a log4j.server.properties were there. Thus, in localhost, with no system property set, the former would direct logging output to the console of the IDEas specified in log4j.properties. But on the server, the log4j.configuration=log4j.server.properties would be set, and output would go to the various files in the logging folders like we want on the servers in our various environments, as defined in log4j.server.properties.

I want to do the same thing on log4j 2. But the log4j.configurationFile appears to demand an absolute URL. But the absolute file path will be different for each webapp installed on that server. I just want to specify log4j2.server.xml to get the same effect I got under log4j 1.2. When I try, I get "Unable to access log4j2.server.xml java.lang.IllegalArgumentException: URI is not absolute".

How can I get the same effect I got under 1.2, without having some script replace the file?
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's never a good idea to use relative paths for resources in a webapp. You don't know where they'll end up. Especially if the server does internal "change working directory" operations at random intervals - which it's fully entitled to do, because "working directory" is not part of the J2EE web application spec.

In my own case, I normally use the log4j.xml file in the WAR classpath and have a separate console logger which is used both by the IDE and as part of the server log in production. Logs pertaining to various subsystems I made using absolute paths. Then again, the conventions of /var/log or /opt/product/log are fairly well-established under Linux, so I can demand those locations with relative impunity. If you're doing stuff that takes you into the Windows world, there are fewer established conventions.

So what I would probably do is simply define the log directory root for the app as a context environment entry variable, set up a JNDI lookup in the logger initialization code to obtain it, and construct the logger channels from there.

Since I typically have Spring managing my webapp assets, I'd first check the relevant Spring docs, since with any luck, that can all be done in the Sprint application context config file.

 
Brian Mulholland
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tim,

The log4j docs themselves recommend putting the config files in your classpath root. I am doing exactly that, just like you say you are. But I merely want to have two there, and control which one is used by the environment setting log4j makes available. Log4j 1.2 makes this possible because I can give a simple file name to replace the default. Log4j 2's preference for absolute paths makes it brittle. I run multiple apps in the same jvm on our server, so absolute paths absolutely doesn't work. I can't specify /opt/long path to my webapp/WEB-INF/classes/log4j.server.xml because that long path would include the SPECIFIC application. Thus the config would not affect the other applications. See the dilemma?
 
Tim Holloway
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I got confused here. There's 1 and only 1 WEB-INF/classes directory per webapp. No sharing. So each webapp would have to have its own config file anyway, regardless of whether the stuff within that directory points, relative or absolute.
 
Brian Mulholland
Ranch Hand
Posts: 68
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
SOLVED - So, I was doing it right. The log4j.configurationFile DOES allow log4j2.server.xml just as I wanted. But we had a lingering log4jConfigListener defined in our web.xml that I didn't know about (darn co-workers, always doin' stuff). For some reason, when this was there, that config DEMANDED an absolute URL. When I removed it, everything worked....smooth as butter.
 
This tiny ad is guaranteed to be gluten free.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic