From 9a34045fe5ecd5a316e189b98a693d70f5159401 Mon Sep 17 00:00:00 2001 From: Bartosz Przybylski Date: Sat, 7 Nov 2015 18:07:19 +0100 Subject: [PATCH 1/8] 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 2bef4fc938..900d0b57ee 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 static void wtf(String TAG, String message) { /** * 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 fbb7bbe9b9195883b5cb9ae55524518a6fd84c47 Mon Sep 17 00:00:00 2001 From: Bartosz Przybylski Date: Mon, 9 Nov 2015 17:45:59 +0100 Subject: [PATCH 2/8] 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 900d0b57ee..628777b2b5 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 static void w(String TAG, String message) { } public static void wtf(String TAG, String message) { - Log.wtf(TAG,message); + Log.wtf(TAG, message); appendLog(TAG+" : "+ message); } @@ -111,6 +111,22 @@ public static void startLogging(String storagePath) { } } + 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 d54fa5ed80531c7c14f6d021a7bb4c538916d9e0 Mon Sep 17 00:00:00 2001 From: Bartosz Przybylski Date: Sat, 21 Nov 2015 13:03:55 +0100 Subject: [PATCH 3/8] 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 628777b2b5..71e3d02e92 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 static void startLogging(String storagePath) { public static void stopLogging() { try { - mBuf.close(); + if (mBuf != null) + mBuf.close(); isEnabled = false; mLogFile = null; @@ -123,7 +124,13 @@ public static void stopLogging() { 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 5eaaa3320955305ccc923db0e4fae7626918857b Mon Sep 17 00:00:00 2001 From: Bartosz Przybylski Date: Sat, 21 Nov 2015 13:11:34 +0100 Subject: [PATCH 4/8] 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 71e3d02e92..5aa85cc1ee 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 static void stopLogging() { 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 2b5bd6edb2bb12b393af8b769018dea8a5b2a427 Mon Sep 17 00:00:00 2001 From: Bartosz Przybylski Date: Sat, 21 Nov 2015 17:22:12 +0100 Subject: [PATCH 5/8] 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 5aa85cc1ee..9670061ff9 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 static void wtf(String TAG, String message) { * 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 static void startLogging(String storagePath) { } } - public static void stopLogging() { + synchronized public static void stopLogging() { try { if (mBuf != null) mBuf.close(); @@ -164,7 +164,7 @@ private static void appendPhoneInfo() { * 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) { From 225748f8e5d5cbc635a7876764a1b96d22884aa8 Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Sun, 3 Jul 2016 14:19:17 +0200 Subject: [PATCH 6/8] fix identation --- src/com/owncloud/android/lib/common/utils/Log_OC.java | 7 +++---- 1 file changed, 3 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 9670061ff9..976952caaa 100644 --- a/src/com/owncloud/android/lib/common/utils/Log_OC.java +++ b/src/com/owncloud/android/lib/common/utils/Log_OC.java @@ -1,5 +1,7 @@ package com.owncloud.android.lib.common.utils; +import android.util.Log; + import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; @@ -7,9 +9,6 @@ import java.text.SimpleDateFormat; import java.util.Calendar; -import android.os.Environment; -import android.util.Log; - public class Log_OC { private static final String SIMPLE_DATE_FORMAT = "yyyy/MM/dd HH:mm:ss"; @@ -113,7 +112,7 @@ synchronized public static void startLogging(String storagePath) { synchronized public static void stopLogging() { try { - if (mBuf != null) + if (mBuf != null) mBuf.close(); isEnabled = false; From 99cb4cb05bf37da93d00668dae795b248e8c63d7 Mon Sep 17 00:00:00 2001 From: Bartosz Przybylski Date: Sat, 9 Jul 2016 21:20:33 +0200 Subject: [PATCH 7/8] Don't use printStackTrace, use Android log instead --- .../android/lib/common/utils/Log_OC.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 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 976952caaa..f63f880933 100644 --- a/src/com/owncloud/android/lib/common/utils/Log_OC.java +++ b/src/com/owncloud/android/lib/common/utils/Log_OC.java @@ -15,7 +15,9 @@ public class Log_OC { private static final String LOG_FOLDER_NAME = "log"; private static final long MAX_FILE_SIZE = 1000000; // 1MB - private static String mOwncloudDataFolderLog = "owncloud_log"; + private static final String TAG = Log_OC.class.getSimpleName(); + + private static String mNextcloudDataFolderLog = "nextcloud_log"; private static File mLogFile; private static File mFolder; @@ -27,7 +29,7 @@ public class Log_OC { private static boolean isEnabled = false; public static void setLogDataFolder(String logFolder){ - mOwncloudDataFolderLog = logFolder; + mNextcloudDataFolderLog = logFolder; } public static void i(String TAG, String message){ @@ -74,7 +76,7 @@ public static void wtf(String TAG, String message) { */ synchronized public static void startLogging(String storagePath) { String logPath = storagePath + File.separator + - mOwncloudDataFolderLog + File.separator + LOG_FOLDER_NAME; + mNextcloudDataFolderLog + File.separator + LOG_FOLDER_NAME; mFolder = new File(logPath); mLogFile = new File(mFolder + File.separator + mLogFileNames[0]); @@ -83,7 +85,7 @@ synchronized public static void startLogging(String storagePath) { if (!mFolder.exists()) { mFolder.mkdirs(); isFileCreated = true; - Log.d("LOG_OC", "Log file created"); + Log.d(TAG, "Log file created"); } try { @@ -98,13 +100,13 @@ synchronized public static void startLogging(String storagePath) { } } catch (IOException e) { - e.printStackTrace(); + Log.e(TAG, "Log initialization failed", e); } finally { if(mBuf != null) { try { mBuf.close(); } catch(IOException e) { - e.printStackTrace(); + Log.e(TAG, "Initialization finishing failed", e); } } } @@ -124,12 +126,12 @@ synchronized public static void stopLogging() { } catch (IOException e) { // Because we are stopping logging, we only log to Android console. - Log.e("OC_Log", "Closing log file failed: ", e); + Log.e(TAG, "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 log to Android console. - Log.e("OC_Log", "Stopping logging failed: ", e); + Log.e(TAG, "Stopping logging failed: ", e); } } @@ -190,12 +192,12 @@ synchronized private static void appendLog(String text) { mBuf.write(text); mBuf.newLine(); } catch (IOException e) { - e.printStackTrace(); + Log.e(TAG, "Writing to logfile failed", e); } finally { try { mBuf.close(); } catch (IOException e) { - e.printStackTrace(); + Log.e(TAG, "Cleaning after logging failed", e); } } From 847e11f985c18954b89cb3446fd54eaafa026cbc Mon Sep 17 00:00:00 2001 From: Bartosz Przybylski Date: Sat, 9 Jul 2016 21:23:09 +0200 Subject: [PATCH 8/8] tabs to spaces --- src/com/owncloud/android/lib/common/utils/Log_OC.java | 2 +- 1 file changed, 1 insertion(+), 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 f63f880933..408856ade0 100644 --- a/src/com/owncloud/android/lib/common/utils/Log_OC.java +++ b/src/com/owncloud/android/lib/common/utils/Log_OC.java @@ -75,7 +75,7 @@ public static void wtf(String TAG, String message) { * @param storagePath : directory for keeping logs */ synchronized public static void startLogging(String storagePath) { - String logPath = storagePath + File.separator + + String logPath = storagePath + File.separator + mNextcloudDataFolderLog + File.separator + LOG_FOLDER_NAME; mFolder = new File(logPath); mLogFile = new File(mFolder + File.separator + mLogFileNames[0]);