0

I am trying to read env variable in logback.xml file. I can do:

<variable name="JAVA" value="${JAVA_HOME}" />

and the use it later:

<source>MY APP ${JAVA}</source>

and it works however when I created new variable by setenv ENV TEST (it's Red Hat) and I check if it's in environment variables by printenv then I can see it ENV=TEST. When I try to define it in logback.xml the same way as JAVA_HOME so: <variable name="ENVIRONMENT" value="${ENV}" /> and use here:

<source>MY APP ${ENVIRONMENT}</source>

then I can see in SPLUNK: source = MY APP ENV_IS_UNDEFINED

Or is there another way to put ENVIRONMENT value somewhere and then read ENVIRONMENT in logback.xml?

I found: if condition in logback - print log messages in two different folders but my problem is different

@Edit

Even though I am starting process with:

$JAVA_HOME/bin/java \
    -Duser.timezone=GMT \
    -Denv="test" \
    -Dhost="127.0.0.1" \
    ...

and trying to send it to SPLUNK by <source>MY APP ${env}</source> I can see in SPLNUK UI source = MY APP env_IS_UNDEFINED

When I run service locally with: VM options then it works locally

Michu93
  • 5,058
  • 7
  • 47
  • 80
  • VM options aren’t env variables. There’s a separate place for those in IntelliJ. Are you saying you can export it to Splunk from local? – Abhijit Sarkar May 11 '23 at 08:42
  • in `logback.xml` both are checked (env variables at the end if I recall, JVM options before). Yes, when I put into configuration in IntelliJ into `VM options` `env` and `hostname` then it's exported to SPLUNK and I can see it there. – Michu93 May 11 '23 at 09:50

1 Answers1

0
<source>${env}</source>

is perfectly fine, there was discrepancy between start scripts which I was using.

To conclude: If you use ${variable} and in start script you use -Dvariable = something then it works.

Michu93
  • 5,058
  • 7
  • 47
  • 80