1 package com
.owncloud
.android
.utils
;
3 import java
.io
.BufferedWriter
;
5 import java
.io
.FileWriter
;
6 import java
.io
.IOException
;
7 import java
.text
.SimpleDateFormat
;
8 import java
.util
.Calendar
;
10 import android
.os
.Environment
;
11 import android
.util
.Log
;
17 private static boolean isEnabled
= false
;
18 private static File logFile
;
19 private static File folder
;
20 private static BufferedWriter buf
;
22 public static void i(String TAG
, String message
){
23 // Printing the message to LogCat console
24 int a
= Log
.i(TAG
, message
);
25 // Write the log message to the file
26 appendLog(TAG
+" : "+message
);
29 public static void d(String TAG
, String message
){
31 appendLog(TAG
+ " : " + message
);
33 public static void d(String TAG
, String message
, Exception e
) {
34 Log
.d(TAG
, message
, e
);
35 appendLog(TAG
+ " : " + message
+ " Exception : "+ e
.getStackTrace());
37 public static void e(String TAG
, String message
){
39 appendLog(TAG
+ " : " + message
);
42 public static void e(String TAG
, String message
, Throwable e
) {
43 Log
.e(TAG
, message
, e
);
44 appendLog(TAG
+" : " + message
+" Exception : " + e
.getStackTrace());
47 public static void v(String TAG
, String message
){
49 appendLog(TAG
+" : "+ message
);
52 public static void w(String TAG
, String message
) {
54 appendLog(TAG
+" : "+ message
);
57 public static void wtf(String TAG
, String message
) {
59 appendLog(TAG
+" : "+ message
);
62 public static void startLogging(String logPath
) {
63 folder
= new File(logPath
);
64 logFile
= new File(folder
+ File
.separator
+ "log.txt");
66 boolean isFileCreated
= false
;
68 if (!folder
.exists()) {
71 Log
.d("LOG_OC", "Log file created");
75 logFile
.createNewFile();
76 buf
= new BufferedWriter(new FileWriter(logFile
, true
));
81 }catch (IOException e
){
86 public static void stopLogging() {
87 if (logFile
!= null
) {
90 buf
= new BufferedWriter(new FileWriter(logFile
, false
));
93 } catch (IOException e
) {
99 private static void appendPhoneInfo() {
100 appendLog("Model : " + android
.os
.Build
.MODEL
);
101 appendLog("Brand : " + android
.os
.Build
.BRAND
);
102 appendLog("Product : " + android
.os
.Build
.PRODUCT
);
103 appendLog("Device : " + android
.os
.Build
.DEVICE
);
104 appendLog("Version-Codename : " + android
.os
.Build
.VERSION
.CODENAME
);
105 appendLog("Version-Release : " + android
.os
.Build
.VERSION
.RELEASE
);
108 private static void appendLog(String text
) {
110 String logPath
= Environment
.getExternalStorageDirectory()+File
.separator
+"owncloud"+File
.separator
+"log";
111 startLogging(logPath
);
112 String timeStamp
= new SimpleDateFormat("HH:mm:ss").format(Calendar
.getInstance().getTime());
115 buf
= new BufferedWriter(new FileWriter(logFile
, true
));
116 buf
.write(timeStamp
+ " -> " +text
);
119 } catch (IOException e
) {