logback-android icon indicating copy to clipboard operation
logback-android copied to clipboard

EXT_DIR value depends on Android version

Open andrew-tpz opened this issue 4 years ago • 2 comments

Related to commit #208:

getExternalStorageDirectory() returns root card path, while getExternalFilesDirectoryPath() returns app data specific path. So property EXT_DIR in logback.xml would get different values depend on Android version.

I think it would be something like this:

  public String getExternalStorageDirectoryPath() {
    if (Build.VERSION.SDK_INT >= 29) {
      return getExternalFilesDirectoryPath();
    } else {
      return Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/" + getPackageName() + "/files";
    }

andrew-tpz avatar Dec 11 '20 13:12 andrew-tpz

Your suggestion is to make $EXT_DIR/getExternalStorageDirectoryPath() always return the app-specific external files dir, but I think that defeats the purpose of the function, which is to return the root of the external storage path. I missed that in my original review of #208.

The more correct fix to me is to make $EXT_DIR/getExternalStorageDirectoryPath() always return the root of the external storage like it did before #208. In either case, this would be as a breaking change, as users might be relying on the current behavior in their configs.

I think I'll address this by:

  1. documenting the current behavior with a warning
  2. deprecating $EXT_DIR, emitting a runtime deprecation warning in the logs
  3. adding a new special variable to replace $EXT_DIR (e.g., $EXTERNAL_STORAGE_DIR)
  4. adding a new special variable specifically for external files dir (e.g., $EXTERNAL_FILES_DIR) (related #181).

🤔

tony19 avatar Nov 06 '22 19:11 tony19

Any update on this? We are having to use a custom PropertyDefiner to work around this issue, whereas in earlier versions we were directly using EXT_DIR in the config.

ajburley avatar Mar 31 '23 08:03 ajburley