Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/src/main/java/ca/pkay/rcloneexplorer/Log2File.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public Log2File(Context context) {

public void log(String message) {
File path = context.getExternalFilesDir("logs");
if (path == null) {
FLog.e(TAG, "log: external storage not available, cannot write log");
return;
}
File logFile = new File(path, "log.txt");

clearLogsIfTooBif(logFile);
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/java/ca/pkay/rcloneexplorer/Rclone.java
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,13 @@ public Process sync(RemoteItem remoteItem, String localPath, String remotePath,
String localRemotePath = (remoteItem.isRemoteType(RemoteItem.LOCAL)) ? getLocalRemotePathPrefix(remoteItem, context) + "/" : "";
String remoteSection = (remotePath.compareTo("//" + remoteName) == 0) ? remoteName + ":" + localRemotePath : remoteName + ":" + localRemotePath + remotePath;

ArrayList<String> defaultParameter = new ArrayList<>(Arrays.asList("--transfers", "1", "--stats=1s", "--stats-log-level", "NOTICE", "--use-json-log"));
boolean loggingEnabled = PreferenceManager
.getDefaultSharedPreferences(context)
.getBoolean(context.getString(R.string.pref_key_logs), false);
ArrayList<String> defaultParameter = new ArrayList<>(Arrays.asList("--transfers", "1", "--stats=1s", "--use-json-log"));
if (!loggingEnabled) {
defaultParameter.addAll(Arrays.asList("--stats-log-level", "NOTICE", "--log-level", "INFO"));
}
ArrayList<String> directionParameter = new ArrayList<>();

if(useMD5Sum){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ class EphemeralWorker (private var mContext: Context, workerParams: WorkerParame

override fun doWork(): Result {

if (sIsLoggingEnabled) {
log2File = Log2File(mContext)
}

registerBroadcastReceivers()

updateForegroundNotification(mNotificationManager?.updateNotification(
Expand Down
43 changes: 37 additions & 6 deletions app/src/main/java/ca/pkay/rcloneexplorer/workmanager/SyncWorker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ class SyncWorker (private var mContext: Context, workerParams: WorkerParameters)

override fun doWork(): Result {

if (sIsLoggingEnabled) {
log2File = Log2File(mContext)
}

prepareNotifications()
registerBroadcastReceivers()

Expand Down Expand Up @@ -176,6 +180,8 @@ class SyncWorker (private var mContext: Context, workerParams: WorkerParameters)
SyncLog.info(mContext, mTitle, mContext.getString(R.string.operation_start_sync))
if (sRcloneProcess != null) {
val localProcessReference = sRcloneProcess!!
val infoLines = StringBuilder()
var lastStats = ""
try {
val reader = BufferedReader(InputStreamReader(localProcessReference.errorStream))
val iterator = reader.lineSequence().iterator()
Expand All @@ -184,13 +190,28 @@ class SyncWorker (private var mContext: Context, workerParams: WorkerParameters)
try {
val logline = JSONObject(line)
//todo: migrate this to StatusObject, so that we can handle everything properly.
if (logline.getString("level") == "error") {
if (sIsLoggingEnabled) {
log2File?.log(line)
when (logline.getString("level")) {
"error" -> {
if (sIsLoggingEnabled) {
log2File?.log(line)
}
statusObject.parseLoglineToStatusObject(logline)
}
"warning" -> {
statusObject.parseLoglineToStatusObject(logline)
}
"info" -> {
val msg = logline.optString("msg", "")
if (msg.isNotEmpty()) {
infoLines.append(msg).append("\n")
}
}
"notice" -> {
val msg = logline.optString("msg", "")
if (msg.isNotEmpty()) {
lastStats = msg
}
}
statusObject.parseLoglineToStatusObject(logline)
} else if (logline.getString("level") == "warning") {
statusObject.parseLoglineToStatusObject(logline)
}

updateForegroundNotification(mNotificationManager.updateSyncNotification(
Expand All @@ -210,6 +231,16 @@ class SyncWorker (private var mContext: Context, workerParams: WorkerParameters)
} catch (e: IOException) {
FLog.e(TAG, "onHandleIntent: error reading stdout", e)
}
val detail = buildString {
if (infoLines.isNotEmpty()) append(infoLines.trimEnd())
if (lastStats.isNotEmpty()) {
if (isNotEmpty()) append("\n\n")
append(lastStats)
}
}
if (detail.isNotEmpty()) {
SyncLog.info(mContext, mTitle, detail)
}
try {
localProcessReference.waitFor()
} catch (e: InterruptedException) {
Expand Down