Official docs say you can do this:
FileLogHandlerConfiguration fileHandler = LoggerConfiguration.fileLogHandler(this); fileHandler.setFullFilePathPattern(SOMEPATH); LoggerConfiguration.configuration().addHandlerToRootLogger(fileHandler);
and the log file will be placed in SOMEPATH. I would recommend using a regular environment directory instead of an arbitrary string, e.g.
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS).getPath()+File.pathSeparator+"appLogs"
Now, if you want to copy some existing logs to the outper destination, you can simply copy the files.
if(BuildConfig.DEBUG) { File logs = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS).getPath(), "logs"); FileLogHandlerConfiguration fileHandler = LoggerConfiguration.fileLogHandler(this); LoggerConfiguration.configuration().addHandlerToRootLogger(fileHandler); File currentLogs = fileHandler.getCurrentFileName(); if (currentLogs.exists()) { FileChannel src = new FileInputStream(currentLogs).getChannel(); FileChannel dst = new FileOutputStream(logs).getChannel(); dst.transferFrom(src, 0, src.size()); src.close(); dst.close(); } }
Finally, keep in mind that nothing will work if you do not get the correct permissions to access the repository!
Hope this helps. Happy coding!
source share