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
;
16 private static boolean isEnabled
= false
;
17 private static File logFile
;
18 private static File folder
;
19 private static BufferedWriter buf
;
21 public static void i(String TAG
, String message
){
22 // Printing the message to LogCat console
24 // Write the log message to the file
25 appendLog(TAG
+" : "+message
);
28 public static void d(String TAG
, String message
){
30 appendLog(TAG
+" : "+message
);
32 public static void d(String TAG
, String message
, Exception e
) {
33 Log
.d(TAG
, message
, e
);
34 appendLog(TAG
+" : "+ message
+" Exception : "+e
.getStackTrace());
36 public static void e(String TAG
, String message
){
38 appendLog(TAG
+" : "+message
);
41 public static void e(String TAG
, String message
, Throwable e
) {
42 Log
.e(TAG
, message
, e
);
43 appendLog(TAG
+" : "+ message
+" Exception : "+e
.getStackTrace());
46 public static void v(String TAG
, String message
){
48 appendLog(TAG
+" : "+message
);
51 public static void w(String TAG
, String message
) {
53 appendLog(TAG
+" : "+message
);
56 public static void wtf(String TAG
, String message
) {
58 appendLog(TAG
+" : "+message
);
61 public static void startLogging(String logPath
) {
63 folder
= new File(logPath
+File
.separator
+"log");
64 logFile
= new File(folder
+File
.separator
+"log.txt");
66 if (!folder
.exists()) {
69 if (logFile
.exists()) {
73 logFile
.createNewFile();
74 buf
= new BufferedWriter(new FileWriter(logFile
, true
));
77 }catch (IOException e
){
82 public static void stopLogging() {
83 SimpleDateFormat sdf
= new SimpleDateFormat("yyyyMMdd_HHmmss",Locale
.getDefault());
84 String currentDateandTime
= sdf
.format(new Date());
85 if (logFile
!= null
) {
86 logFile
.renameTo(new File(folder
+File
.separator
+"log_"+currentDateandTime
));
90 } catch (IOException e
) {
98 private static void appendPhoneInfo() {
99 appendLog("Model : " + android
.os
.Build
.MODEL
);
100 appendLog("Brand : " + android
.os
.Build
.BRAND
);
101 appendLog("Product : " + android
.os
.Build
.PRODUCT
);
102 appendLog("Device : " + android
.os
.Build
.DEVICE
);
103 appendLog("Version-Codename : " + android
.os
.Build
.VERSION
.CODENAME
);
104 appendLog("Version-Release : " + android
.os
.Build
.VERSION
.RELEASE
);
107 private static void appendLog(String text
) {
112 } catch (IOException e
) {