I send logs to graylog from my JAR file. The issue is sometimes this jar is deployed and run on a temp folder on the prod machine whose logs also are sent to the graylog and error alerts if any are triggered causing slack and email alerts. These alerts are currently restricted to the filter that they should come from production machine. Now, I want that if a particular process is running from inside the SOMETHING/temp/{Name}/ folder then its logs should not be sending prod level alerts. We might redirect those logs to a seperate slack channel. For that I want to send a property mentioning the path from where the JAR is triggered to the graylog. Is there any way to fetch this information from inside the logback.xml file through any property or something?
I searched on net and found a way to get this using user.dir so I tried to perform it using the following way but it doesn't sends the property on graylog.
...
<property name="directoryPath" value="${user.dir}" />
...
<appender name="GELF" class="biz.paluch.logging.gelf.logback.GelfLogbackAppender">
...
<includeMdcKeyName>directoryPath</includeMdcKeyName>
...
</appender>
...
Also, I know that I can get it from inside the JAVA file using this method but I have multiple main classes in the java so instead of adding this in all the files and then use it log. I am looking for an easier way where just after changing the logback.xml file it can be reflected across all files.
File f= new File( Test.class.getProtectionDomain()
.getCodeSource()
.getLocation().toURI() );
What is the recommended way to achieve this? Thanks.