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

collectLogFile and getFilesDir() #334

Closed
gregd opened this issue Dec 3, 2015 · 3 comments
Closed

collectLogFile and getFilesDir() #334

gregd opened this issue Dec 3, 2015 · 3 comments

Comments

@gregd
Copy link
Contributor

gregd commented Dec 3, 2015

Below is code fragment used to read an application log file

if (fileName.contains("/")) {
    return new BufferedReader(new InputStreamReader(new FileInputStream(fileName)), 1024);
} else {
    return new BufferedReader(new InputStreamReader(context.openFileInput(fileName)), 1024);
}

The problem is when a log file is in the main package sub directory.

@ReportsCrashes(
        applicationLogFile = "files/logs/app.log",
        applicationLogFileLines = 200,

ACRA won't find a such file. Because new FileInputStream() uses root directory as starting point on Android. So one have to hard code an absolute path, for example /data/data/com.example.app/files/logs/app.log. For many reasons this is not a good practice. A fix is very simple

if (fileName.startsWith("/")) {

I really can't imagine any edge case when fileName.contains("/") is more correct. new FileInputStream() should be used only when a full path is passed to the ACRA config. And a full path should always start with /.

@william-ferguson-au
Copy link
Member

Yeah, that looks like a straight out error to me.
Want to submit a PR?

@gregd
Copy link
Contributor Author

gregd commented Dec 4, 2015

#336
It turned out that the fix is a little bit more complicated because openFileInput doesn't work with path separators. The code from the pull request assumes that when a relative log file path is passed to ACRA, then it must be in the files directory or its sub-directory, for example applicationLogFile = "logs/app.log" I tested this with logback-android and the fix works fine.

@william-ferguson-au
Copy link
Member

#336 Merged - thanks.

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

No branches or pull requests

2 participants