From 7954bdbcdd8612849ede2a9277e10d07182b7a57 Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Wed, 19 Dec 2018 08:49:37 +0100 Subject: [PATCH 1/4] compact logfile time and text in same line, no empty lines --- .../owncloud/android/lib/common/utils/Log_OC.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/Log_OC.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/Log_OC.java index ca30f1d8..978a0bbf 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/Log_OC.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/Log_OC.java @@ -8,6 +8,7 @@ import java.io.FileWriter; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Calendar; +import java.util.Locale; public class Log_OC { private static final String SIMPLE_DATE_FORMAT = "yyyy/MM/dd HH:mm:ss"; @@ -114,7 +115,6 @@ public class Log_OC { mFolder = null; mBuf = null; isMaxFileSizeReached = false; - isEnabled = false; } catch (IOException e) { // Because we are stopping logging, we only log to Android console. @@ -134,8 +134,8 @@ public class Log_OC { File folderLogs = new File(mFolder + File.separator); if(folderLogs.isDirectory()){ String[] myFiles = folderLogs.list(); - for (int i=0; i Date: Fri, 28 Dec 2018 19:38:17 +0100 Subject: [PATCH 2/4] Log delete logfile result --- .../main/java/com/owncloud/android/lib/common/utils/Log_OC.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/Log_OC.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/Log_OC.java index 978a0bbf..621a92c7 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/Log_OC.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/Log_OC.java @@ -136,7 +136,7 @@ public class Log_OC { String[] myFiles = folderLogs.list(); for (String myFile1 : myFiles) { File myFile = new File(folderLogs, myFile1); - myFile.delete(); + Log_OC.d("delete file", myFile.getAbsoluteFile() + " " + myFile.delete()); } } } From 6560aa987db2134f06385d971c87a5b2ad009385 Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Sat, 19 Jan 2019 23:28:22 +0100 Subject: [PATCH 3/4] apply codestyle request for complete file --- .../android/lib/common/utils/Log_OC.java | 67 ++++++++++--------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/Log_OC.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/Log_OC.java index 621a92c7..93bd0e56 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/Log_OC.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/Log_OC.java @@ -26,50 +26,53 @@ public class Log_OC { private static boolean isMaxFileSizeReached = false; private static boolean isEnabled = false; - public static void setLogDataFolder(String logFolder){ - mOwncloudDataFolderLog = logFolder; + public static void setLogDataFolder(String logFolder) { + mOwncloudDataFolderLog = logFolder; } - public static void i(String TAG, String message){ + public static void i(String TAG, String message) { Log.i(TAG, message); - appendLog(TAG+" : "+ message); + appendLog(TAG + " : " + message); } - public static void d(String TAG, String message){ + public static void d(String TAG, String message) { Log.d(TAG, message); appendLog(TAG + " : " + message); } + public static void d(String TAG, String message, Exception e) { Log.d(TAG, message, e); - appendLog(TAG + " : " + message + " Exception : "+ e.getStackTrace()); + appendLog(TAG + " : " + message + " Exception : " + e.getStackTrace()); } - public static void e(String TAG, String message){ + + public static void e(String TAG, String message) { Log.e(TAG, message); appendLog(TAG + " : " + message); } - + public static void e(String TAG, String message, Throwable e) { Log.e(TAG, message, e); - appendLog(TAG+" : " + message +" Exception : " + e.getStackTrace()); + appendLog(TAG + " : " + message + " Exception : " + e.getStackTrace()); } - - public static void v(String TAG, String message){ + + public static void v(String TAG, String message) { Log.v(TAG, message); - appendLog(TAG+" : "+ message); + appendLog(TAG + " : " + message); } - + public static void w(String TAG, String message) { Log.w(TAG, message); - appendLog(TAG+" : "+ message); + appendLog(TAG + " : " + message); } /** * Start doing logging + * * @param storagePath : directory for keeping logs */ synchronized public static void startLogging(String storagePath) { - String logPath = storagePath + File.separator + - mOwncloudDataFolderLog + File.separator + LOG_FOLDER_NAME; + String logPath = storagePath + File.separator + + mOwncloudDataFolderLog + File.separator + LOG_FOLDER_NAME; mFolder = new File(logPath); mLogFile = new File(mFolder + File.separator + mLogFileNames[0]); @@ -81,7 +84,7 @@ public class Log_OC { Log.d("LOG_OC", "Log file created"); } - try { + try { // Create the current log file if does not exist mLogFile.createNewFile(); @@ -95,10 +98,10 @@ public class Log_OC { } catch (IOException e) { e.printStackTrace(); } finally { - if(mBuf != null) { + if (mBuf != null) { try { mBuf.close(); - } catch(IOException e) { + } catch (IOException e) { e.printStackTrace(); } } @@ -107,8 +110,9 @@ public class Log_OC { synchronized public static void stopLogging() { try { - if (mBuf != null) + if (mBuf != null) { mBuf.close(); + } isEnabled = false; mLogFile = null; @@ -132,7 +136,7 @@ public class Log_OC { */ public static void deleteHistoryLogging() { File folderLogs = new File(mFolder + File.separator); - if(folderLogs.isDirectory()){ + if (folderLogs.isDirectory()) { String[] myFiles = folderLogs.list(); for (String myFile1 : myFiles) { File myFile = new File(folderLogs, myFile1); @@ -140,7 +144,7 @@ public class Log_OC { } } } - + /** * Append the info of the device */ @@ -152,9 +156,10 @@ public class Log_OC { appendLog("Version-Codename : " + android.os.Build.VERSION.CODENAME); appendLog("Version-Release : " + android.os.Build.VERSION.RELEASE); } - + /** * Append to the log file the info passed + * * @param text : text for adding to the log file */ synchronized private static void appendLog(String text) { @@ -174,15 +179,15 @@ public class Log_OC { isMaxFileSizeReached = false; } - String timeStamp = new SimpleDateFormat(SIMPLE_DATE_FORMAT, Locale.ENGLISH).format(Calendar.getInstance().getTime()); + String timeStamp = new SimpleDateFormat(SIMPLE_DATE_FORMAT, Locale.ENGLISH).format(Calendar.getInstance().getTime()); - try { - mBuf = new BufferedWriter(new FileWriter(mLogFile, true)); - mBuf.newLine(); - mBuf.write(timeStamp+" "+text); - } catch (IOException e) { - e.printStackTrace(); - } finally { + try { + mBuf = new BufferedWriter(new FileWriter(mLogFile, true)); + mBuf.newLine(); + mBuf.write(timeStamp + " " + text); + } catch (IOException e) { + e.printStackTrace(); + } finally { try { mBuf.close(); } catch (IOException e) { From 940f0b9bb042e3c318e4cbeff71782e0d8733f93 Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Sat, 19 Jan 2019 23:35:25 +0100 Subject: [PATCH 4/4] adapt variable name --- .../java/com/owncloud/android/lib/common/utils/Log_OC.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/Log_OC.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/Log_OC.java index 93bd0e56..bdfc2645 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/Log_OC.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/Log_OC.java @@ -138,9 +138,9 @@ public class Log_OC { File folderLogs = new File(mFolder + File.separator); if (folderLogs.isDirectory()) { String[] myFiles = folderLogs.list(); - for (String myFile1 : myFiles) { - File myFile = new File(folderLogs, myFile1); - Log_OC.d("delete file", myFile.getAbsoluteFile() + " " + myFile.delete()); + for (String fileName : myFiles) { + File fileInFolder = new File(folderLogs, fileName); + Log_OC.d("delete file", fileInFolder.getAbsoluteFile() + " " + fileInFolder.delete()); } } }