loki4j / loki-logback-appender

Fast and lightweight implementation of Logback appender for Grafana Loki
https://loki4j.github.io/loki-logback-appender/
BSD 2-Clause "Simplified" License
300 stars 26 forks source link

How to set default value for url if enviroment variable is undefined #146

Closed setofaces closed 2 years ago

setofaces commented 2 years ago

Hi there. I have my spring app with following configuration property in application.properties: loki4j.url: ${LOKI4J_URL} and in logback-spring.xml I have following: `

    <http>
        <url>${loki4j.url:-localhost:3100/loki/api/v1/push}</url>

..... `

Inspite of information about possibillity of setting default value via :-, when I dont explicitly set LOKI4J_URL variable I get java.lang.IllegalStateException: java.lang.IllegalStateException: Logback configuration error detected: ERROR in ch.qos.logback.core.joran.spi.Interpreter@38:16 - RuntimeException in Action for tag [appender] java.lang.IllegalArgumentException: URI with undefined scheme

Could you please tell me is it possible to get what I want or no? Thank you in advance.

nehaev commented 2 years ago

Hi @setofaces,

First off, you should be able to use env vars directly in your Logback config.

Second, the error that you're getting - "URI with undefined scheme" - is exactly what is wrong, you just need to add scheme to your URI:

<url>${LOKI_URL:-http://localhost:3100/loki/api/v1/push}</url>

Closing this issue for now, but feel free to ask any further questions here or in dedicated discussions section.