mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
commit
5f579fbb24
@ -8,6 +8,7 @@ import java.io.FileWriter;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
public class Log_OC {
|
public class Log_OC {
|
||||||
private static final String SIMPLE_DATE_FORMAT = "yyyy/MM/dd HH:mm:ss";
|
private static final String SIMPLE_DATE_FORMAT = "yyyy/MM/dd HH:mm:ss";
|
||||||
@ -25,50 +26,53 @@ public class Log_OC {
|
|||||||
private static boolean isMaxFileSizeReached = false;
|
private static boolean isMaxFileSizeReached = false;
|
||||||
private static boolean isEnabled = false;
|
private static boolean isEnabled = false;
|
||||||
|
|
||||||
public static void setLogDataFolder(String logFolder){
|
public static void setLogDataFolder(String logFolder) {
|
||||||
mOwncloudDataFolderLog = logFolder;
|
mOwncloudDataFolderLog = logFolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void i(String TAG, String message){
|
public static void i(String TAG, String message) {
|
||||||
Log.i(TAG, 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);
|
Log.d(TAG, message);
|
||||||
appendLog(TAG + " : " + message);
|
appendLog(TAG + " : " + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void d(String TAG, String message, Exception e) {
|
public static void d(String TAG, String message, Exception e) {
|
||||||
Log.d(TAG, message, 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);
|
Log.e(TAG, message);
|
||||||
appendLog(TAG + " : " + message);
|
appendLog(TAG + " : " + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void e(String TAG, String message, Throwable e) {
|
public static void e(String TAG, String message, Throwable e) {
|
||||||
Log.e(TAG, message, 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);
|
Log.v(TAG, message);
|
||||||
appendLog(TAG+" : "+ message);
|
appendLog(TAG + " : " + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void w(String TAG, String message) {
|
public static void w(String TAG, String message) {
|
||||||
Log.w(TAG, message);
|
Log.w(TAG, message);
|
||||||
appendLog(TAG+" : "+ message);
|
appendLog(TAG + " : " + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start doing logging
|
* Start doing logging
|
||||||
|
*
|
||||||
* @param storagePath : directory for keeping logs
|
* @param storagePath : directory for keeping logs
|
||||||
*/
|
*/
|
||||||
synchronized public static void startLogging(String storagePath) {
|
synchronized public static void startLogging(String storagePath) {
|
||||||
String logPath = storagePath + File.separator +
|
String logPath = storagePath + File.separator +
|
||||||
mOwncloudDataFolderLog + File.separator + LOG_FOLDER_NAME;
|
mOwncloudDataFolderLog + File.separator + LOG_FOLDER_NAME;
|
||||||
mFolder = new File(logPath);
|
mFolder = new File(logPath);
|
||||||
mLogFile = new File(mFolder + File.separator + mLogFileNames[0]);
|
mLogFile = new File(mFolder + File.separator + mLogFileNames[0]);
|
||||||
|
|
||||||
@ -80,7 +84,7 @@ public class Log_OC {
|
|||||||
Log.d("LOG_OC", "Log file created");
|
Log.d("LOG_OC", "Log file created");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// Create the current log file if does not exist
|
// Create the current log file if does not exist
|
||||||
mLogFile.createNewFile();
|
mLogFile.createNewFile();
|
||||||
@ -94,10 +98,10 @@ public class Log_OC {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
if(mBuf != null) {
|
if (mBuf != null) {
|
||||||
try {
|
try {
|
||||||
mBuf.close();
|
mBuf.close();
|
||||||
} catch(IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -106,15 +110,15 @@ public class Log_OC {
|
|||||||
|
|
||||||
synchronized public static void stopLogging() {
|
synchronized public static void stopLogging() {
|
||||||
try {
|
try {
|
||||||
if (mBuf != null)
|
if (mBuf != null) {
|
||||||
mBuf.close();
|
mBuf.close();
|
||||||
|
}
|
||||||
isEnabled = false;
|
isEnabled = false;
|
||||||
|
|
||||||
mLogFile = null;
|
mLogFile = null;
|
||||||
mFolder = null;
|
mFolder = null;
|
||||||
mBuf = null;
|
mBuf = null;
|
||||||
isMaxFileSizeReached = false;
|
isMaxFileSizeReached = false;
|
||||||
isEnabled = false;
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// Because we are stopping logging, we only log to Android console.
|
// Because we are stopping logging, we only log to Android console.
|
||||||
@ -132,15 +136,15 @@ public class Log_OC {
|
|||||||
*/
|
*/
|
||||||
public static void deleteHistoryLogging() {
|
public static void deleteHistoryLogging() {
|
||||||
File folderLogs = new File(mFolder + File.separator);
|
File folderLogs = new File(mFolder + File.separator);
|
||||||
if(folderLogs.isDirectory()){
|
if (folderLogs.isDirectory()) {
|
||||||
String[] myFiles = folderLogs.list();
|
String[] myFiles = folderLogs.list();
|
||||||
for (int i=0; i<myFiles.length; i++) {
|
for (String fileName : myFiles) {
|
||||||
File myFile = new File(folderLogs, myFiles[i]);
|
File fileInFolder = new File(folderLogs, fileName);
|
||||||
myFile.delete();
|
Log_OC.d("delete file", fileInFolder.getAbsoluteFile() + " " + fileInFolder.delete());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Append the info of the device
|
* Append the info of the device
|
||||||
*/
|
*/
|
||||||
@ -152,9 +156,10 @@ public class Log_OC {
|
|||||||
appendLog("Version-Codename : " + android.os.Build.VERSION.CODENAME);
|
appendLog("Version-Codename : " + android.os.Build.VERSION.CODENAME);
|
||||||
appendLog("Version-Release : " + android.os.Build.VERSION.RELEASE);
|
appendLog("Version-Release : " + android.os.Build.VERSION.RELEASE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Append to the log file the info passed
|
* Append to the log file the info passed
|
||||||
|
*
|
||||||
* @param text : text for adding to the log file
|
* @param text : text for adding to the log file
|
||||||
*/
|
*/
|
||||||
synchronized private static void appendLog(String text) {
|
synchronized private static void appendLog(String text) {
|
||||||
@ -174,18 +179,15 @@ public class Log_OC {
|
|||||||
isMaxFileSizeReached = false;
|
isMaxFileSizeReached = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String timeStamp = new SimpleDateFormat(SIMPLE_DATE_FORMAT).format(Calendar.getInstance().getTime());
|
String timeStamp = new SimpleDateFormat(SIMPLE_DATE_FORMAT, Locale.ENGLISH).format(Calendar.getInstance().getTime());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mBuf = new BufferedWriter(new FileWriter(mLogFile, true));
|
mBuf = new BufferedWriter(new FileWriter(mLogFile, true));
|
||||||
mBuf.newLine();
|
mBuf.newLine();
|
||||||
mBuf.write(timeStamp);
|
mBuf.write(timeStamp + " " + text);
|
||||||
mBuf.newLine();
|
} catch (IOException e) {
|
||||||
mBuf.write(text);
|
e.printStackTrace();
|
||||||
mBuf.newLine();
|
} finally {
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
try {
|
try {
|
||||||
mBuf.close();
|
mBuf.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user