Loading src/com/owncloud/android/lib/common/utils/Log_OC.java +40 −16 Original line number Diff line number Diff line package com.owncloud.android.lib.common.utils; import android.util.Log; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; Loading @@ -7,16 +9,15 @@ import java.io.IOException; 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"; 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; Loading @@ -28,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){ Loading Loading @@ -71,11 +72,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; synchronized public static void startLogging(String storagePath) { String logPath = storagePath + File.separator + mNextcloudDataFolderLog + File.separator + LOG_FOLDER_NAME; mFolder = new File(logPath); mLogFile = new File(mFolder + File.separator + mLogFileNames[0]); Loading @@ -84,7 +85,7 @@ public class Log_OC { if (!mFolder.exists()) { mFolder.mkdirs(); isFileCreated = true; Log.d("LOG_OC", "Log file created"); Log.d(TAG, "Log file created"); } try { Loading @@ -99,15 +100,38 @@ public class Log_OC { } } 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); } } } } synchronized public static void stopLogging() { try { if (mBuf != null) mBuf.close(); isEnabled = false; mLogFile = null; mFolder = null; mBuf = null; isMaxFileSizeReached = false; isEnabled = false; } catch (IOException e) { // Because we are stopping logging, we only log to Android console. 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(TAG, "Stopping logging failed: ", e); } } Loading Loading @@ -141,7 +165,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) { Loading @@ -168,12 +192,12 @@ public class Log_OC { 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); } } Loading Loading
src/com/owncloud/android/lib/common/utils/Log_OC.java +40 −16 Original line number Diff line number Diff line package com.owncloud.android.lib.common.utils; import android.util.Log; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; Loading @@ -7,16 +9,15 @@ import java.io.IOException; 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"; 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; Loading @@ -28,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){ Loading Loading @@ -71,11 +72,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; synchronized public static void startLogging(String storagePath) { String logPath = storagePath + File.separator + mNextcloudDataFolderLog + File.separator + LOG_FOLDER_NAME; mFolder = new File(logPath); mLogFile = new File(mFolder + File.separator + mLogFileNames[0]); Loading @@ -84,7 +85,7 @@ public class Log_OC { if (!mFolder.exists()) { mFolder.mkdirs(); isFileCreated = true; Log.d("LOG_OC", "Log file created"); Log.d(TAG, "Log file created"); } try { Loading @@ -99,15 +100,38 @@ public class Log_OC { } } 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); } } } } synchronized public static void stopLogging() { try { if (mBuf != null) mBuf.close(); isEnabled = false; mLogFile = null; mFolder = null; mBuf = null; isMaxFileSizeReached = false; isEnabled = false; } catch (IOException e) { // Because we are stopping logging, we only log to Android console. 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(TAG, "Stopping logging failed: ", e); } } Loading Loading @@ -141,7 +165,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) { Loading @@ -168,12 +192,12 @@ public class Log_OC { 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); } } Loading