d958ffd653cb9a90470b328962e1dcca6518843b
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 java
.util
.Locale
;
12 import android
.util
.Log
;
14 import com
.owncloud
.android
.MainApp
;
21 private static boolean isEnabled
= false
;
22 private static File logFile
;
23 private static File folder
;
24 private static BufferedWriter buf
;
26 public static void i(String TAG
, String message
){
27 // Printing the message to LogCat console
28 int a
= Log
.i(TAG
, message
);
29 // Write the log message to the file
30 appendLog(TAG
+" : "+message
);
33 public static void d(String TAG
, String message
){
35 appendLog(TAG
+ " : " + message
);
37 public static void d(String TAG
, String message
, Exception e
) {
38 Log
.d(TAG
, message
, e
);
39 appendLog(TAG
+ " : " + message
+ " Exception : "+ e
.getStackTrace());
41 public static void e(String TAG
, String message
){
43 appendLog(TAG
+ " : " + message
);
46 public static void e(String TAG
, String message
, Throwable e
) {
47 Log
.e(TAG
, message
, e
);
48 appendLog(TAG
+" : " + message
+" Exception : " + e
.getStackTrace());
51 public static void v(String TAG
, String message
){
53 appendLog(TAG
+" : "+ message
);
56 public static void w(String TAG
, String message
) {
58 appendLog(TAG
+" : "+ message
);
61 public static void wtf(String TAG
, String message
) {
63 appendLog(TAG
+" : "+ message
);
66 public static void startLogging(String logPath
) {
67 folder
= new File(logPath
);
68 logFile
= new File(folder
+ File
.separator
+ "log.txt");
70 boolean isFileCreated
= false
;
72 if (!folder
.exists()) {
75 Log
.d("LOG_OC", "Log file created");
77 // if (logFile.exists()) {
81 logFile
.createNewFile();
82 buf
= new BufferedWriter(new FileWriter(logFile
, true
));
87 }catch (IOException e
){
92 public static void stopLogging() {
93 SimpleDateFormat sdf
= new SimpleDateFormat("yyyyMMdd_HHmmss", Locale
.getDefault());
94 // String currentDateandTime = sdf.format(new Date());
95 if (logFile
!= null
) {
96 // logFile.renameTo(new File(folder + File.separator + MainApp.getLogName() + currentDateandTime+".log"));
101 buf
= new BufferedWriter(new FileWriter(logFile
, false
));
104 } catch (IOException e
) {
112 private static void appendPhoneInfo() {
113 appendLog("Model : " + android
.os
.Build
.MODEL
);
114 appendLog("Brand : " + android
.os
.Build
.BRAND
);
115 appendLog("Product : " + android
.os
.Build
.PRODUCT
);
116 appendLog("Device : " + android
.os
.Build
.DEVICE
);
117 appendLog("Version-Codename : " + android
.os
.Build
.VERSION
.CODENAME
);
118 appendLog("Version-Release : " + android
.os
.Build
.VERSION
.RELEASE
);
121 private static void appendLog(String text
) {
123 String timeStamp
= new SimpleDateFormat("HH:mm:ss").format(Calendar
.getInstance().getTime());
125 buf
= new BufferedWriter(new FileWriter(logFile
, true
));
126 buf
.write(timeStamp
+ " -> " +text
);
129 } catch (IOException e
) {