1 package com
.owncloud
.android
;
3 import java
.io
.BufferedWriter
;
5 import java
.io
.FileWriter
;
6 import java
.io
.IOException
;
7 import java
.text
.SimpleDateFormat
;
9 import java
.util
.Locale
;
11 import android
.util
.Log
;
18 private static boolean isEnabled
= false
;
19 private static File logFile
;
20 private static File folder
;
21 private static BufferedWriter buf
;
23 public static void i(String TAG
, String message
){
24 // Printing the message to LogCat console
26 // Write the log message to the file
27 appendLog(TAG
+" : "+message
);
30 public static void d(String TAG
, String message
){
32 appendLog(TAG
+ " : " + message
);
34 public static void d(String TAG
, String message
, Exception e
) {
35 Log
.d(TAG
, message
, e
);
36 appendLog(TAG
+ " : " + message
+ " Exception : "+ e
.getStackTrace());
38 public static void e(String TAG
, String message
){
40 appendLog(TAG
+ " : " + message
);
43 public static void e(String TAG
, String message
, Throwable e
) {
44 Log
.e(TAG
, message
, e
);
45 appendLog(TAG
+" : " + message
+" Exception : " + e
.getStackTrace());
48 public static void v(String TAG
, String message
){
50 appendLog(TAG
+" : "+ message
);
53 public static void w(String TAG
, String message
) {
55 appendLog(TAG
+" : "+ message
);
58 public static void wtf(String TAG
, String message
) {
60 appendLog(TAG
+" : "+ message
);
63 public static void startLogging(String logPath
) {
64 folder
= new File(logPath
);
65 logFile
= new File(folder
+ File
.separator
+ "log.txt");
67 if (!folder
.exists()) {
70 if (logFile
.exists()) {
74 logFile
.createNewFile();
75 buf
= new BufferedWriter(new FileWriter(logFile
, true
));
78 }catch (IOException e
){
83 public static void stopLogging() {
84 SimpleDateFormat sdf
= new SimpleDateFormat("yyyyMMdd_HHmmss", Locale
.getDefault());
85 String currentDateandTime
= sdf
.format(new Date());
86 if (logFile
!= null
) {
87 logFile
.renameTo(new File(folder
+ File
.separator
+ MainApp
.getLogName() + currentDateandTime
+".log"));
92 } catch (IOException e
) {
100 private static void appendPhoneInfo() {
101 appendLog("Model : " + android
.os
.Build
.MODEL
);
102 appendLog("Brand : " + android
.os
.Build
.BRAND
);
103 appendLog("Product : " + android
.os
.Build
.PRODUCT
);
104 appendLog("Device : " + android
.os
.Build
.DEVICE
);
105 appendLog("Version-Codename : " + android
.os
.Build
.VERSION
.CODENAME
);
106 appendLog("Version-Release : " + android
.os
.Build
.VERSION
.RELEASE
);
109 private static void appendLog(String text
) {
114 } catch (IOException e
) {