mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-08 08:26:10 +00:00
Update logger for not start logging each time it is something appended
This commit is contained in:
parent
cb7b547cd7
commit
0924277662
@ -25,6 +25,7 @@ public class Log_OC {
|
|||||||
private static String[] mLogFileNames = {"currentLog.txt", "olderLog.txt"};
|
private static String[] mLogFileNames = {"currentLog.txt", "olderLog.txt"};
|
||||||
|
|
||||||
private static boolean isMaxFileSizeReached = false;
|
private static boolean isMaxFileSizeReached = false;
|
||||||
|
private static boolean isEnabled = false;
|
||||||
|
|
||||||
public static void setLogDataFolder(String logFolder){
|
public static void setLogDataFolder(String logFolder){
|
||||||
mOwncloudDataFolderLog = logFolder;
|
mOwncloudDataFolderLog = logFolder;
|
||||||
@ -89,30 +90,15 @@ public class Log_OC {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if (isMaxFileSizeReached) {
|
|
||||||
|
|
||||||
// Move current log file info to another file (old logs)
|
|
||||||
File olderFile = new File(mFolder + File.separator + mLogFileNames[1]);
|
|
||||||
if (mLogFile.exists()) {
|
|
||||||
mLogFile.renameTo(olderFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Construct a new file for current log info
|
|
||||||
mLogFile = new File(mFolder + File.separator + mLogFileNames[0]);
|
|
||||||
isMaxFileSizeReached = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the current log file if does not exist
|
// Create the current log file if does not exist
|
||||||
mLogFile.createNewFile();
|
mLogFile.createNewFile();
|
||||||
mBuf = new BufferedWriter(new FileWriter(mLogFile, true));
|
mBuf = new BufferedWriter(new FileWriter(mLogFile, true));
|
||||||
|
isEnabled = true;
|
||||||
|
|
||||||
if (isFileCreated) {
|
if (isFileCreated) {
|
||||||
appendPhoneInfo();
|
appendPhoneInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if current log file size is bigger than the max file size defined
|
|
||||||
if (mLogFile.length() > MAX_FILE_SIZE) {
|
|
||||||
isMaxFileSizeReached = true;
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -150,7 +136,20 @@ public class Log_OC {
|
|||||||
*/
|
*/
|
||||||
private static void appendLog(String text) {
|
private static void appendLog(String text) {
|
||||||
|
|
||||||
startLogging();
|
if (isEnabled) {
|
||||||
|
|
||||||
|
if (isMaxFileSizeReached) {
|
||||||
|
|
||||||
|
// Move current log file info to another file (old logs)
|
||||||
|
File olderFile = new File(mFolder + File.separator + mLogFileNames[1]);
|
||||||
|
if (mLogFile.exists()) {
|
||||||
|
mLogFile.renameTo(olderFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Construct a new file for current log info
|
||||||
|
mLogFile = new File(mFolder + File.separator + mLogFileNames[0]);
|
||||||
|
isMaxFileSizeReached = false;
|
||||||
|
}
|
||||||
|
|
||||||
String timeStamp = new SimpleDateFormat(SIMPLE_DATE_FORMAT).format(Calendar.getInstance().getTime());
|
String timeStamp = new SimpleDateFormat(SIMPLE_DATE_FORMAT).format(Calendar.getInstance().getTime());
|
||||||
|
|
||||||
@ -165,13 +164,16 @@ public class Log_OC {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if current log file size is bigger than the max file size defined
|
||||||
|
if (mLogFile.length() > MAX_FILE_SIZE) {
|
||||||
|
isMaxFileSizeReached = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String[] getLogFileNames() {
|
public static String[] getLogFileNames() {
|
||||||
return mLogFileNames;
|
return mLogFileNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setmLogFileNames(String[] logFileNames) {
|
|
||||||
Log_OC.mLogFileNames = logFileNames;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user