From 9adb155f7e79237582d9bac392d6e1a2b6f04cd1 Mon Sep 17 00:00:00 2001 From: Bartosz Przybylski Date: Sat, 7 Nov 2015 18:07:19 +0100 Subject: [PATCH 1/5] Bring back storagePath argument in startLogging --- src/com/owncloud/android/lib/common/utils/Log_OC.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/com/owncloud/android/lib/common/utils/Log_OC.java b/src/com/owncloud/android/lib/common/utils/Log_OC.java index 2bef4fc9..900d0b57 100644 --- a/src/com/owncloud/android/lib/common/utils/Log_OC.java +++ b/src/com/owncloud/android/lib/common/utils/Log_OC.java @@ -71,11 +71,11 @@ public class Log_OC { /** * Start doing logging - * @param logPath : path of log file + * @param storagePath : directory for keeping logs */ - public static void startLogging() { - String logPath = Environment.getExternalStorageDirectory() + File.separator + - mOwncloudDataFolderLog + File.separator + LOG_FOLDER_NAME; + public static void startLogging(String storagePath) { + String logPath = storagePath + File.separator + + mOwncloudDataFolderLog + File.separator + LOG_FOLDER_NAME; mFolder = new File(logPath); mLogFile = new File(mFolder + File.separator + mLogFileNames[0]); From 9cbf572510a138903e564f5571e90217cf2f9740 Mon Sep 17 00:00:00 2001 From: Bartosz Przybylski Date: Mon, 9 Nov 2015 17:45:59 +0100 Subject: [PATCH 2/5] Add stopLogging method to Log_OC --- .../android/lib/common/utils/Log_OC.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/com/owncloud/android/lib/common/utils/Log_OC.java b/src/com/owncloud/android/lib/common/utils/Log_OC.java index 900d0b57..628777b2 100644 --- a/src/com/owncloud/android/lib/common/utils/Log_OC.java +++ b/src/com/owncloud/android/lib/common/utils/Log_OC.java @@ -65,7 +65,7 @@ public class Log_OC { } public static void wtf(String TAG, String message) { - Log.wtf(TAG,message); + Log.wtf(TAG, message); appendLog(TAG+" : "+ message); } @@ -111,6 +111,22 @@ public class Log_OC { } } + public static void stopLogging() { + try { + mBuf.close(); + isEnabled = false; + + mLogFile = null; + mFolder = null; + mBuf = null; + isMaxFileSizeReached = false; + isEnabled = false; + + } catch (IOException e) { + e.printStackTrace(); + } + } + /** * Delete history logging */ From 080b3f56fcd0f1d53a3d0908c6330204d07138b7 Mon Sep 17 00:00:00 2001 From: Bartosz Przybylski Date: Sat, 21 Nov 2015 13:03:55 +0100 Subject: [PATCH 3/5] Stop logging in exception free way --- src/com/owncloud/android/lib/common/utils/Log_OC.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/com/owncloud/android/lib/common/utils/Log_OC.java b/src/com/owncloud/android/lib/common/utils/Log_OC.java index 628777b2..71e3d02e 100644 --- a/src/com/owncloud/android/lib/common/utils/Log_OC.java +++ b/src/com/owncloud/android/lib/common/utils/Log_OC.java @@ -113,7 +113,8 @@ public class Log_OC { public static void stopLogging() { try { - mBuf.close(); + if (mBuf != null) + mBuf.close(); isEnabled = false; mLogFile = null; @@ -123,7 +124,13 @@ public class Log_OC { isEnabled = false; } catch (IOException e) { - e.printStackTrace(); + // Because we are stopping logging, we only lon to Android console. + Log.e("OC_Log", "Closing log file failed: ", e); + } catch (Exception e) { + // This catch should never fire because we do null check on mBuf. + // But just for the sake of stability let's log this odd situation. + // Because we are stopping logging, we only lon to Android console. + Log.e("OC_Log", "Stopping logging failed: ", e); } } From 17325dd43f2b746f6c10cf7f66d1bd03f27e4f35 Mon Sep 17 00:00:00 2001 From: Bartosz Przybylski Date: Sat, 21 Nov 2015 13:11:34 +0100 Subject: [PATCH 4/5] Update Log_OC.java Fix typos --- src/com/owncloud/android/lib/common/utils/Log_OC.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/com/owncloud/android/lib/common/utils/Log_OC.java b/src/com/owncloud/android/lib/common/utils/Log_OC.java index 71e3d02e..5aa85cc1 100644 --- a/src/com/owncloud/android/lib/common/utils/Log_OC.java +++ b/src/com/owncloud/android/lib/common/utils/Log_OC.java @@ -124,12 +124,12 @@ public class Log_OC { isEnabled = false; } catch (IOException e) { - // Because we are stopping logging, we only lon to Android console. + // Because we are stopping logging, we only log to Android console. Log.e("OC_Log", "Closing log file failed: ", e); } catch (Exception e) { // This catch should never fire because we do null check on mBuf. // But just for the sake of stability let's log this odd situation. - // Because we are stopping logging, we only lon to Android console. + // Because we are stopping logging, we only log to Android console. Log.e("OC_Log", "Stopping logging failed: ", e); } } From 45650d2307bd512a4896d532cc91a5a6a9fd6206 Mon Sep 17 00:00:00 2001 From: Bartosz Przybylski Date: Sat, 21 Nov 2015 17:22:12 +0100 Subject: [PATCH 5/5] Sychronize methods for logging starting and stopping. First of, this will prevent logs mixing, sencondly this will allow user to safely migrate data even when other thread will call logging functions --- src/com/owncloud/android/lib/common/utils/Log_OC.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/com/owncloud/android/lib/common/utils/Log_OC.java b/src/com/owncloud/android/lib/common/utils/Log_OC.java index 5aa85cc1..9670061f 100644 --- a/src/com/owncloud/android/lib/common/utils/Log_OC.java +++ b/src/com/owncloud/android/lib/common/utils/Log_OC.java @@ -73,7 +73,7 @@ public class Log_OC { * Start doing logging * @param storagePath : directory for keeping logs */ - public static void startLogging(String storagePath) { + synchronized public static void startLogging(String storagePath) { String logPath = storagePath + File.separator + mOwncloudDataFolderLog + File.separator + LOG_FOLDER_NAME; mFolder = new File(logPath); @@ -111,7 +111,7 @@ public class Log_OC { } } - public static void stopLogging() { + synchronized public static void stopLogging() { try { if (mBuf != null) mBuf.close(); @@ -164,7 +164,7 @@ public class Log_OC { * Append to the log file the info passed * @param text : text for adding to the log file */ - private static void appendLog(String text) { + synchronized private static void appendLog(String text) { if (isEnabled) {