2

I have placed my logback.xml outside the war and have included that file in the main logback.xml.

The problem is absolute path is working with include file but relative path is not working Below is the code :

 <configuration scan="true" scanPeriod="30 seconds">
   <include file="..//..//..//..//logback-new.xml" />   
 </configuration>

included file path : C:\Users\MB0000038\Documents\vuliv-server-development - 2\theapp\logback files

resources folder inside war : C:\Users\MB0000038\Documents\vuliv-server-development - 2\theapp\AnalyticsAPI\src\main\resources

Any help appreciated

Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130
amol
  • 125
  • 1
  • 11

1 Answers1

1

According to the Logback docs the file inclusion ...

can use relative paths but note that the current directory is defined by the application and is not necessarily related to the path of the configuration file.

So, given your relative path: ..//..//..//..//logback-new.xml Logback will look for that logback-new.xml four directories above the application's current working directory.

I suspect you are defining the relative path as if should be relative to the resources folder inside your WAR but this is not how it should be defined. Instead, it should be defined relative to the application's current working directory. If Logback cannot find the file to be included it will emit a status message telling you that.

glytching
  • 44,936
  • 9
  • 114
  • 120
  • so the applications current working directory is `C:\Users\MB0000038\Documents\vuliv-server-development - 2\theapp\AnalyticsAPI` coz name of project is AnalyticsAPI ? – amol Oct 25 '17 at 07:20
  • I'm not sure what you are asking in your last comment. Are you asking me what the application's current working directory is? Or have you verified what the application's current working directory is (if so, how?) and you are now asking me why it is that value? – glytching Oct 25 '17 at 07:24
  • yes i am asking the current working directory also and also if CWD is `C:\Users\MB0000038\Documents\vuliv-server-development - 2\theapp\AnalyticsAPI` , the what should be the relative path ? – amol Oct 25 '17 at 07:26
  • [Find current working directory](https://stackoverflow.com/questions/3153337/get-current-working-directory-in-java). However, attempting to define a relative path from within a WAR which is - I presume - being run inside a web container is likely to be very brittle. I'd suggest that using an absolute path is more reliable. – glytching Oct 25 '17 at 07:29
  • can't use an absolute path ..since i am using multiple application servers and i need relative path of each app server which will be different but absolute path will be same – amol Oct 25 '17 at 08:57
  • You could use the link I provided in my last comment to help you determine what your current working direcotry is and set the path accordingly. It's not possible for me to tell you what that value because I don't have enough access to or knowledge of your setup. – glytching Oct 25 '17 at 09:03