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
;
9 import java
.util
.Locale
;
11 import com
.owncloud
.android
.MainApp
;
13 import android
.util
.Log
;
20 private static boolean isEnabled
= false
;
21 private static File logFile
;
22 private static File folder
;
23 private static BufferedWriter buf
;
25 public static void i(String TAG
, String message
){
26 // Printing the message to LogCat console
27 int a
= Log
.i(TAG
, message
);
28 // Write the log message to the file
29 appendLog(TAG
+" : "+message
);
32 public static void d(String TAG
, String message
){
34 appendLog(TAG
+ " : " + message
);
36 public static void d(String TAG
, String message
, Exception e
) {
37 Log
.d(TAG
, message
, e
);
38 appendLog(TAG
+ " : " + message
+ " Exception : "+ e
.getStackTrace());
40 public static void e(String TAG
, String message
){
42 appendLog(TAG
+ " : " + message
);
45 public static void e(String TAG
, String message
, Throwable e
) {
46 Log
.e(TAG
, message
, e
);
47 appendLog(TAG
+" : " + message
+" Exception : " + e
.getStackTrace());
50 public static void v(String TAG
, String message
){
52 appendLog(TAG
+" : "+ message
);
55 public static void w(String TAG
, String message
) {
57 appendLog(TAG
+" : "+ message
);
60 public static void wtf(String TAG
, String message
) {
62 appendLog(TAG
+" : "+ message
);
65 public static void startLogging(String logPath
) {
66 folder
= new File(logPath
);
67 logFile
= new File(folder
+ File
.separator
+ "log.txt");
69 if (!folder
.exists()) {
72 if (logFile
.exists()) {
76 logFile
.createNewFile();
77 buf
= new BufferedWriter(new FileWriter(logFile
, true
));
80 }catch (IOException e
){
85 public static void stopLogging() {
86 SimpleDateFormat sdf
= new SimpleDateFormat("yyyyMMdd_HHmmss", Locale
.getDefault());
87 String currentDateandTime
= sdf
.format(new Date());
88 if (logFile
!= null
) {
89 logFile
.renameTo(new File(folder
+ File
.separator
+ MainApp
.getLogName() + currentDateandTime
+".log"));
94 } catch (IOException e
) {
102 private static void appendPhoneInfo() {
103 appendLog("Model : " + android
.os
.Build
.MODEL
);
104 appendLog("Brand : " + android
.os
.Build
.BRAND
);
105 appendLog("Product : " + android
.os
.Build
.PRODUCT
);
106 appendLog("Device : " + android
.os
.Build
.DEVICE
);
107 appendLog("Version-Codename : " + android
.os
.Build
.VERSION
.CODENAME
);
108 appendLog("Version-Release : " + android
.os
.Build
.VERSION
.RELEASE
);
111 private static void appendLog(String text
) {
116 } catch (IOException e
) {