Hi Rao To be clear I have two different applications which share many similar jar, including in-house developed, in same tomcat so in order to have clear logs. I do not want them to write logs in to the same file. What mechanism my team and I have used for separating property files are using xxx.dev.properties, xxx.prod.properties in the same application war and by setting a jvm argument such as "-Dactive.profile=dev" or even just use the Spring one "-Dspring.active.profiles=dev" to decide which properties to load. So sharing such property in tomcat or even in development environment such as Eclipse is not a problem. However, the mechanism log4j has is a "loading preference" based on the name of the file, such that log4j2-test.xml will load before log4j2.xml. This will only work for at most one other environment other than the development one, if I always use log4j2-test.xml for development. In reality, I have more than one environment, such as SIT and UAT for different phases of testing. Therefore the approach I took before I had to run 2 applications in the same tomcat was to put the log4j2 -D flag, which requires an absolute path, in jvm opts to specify the log4j2.xml. For example /usr/share/myapp/log4j-sit.xml.
Of course if log4j has provided some mechanism to use some environment variable to load different configuration file within the application that will be great for me. Also I might need to write my own lookup mechanism myself to achieve the behaviour I want, but I just havent looked into that and want to seek if people have the problem and how are people solving this to get some idea before I do something that someone else might have done or have a better way of doing. hope this makes you understand better of my situation. Thank On Sat, Apr 16, 2016 at 1:12 AM, Niranjan Rao <[email protected]> wrote: > You know your environment better and know all the problems, but I think I > am getting confused. Is it same application deployed with two different WAR > files? I mean say app.war copied as prod.war and qa.war? How do > applications know where to find other settings? Is it read from the > resources or come via same external configuration. > > I mean when you create the WAR file, something is telling application what > to look at. Can same mechanism be used to modify the entry web.xml? > > For local development, it's actually very easy - you just set -D flag in > eclipse launch configuration. Other IDEs should be supporting something > similar. > > Good luck. > > Regards, > > Niranjan > > > > On 04/15/2016 01:52 AM, Steven Yang wrote: > >> First of all thanks to all suggestions. >> >> I dont think setting system property solves my issue because they are both >> in the same tomcat which means they share the same system property. >> >> setting the log4jConfiguration in web.xml means I will always have to set >> it even if I am in local development right? unless I use different web.xml >> for different environments? >> >> I think I will go into the direction of Ralph's suggestion, however I am >> probably going to use ${web:contextPath}. >> >> Thanks all >> >> On Fri, Apr 15, 2016 at 5:02 AM, Matt Sicker <[email protected]> wrote: >> >> That functionality is from log4j-web. >>> >>> On 14 April 2016 at 15:50, Niranjan Rao <[email protected]> wrote: >>> >>> If you are using spring by any chance, I think this can be resolved using >>>> following in web.xml >>>> >>>> <context-param> >>>> <param-name>log4jConfiguration</param-name> >>>> <param-value>${sys:LOG4J_PATH}</param-value> >>>> </context-param> >>>> >>>> and LOG4J_PATH is defined using -DLOG4J_PATH=file:///<your path> in >>>> >>> setenv >>> >>>> file. >>>> >>>> I am not sure if this is spring functionality, or log4j functionality, >>>> >>> but >>> >>>> it does work for us. We have multiple application on same tomcat >>>> instance >>>> and each log goes to it's own file. We don't like to embed the log4j >>>> settings in the JAR or WAR files as it means another deployment if you >>>> >>> want >>> >>>> to change log settings to triage a problem. >>>> >>>> Regards, >>>> >>>> Niranjan >>>> >>>> >>>> On 04/13/2016 09:54 PM, Ralph Goers wrote: >>>> >>>> Is the log4j configuration similar in the same environments? If so you >>>>> could have your log4j.xml file be a “template” where all the items that >>>>> >>>> are >>> >>>> variable are variables resolved by a lookup. You could either use the >>>>> system properties lookup and make sure all the system properties are >>>>> defined, or you could create a custom lookup that reads a property file >>>>> named for the environment as you have described. You would then use >>>>> that >>>>> lookup to resolve all the configurable items in log4j2.xml. >>>>> >>>>> Ralph >>>>> >>>>> On Apr 13, 2016, at 5:22 PM, Steven Yang <[email protected]> wrote: >>>>> >>>>>> Hi >>>>>> >>>>>> currently the convention we adopt on property files are having >>>>>> separate >>>>>> file for each environment. >>>>>> for example, if there is a property file call "database" then there >>>>>> >>>>> will >>> >>>> be >>>>>> a database.dev.properties for local develop, database.uat.properties >>>>>> >>>>> for >>> >>>> UAT and a database.prod.properties for production. >>>>>> However log4j only supports a normal one and a test. >>>>>> >>>>>> Of course we can rename the file before deploying the application (no >>>>>> hassle, since we are using Gradle). >>>>>> However, we dont feel like its the best solution thats why we used the >>>>>> jvm >>>>>> argument when we were using separate tomcats. >>>>>> >>>>>> So just want to make sure there is no other better solution for this >>>>>> >>>>> case >>> >>>> before I go into using the xml file directly in the war file. >>>>>> >>>>>> Thanks >>>>>> >>>>>> On Wed, Apr 13, 2016 at 3:17 AM, Kamal Mettananda <[email protected]> >>>>>> wrote: >>>>>> >>>>>> Hi Steven >>>>>> >>>>>>> Have you looked at using separate and different log4j2.xml files >>>>>>> >>>>>> inside >>> >>>> each app (.war files) rather than using command line configurations? >>>>>>> >>>>>>> Thanks >>>>>>> Kamal >>>>>>> >>>>>>> ----------------------- >>>>>>> www.digizol.com >>>>>>> >>>>>>> >>>>>>> On Tue, Apr 12, 2016 at 4:10 PM Steven Yang <[email protected]> >>>>>>> wrote: >>>>>>> >>>>>>> Hi >>>>>>> >>>>>>>> I am trying to deploy 2 applications in to one tomcat (originally in >>>>>>>> >>>>>>> 2 >>> >>>> separate tomcat). >>>>>>>> And I use -Dlog4j.configurationFile to specify my log4j >>>>>>>> >>>>>>> configuration. >>> >>>> However, if I do that both applications will write to the same file. >>>>>>>> I want each application to write to there own files. >>>>>>>> Both applications have very similar packages and share many common >>>>>>>> libraries developed in-house, so using package name to separate logs >>>>>>>> will >>>>>>>> not be what we want. >>>>>>>> >>>>>>>> What is the best solution/practice to this kind of problem? >>>>>>>> >>>>>>>> (using log4j 2.5) >>>>>>>> >>>>>>>> Thanks >>>>>>>> >>>>>>>> >>>>>>>> >>>>> --------------------------------------------------------------------- >>>>> To unsubscribe, e-mail: [email protected] >>>>> For additional commands, e-mail: [email protected] >>>>> >>>>> >>>>> --------------------------------------------------------------------- >>>> To unsubscribe, e-mail: [email protected] >>>> For additional commands, e-mail: [email protected] >>>> >>>> >>>> >>> -- >>> Matt Sicker <[email protected]> >>> >>> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > >
