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

${DATA__DIR} seems to be an empty string #172

Closed
mgohin opened this issue Apr 12, 2018 · 9 comments
Closed

${DATA__DIR} seems to be an empty string #172

mgohin opened this issue Apr 12, 2018 · 9 comments
Assignees
Labels

Comments

@mgohin
Copy link

mgohin commented Apr 12, 2018

Using v_1.1.1-11 got a new problem, I got this :

04-12 09:31:15.629 21508-21508/? I/System.out: 09:31:15,628 |-ERROR in ch.qos.logback.core.rolling.RollingFileAppender[rotation] - openFile(/logs/myapp.log,true) failed java.io.FileNotFoundException: /logs/myapp.log: open failed: ENOENT (No such file or directory)
<appender name="rotation" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${DATA_DIR}/logs/myapp.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${DATA_DIR}/logs/myapp.%d{yyyy-MM-dd}.log.zip</fileNamePattern>
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>10MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
            <maxHistory>2</maxHistory>
        </rollingPolicy>
        <encoder>
            <pattern>%date{dd MMM yyyy;HH:mm:ss.SSS} [%thread] %-5level %logger{35} - %msg%n</pattern>
        </encoder>
    </appender>

Devices are on android 4.3, 6.0.1, 8.

@mgohin
Copy link
Author

mgohin commented Apr 12, 2018

I confirm that some keys are empty, here is my test :

<file>${DATA_DIR}/logs/${PACKAGE_NAME}/${EXT_DIR}/${PACKAGE_NAME}/${VERSION_NAME}/${VERSION_CODE}/myapp.log</file>

and got in logs :

10:49:06,125 |-ERROR in ch.qos.logback.core.rolling.RollingFileAppender[rotation] - openFile(/logs///storage/emulated/0////myapp.log,true) failed java.io.FileNotFoundException: /logs/storage/emulated/0/myapp.log (No such file or directory)

@tony19
Copy link
Owner

tony19 commented Apr 12, 2018

That's odd. When you mentioned it working, which version of Android was used?

@tony19 tony19 added this to the 1.1.1-12 milestone Apr 12, 2018
@tony19 tony19 self-assigned this Apr 12, 2018
@tony19
Copy link
Owner

tony19 commented Apr 13, 2018

I can't reproduce this in the emulators. Do you have a sample project that reproduces the problem?

@mgohin
Copy link
Author

mgohin commented Apr 13, 2018

I'll try to give you a sample project. I'm retesting it

@mgohin
Copy link
Author

mgohin commented Apr 13, 2018

Ok, my mistake.

public class App extends MultiDexApplication {

    private static final LoggerHelper log = new LoggerHelper();

So it's initializing the LoggerFactory without any context because App is not loaded yet.
To make it work, I changed for :

public class App extends MultiDexApplication {
    @Override
    public void onCreate() {
        super.onCreate();
        log = new LoggerHelper();
        ....
    }
    ...
}

and it works as expected. Sorry for wasting your time ;)

@mgohin mgohin closed this as completed Apr 13, 2018
@tony19
Copy link
Owner

tony19 commented Apr 13, 2018

No problem. This is useful info that I'll add docs for. Thanks

@tony19 tony19 removed this from the 1.1.1-12 milestone Apr 14, 2018
@stari4ek
Copy link

BTW, this problem was introduced with 1.1.1-10
I have logger initialization inside Application's static fields. And it does work well with 1.1.1-9

AndroidContextUtil.getFilesDirectoryPath() returns empty string

	  at ch.qos.logback.core.android.AndroidContextUtil.getFilesDirectoryPath(AndroidContextUtil.java:145)
	  at ch.qos.logback.core.android.AndroidContextUtil.setupProperties(AndroidContextUtil.java:56)
	  at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:124)
	  at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:85)
	  at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55)
	  at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)
	  at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)
	  at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:412)
	  at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)

	  at by.stari4ek.iptv4atv.app.TVirlApp.<init>(TVirlApp.java:8)

	  at java.lang.Class.newInstance(Class.java:-1)
	  at android.app.Instrumentation.newApplication(Instrumentation.java:1007)
	  at android.app.Instrumentation.newApplication(Instrumentation.java:992)
	  at android.app.LoadedApk.makeApplication(LoadedApk.java:796)

* 1.1.1-9
I/System.out: 23:46:01,373 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - Active log file name: logFile.log
I/System.out: 23:46:01,456 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - File property is set to [/data/data/by.stari4ek.tvirl.debug/files/logFile.log]


* 1.1.1-10
I/System.out: 23:49:02,501 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - Active log file name: logFile.log
I/System.out: 23:49:02,502 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - File property is set to [logFile.log]
I/System.out: 23:49:02,504 |-ERROR in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - openFile(logFile.log,true) failed java.io.FileNotFoundException: logFile.log (Read-only file system)


* 1.1.1-11
06-12 23:54:55.584 10453-10453/by.stari4ek.tvirl.debug I/System.out: 23:54:55,583 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - Active log file name: logFile.log
06-12 23:54:55.585 10453-10453/by.stari4ek.tvirl.debug I/System.out: 23:54:55,585 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - File property is set to [logFile.log]
06-12 23:54:55.589 10453-10453/by.stari4ek.tvirl.debug I/System.out: 23:54:55,586 |-ERROR in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - openFile(logFile.log,true) failed java.io.FileNotFoundException: logFile.log (Read-only file system)

* 1.1.1-12
I/System.out: 23:56:45,999 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - Active log file name: logFile.log
I/System.out: 23:56:46,000 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - File property is set to [logFile.log]
I/System.out: 23:56:46,002 |-ERROR in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - openFile(logFile.log,true) failed java.io.FileNotFoundException: logFile.log (Read-only file system)
                  at java.io.FileNotFoundException: logFile.log (Read-only file system)
                  at 	at java.io.FileOutputStream.open(Native Method)
                  at 	at java.io.FileOutputStream.<init>(FileOutputStream.java:221)
                  at 	at ch.qos.logback.core.recovery.ResilientFileOutputStream.<init>(Unknown Source)
                  at 	at ch.qos.logback.core.FileAppender.openFile(Unknown Source)

@tony19
Copy link
Owner

tony19 commented Jun 13, 2018

@stari4ek In order to improve performance and remove an unnecessary dependency, logback-android now grabs the app context via reflection, and this doesn't work statically (yet). The context is required to determine the user's internal files directory. For now, this is documented in the wiki.

@lock
Copy link

lock bot commented Feb 27, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot added the archived label Feb 27, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Feb 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants