logback-android
logback-android copied to clipboard
Make externalFilesDir available as a property
The class AndroidContextUtil.java
already contains a way to query the external files directory. This is actually the Context.getExternalFilesDir(null)
. The importance of this directory is than beginning with Android 7 this is a directory where the application can write without asking for permission, and this directory is also publicly readable, making it ideal for storing non-sensitive logfiles during development.
However there is no way to refer to this directory from the logback.xml file, because it is not registered in the logger context properties.
I suggest a new CoreConstants value like EXT_DATA_DIR
which points to this directory, if available.
There are also more directories like the externalCacheDir which is also present in AndroidContextUtil
but not registered in the logger context.
FYI: If you need a workaround, you can use PropertyDefiner (See https://logback.qos.ch/manual/configuration.html#definingPropsOnTheFly). I used it to to expose BuildConfig
variables to the XML configuration.
Hi @wimdeblauwe , could PropertyDefiner
be used to add a build.gradle
property to the logback.xml
file?
Example:
build.gradle
def MY_CUSTOM_HOST = "http://an.example.url"
def MY_CUSTOM_PORT = 1234
logback.xml
<configuration>
...
<appender name="syslog-tls" class="com.papertrailapp.logback.Syslog4jAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>...</pattern>
</layout>
<syslogConfig class="org.productivity.java.syslog4j.impl.net.tcp.ssl.SSLTCPNetSyslogConfig">
<host>${MY_CUSTOM_HOST}</host>
<port>${MY_CUSTOM_PORT}</port>
<sendLocalName>...</sendLocalName>
<sendLocalTimestamp>...</sendLocalTimestamp>
<maxMessageLength>...</maxMessageLength>
</syslogConfig>
</appender>
...
</configuration>
In case it can, could you post any example code, link, or public gist that I can check? Thanks in advance!