Search code examples
javaenvironment-variablesredhatlogbacksplunk

Can't read one variable in logback.xml but can read another


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


Solution

  • <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.