Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not writting files android 11 #228

Open
sagamagus opened this issue Aug 27, 2021 · 5 comments
Open

not writting files android 11 #228

sagamagus opened this issue Aug 27, 2021 · 5 comments
Labels

Comments

@sagamagus
Copy link

sagamagus commented Aug 27, 2021

Description

there is an issue involving Android 11 and the google policy that dont let upload to playstore with the permission "MANAGE_EXTERNAL_STORAGE", if you dont use that permission the logs write once, but if you have another app in background, doesnt writte nor the file, nor the logs once the files exists, and if you delete the log file, it doent write again a file with that name, you must change the name of the file.

Steps to reproduce

logback.xml:
<configuration>
<timestamp key="bySecond" datePattern="yyyyMMdd"/>
<property name="LOG_DIR" value="/storage/emulated/0/documents/logs" />
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>${LOG_DIR}/log-${bySecond}.txt</file>
<append>true</append>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{40} - %msg%n</pattern>
</encoder>
</appender>

`<appender name="LOGCAT" class="ch.qos.logback.classic.android.LogcatAppender">`
    `<encoder>`
        `<pattern>%-5level - %msg%n</pattern>`
    `</encoder>`
`</appender>`

`<root level="DEBUG">`
    `<appender-ref ref="FILE" />`
    `<appender-ref ref="LOGCAT" />`
`</root>`

</configuration>

add this to manifest to write in Documents route:
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS" />

Environment

  • logback-android version: 2.0.0
  • Android version: API 30 Android 11
  • Platform: Any
@sagamagus sagamagus added the bug label Aug 27, 2021
@sagamagus
Copy link
Author

sagamagus commented Nov 9, 2021 via email

@tony19
Copy link
Owner

tony19 commented Nov 9, 2021

Notes on permission usage:

@tony19
Copy link
Owner

tony19 commented Nov 9, 2021

It sounds like there are two issues here:

  1. You want to write logs to shared storage on Android 11, and you're trying the Documents folder, which is normally not allowed in Android 11. It's not clear to me whether you actually need the file location to be the Documents folder. If the objective is for users to be able to pull the logs themselves from a commonly accessible directory, you could store the logs in the Downloads folder, which does not require any special permissions.

  2. You delete the log file while the app is running, and you want the logger to create a new log file the next time it tries to log something (all while not restarting the app), but it doesn't? Is that right?

@sagamagus
Copy link
Author

sagamagus commented Nov 10, 2021 via email

@stale stale bot added the stale label Jan 9, 2022
Repository owner deleted a comment from stale bot Jan 9, 2022
@stale stale bot removed the stale label Jan 9, 2022
Repository owner deleted a comment from kunalvaibhav Feb 14, 2022
Repository owner deleted a comment from Sidnio Feb 23, 2022
@vitalyster
Copy link

vitalyster commented Nov 21, 2022

I saw the same issue, and I see the following error:

|-ERROR in ch.qos.logback.core.rolling.RollingFileAppender[file] - openFile(/storage/emulated/0/Android/data/com.example/files/file.log,true) failed java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.example/files/file.log: open failed: ENOENT (No such file or directory)

I started to debug the issue and added the following code to my Application onCreate method:

System.out.println("External files dir: " + getExternalFilesDir(null));

With that code logback-android magically started to create parent directories and log files.
My manifest permissions looks like this:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18" />

(Doesn't need any permissions on Android 4.4+)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants