[SRADA-244]Implementation LogExport Class
authorggh1933.go <ggh1933.go@samsung.com>
Tue, 22 Mar 2016 02:43:44 +0000 (11:43 +0900)
committerdongkyu6 lee <dongkyu6.lee@samsung.com>
Thu, 24 Mar 2016 08:26:30 +0000 (17:26 +0900)
 - Make LogExportClass, Add exportDaemonLog to custompath method in DAcomm.
 - this class function is exporting(or copy to customPath ) DA Console Log, daemon Log, data Log, control Log
 - dataLog, controlLog are enabled by setting 'Debug Print | true' in DA Setting config file
 - there is 'setting file' in "SDK_PATH/tools/dynamic-analyzer/config/setting"
 - When add console message, DA ConsoleLog updated too. so, need to find latest DA Console logfile.
 - add Logs compress function, Button, FileExplorer..
 - Modified UI_Action, DADialog..etc for add LogExport Listener.
 - 1. popup ErrorMessage -> 2. click "exportLogs" button -> 3. popup "exportPath" Dialog
   4. select path and click "Ok" -> 5. export Logs to "DALogs_(current date&time).zip" in path.
 - Modified DebugLog for always enable Data and Control Log Exported

Change-Id: Ice70c8872c21b38c7272800eba1399d85e52577e

org.tizen.dynamicanalyzer.appearance/src/org/tizen/dynamicanalyzer/widgets/da/base/DADialog.java
org.tizen.dynamicanalyzer.workbench/src/org/tizen/dynamicanalyzer/workbench/Application.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/DALogExport.java [new file with mode: 0755]
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/communicator/DACommunicator.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/handlers/UIAction.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/protocol/DebugLog.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/common/explorer/FileExplorerDialog.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/hierarchy/tree/HierarchyTreeView.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/hierarchy/tree/tool/HierarchyTreeExporter.java

index 96de49c..980e186 100644 (file)
@@ -51,6 +51,7 @@ public class DADialog {
        private Shell parent = null;
        private Shell shell = null;
        private DACustomButton okButton = null;
+       private DACustomButton exportButton = null;
        private String message = null;
        private boolean returnType = false;
        private String titleText = WidgetLabels.DA_WARNING;
@@ -58,18 +59,16 @@ public class DADialog {
        private final int defaultHeifght = 153;
        private int width = 0;
        private int height = 0;
-
        private Image iconImage = ImageResources.DYNANMIC_ANALYZER_ICON;
 
        private DACustomButtonClickEventListener okButtonListener = new DACustomButtonClickEventListener() {
-
                @Override
                public void handleClickEvent(DACustomButton button) {
                        returnType = true;
                        shell.dispose();
                }
        };
-
+       
        public DADialog(Shell parent, int style) {
                this.width = this.defaultWidth;
                this.height = this.defaultHeifght;
@@ -81,8 +80,8 @@ public class DADialog {
                this.width = width;
                this.height = height;
        }
-
-       public boolean open() {
+       
+       public boolean setDialog(boolean isExport) {
                shell = new Shell(parent, SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM);
                shell.setSize(width, height);
                shell.setLayout(new FormLayout());
@@ -166,7 +165,24 @@ public class DADialog {
                okData.width = DesignConstants.DA_BUTTON_WIDTH;
                okData.height = DesignConstants.DA_BUTTON_HEIGHT;
                okButton.setLayoutData(okData);
-
+               
+               // Export button
+               if(isExport){
+                       exportButton = new DAButton(buttonComp, SWT.NONE);
+                       exportButton.setText("ExportLogs");
+                       exportButton.setButtonFont(FontResources.DIALOG_BUTTON_FONT);
+                       
+                       FormData exportData = new FormData();
+                       exportData.top = new FormAttachment(0, 11);
+                       exportData.right = new FormAttachment(okButton,-220, SWT.LEFT);
+                       exportData.width = DesignConstants.DA_BUTTON_WIDTH;
+                       exportData.height = DesignConstants.DA_BUTTON_HEIGHT;
+                       exportButton.setLayoutData(exportData);
+               }
+               return returnType;
+       }
+       
+       public void open(){
                shell.open();
 
                Display display = Display.getCurrent();
@@ -178,9 +194,8 @@ public class DADialog {
                }
 
                shell.dispose();
-               return returnType;
        }
-
+       
        public void setMessage(String msg) {
                message = msg;
        }
@@ -192,4 +207,8 @@ public class DADialog {
        public void setTitleText(String title) {
                titleText = title;
        }
+       
+       public DACustomButton getExportButton(){
+               return exportButton;
+       }
 }
index 558b902..aa606ee 100755 (executable)
@@ -84,6 +84,7 @@ public class Application implements IApplication {
                        dialog.setTitleText(WorkbenchLabels.TIZEN_SDK_PATH_ERROR_TITLE);
                        dialog.setMessage(WorkbenchLabels.TIZEN_SDK_PATH_ERROR);
                        dialog.setIcon(ImageResources.DIALOG_WARNING_ICON);
+                       dialog.setDialog(false);
                        dialog.open();
                        return IApplication.EXIT_OK;
                }
diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/DALogExport.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/DALogExport.java
new file mode 100755 (executable)
index 0000000..d70421b
--- /dev/null
@@ -0,0 +1,289 @@
+package org.tizen.dynamicanalyzer.common;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+import org.tizen.dynamicanalyzer.common.path.PathManager;
+import org.tizen.dynamicanalyzer.communicator.DACommunicator;
+import org.tizen.dynamicanalyzer.ui.common.explorer.FileExplorerDialog;
+import org.tizen.dynamicanalyzer.util.CommonUtil;
+import org.tizen.dynamicanalyzer.util.Logger;
+import org.tizen.dynamicanalyzer.util.WorkbenchUtil;
+
+public class DALogExport {
+
+       private String LogexportPath;
+       private String LogZipPath;
+       private String ExportLogName;
+       
+       public DALogExport() {
+
+               Boolean result = false;
+
+               result = exportPathDialog();
+               if (result != true) {
+                       Logger.info("selected export path is wrong");
+               }
+               result = exportDALog();
+               if (result != true) {
+                       Logger.info("export DAConsoleLog failed");
+               }
+               result = exportDaemonLog();
+               if (result != true) {
+                       Logger.info("export DaemonLog failed");
+               }
+               result = exportDataLog();
+               if (result != true) {
+                       Logger.info("export DataLog failed");
+               }
+               result = exportControlLog();
+               if (result != true) {
+                       Logger.info("export ControlLog failed");
+               }
+               result = compressLogs();
+               if (result != true) {
+                       Logger.info("compress Logs failed");
+               }
+               result = removeTemp();
+               if (result != true) {
+               Logger.info("remove temp failed");
+               }
+       }
+       
+       /// User Select Directory to export Logs
+       public Boolean exportPathDialog(){              
+               FileExplorerDialog dialog = new FileExplorerDialog(WorkbenchUtil.getWorkbenchWindow().getShell());
+               dialog.setTitle("Select export path");
+               dialog.getExplorer().setRoot(CommonUtil.getHomeDirectory());
+               Object result = dialog.open();
+               LogexportPath = result.toString();
+               
+               if(LogexportPath==null){
+                       return false;
+               }
+               
+               int cutStart = LogexportPath.indexOf("[");
+               int cutEnd = LogexportPath.indexOf("]");
+               String tmpPath = LogexportPath.substring(cutStart+1, cutEnd);
+               
+               SimpleDateFormat format = new SimpleDateFormat(
+                               "yyyy_MM_dd_HH-mm-ss", Locale.KOREA); //$NON-NLS-1$
+               Date date = new Date();
+               String logPostFix = format.format(date);
+               ExportLogName = "DALogs_"+ logPostFix;
+               LogZipPath = tmpPath;
+               LogexportPath = tmpPath+"/"+ExportLogName;
+               
+               return true;
+       }
+       
+       // / set LogExportPath
+       public void setLogExportPath(String path) {
+               LogexportPath = path;
+       }
+
+       // / get LogExportPath
+       public String getLogExportPath(String path) {
+               return LogexportPath;
+       }
+
+       // / Export DA Log
+       public Boolean exportDALog() {
+               File src = getLastDALog(PathManager.DA_LOG_PATH);
+               File dirCheck = new File(LogexportPath);
+               File dest = new File(LogexportPath + "/" + "da_console.log");
+               
+               if(!checkDirectory(dirCheck)){
+                       return false;
+               }
+               
+               if(!copyLogFile(src, dest)){
+                       return false;
+               }
+               
+               return true;
+       }
+
+       // / Export Daemon Log
+       public Boolean exportDaemonLog() {
+               DACommunicator.exportCustomPathDaemonLog(LogexportPath);
+               return true;
+       }
+
+       // / Export DATA Log
+       public Boolean exportDataLog() {
+               File src = new File(PathManager.DA_DEBUG_DATA_CHANNEL_LOG_FILE);
+               File dest = new File(LogexportPath + "/" + "da_data.log");
+
+               if(!copyLogFile(src, dest)){
+                       return false;
+               }
+
+               return true;
+       }
+
+       // / Export Control Log
+       public Boolean exportControlLog() {
+               File src = new File(PathManager.DA_DEBUG_CONTROL_CHANNEL_LOG_FILE);
+               File dest = new File(LogexportPath + "/" + "da_control.log");
+
+               if(!copyLogFile(src, dest)){
+                       return false;
+               }
+
+               return true;
+       }
+
+       private Boolean copyLogFile(File source, File dest){
+
+               InputStream input = null;
+               OutputStream output = null;
+
+               try {
+                       input = new FileInputStream(source);
+                       output = new FileOutputStream(dest);
+
+                       byte[] buf = new byte[1024];
+                       int bytesRead;
+
+                       while ((bytesRead = input.read(buf)) > 0) {
+                               output.write(buf, 0, bytesRead);
+                       }
+
+               } 
+               catch(IOException e){
+                       e.printStackTrace();
+                       return false;
+               }
+               finally {
+                       try {
+                               if (input != null) {
+                                       input.close();
+                               }
+                               if (output != null) {
+                                       output.close();
+                               }
+                       } catch (IOException e) {
+                               // TODO Auto-generated catch block
+                               e.printStackTrace();
+                               return false;
+                       }
+               }               
+               return true;
+       }
+
+       public File getLastDALog(String dir) {
+               File fl = new File(dir);
+               File[] files = fl.listFiles(new FileFilter() {
+                       public boolean accept(File file) {
+                               return file.isFile();
+                       }
+               });
+               long lastMod = Long.MIN_VALUE;
+               File lastModFile = null;
+               for (File file : files) {
+                       if (file.toString().contains("da_log_")) {
+                               if (file.lastModified() > lastMod) {
+                                       lastModFile = file;
+                                       lastMod = file.lastModified();
+                               }
+                       }
+               }
+               return lastModFile;
+       }
+
+       /// CompressLogs
+       public Boolean compressLogs(){
+               ZipOutputStream zip = null;
+               FileOutputStream fileWriter = null;
+               String srcFolder = LogexportPath;
+               String destZipFile = LogZipPath + "/" + ExportLogName + ".zip";
+               
+               try {
+                       fileWriter = new FileOutputStream(destZipFile);
+                       zip = new ZipOutputStream(fileWriter);
+                       addFolderToZip("", srcFolder, zip);
+               } catch (Exception e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+                       return false;
+               }
+               
+               if(zip!=null){
+                       try {
+                               zip.flush();
+                               zip.close();
+                       } catch (IOException e) {
+                               // TODO Auto-generated catch block
+                               e.printStackTrace();
+                       }
+               }
+                               
+               return true;
+       }
+
+       /// Make zip from file.
+       private void addFileToZip(String path, String srcFile,ZipOutputStream zip){
+               File folder = new File(srcFile);
+
+               if (folder.isDirectory()) {
+                       addFolderToZip(path, srcFile, zip);
+               } else {                                
+                               byte[] buf = new byte[1024];
+                               int len;
+                               FileInputStream in;                             
+                               try {
+                                       in = new FileInputStream(srcFile);
+                                       zip.putNextEntry(new ZipEntry(path + "/" + folder.getName()));
+                                       while ((len = in.read(buf)) > 0) {
+                                               zip.write(buf, 0, len);
+                                       }                                       
+                               } catch (IOException e) {
+                                       // TODO Auto-generated catch block
+                                       e.printStackTrace();
+                               }
+               }
+               
+       }
+
+       /// Compress Files in folder
+       private void addFolderToZip(String path, String srcFolder,ZipOutputStream zip){
+               File folder = new File(srcFolder);
+               for (String fileName : folder.list()) {
+                               addFileToZip(folder.getName(), srcFolder + "/" + fileName, zip);
+               }
+       }
+       
+       private boolean checkDirectory(File file){
+               if (!file.exists()) {
+                       if(!file.mkdirs()){
+                               return false;
+                       }
+               } else {
+                       File[] destroy = file.listFiles();
+                       for (File des : destroy) {
+                               if(!des.delete()){
+                                       return false;
+                               }
+                       }
+               }
+               return true;
+       }
+       
+       private boolean removeTemp(){
+               File file = new File(LogexportPath);
+               checkDirectory(file);
+               file.delete();
+               return true;
+       }
+}
index a9d5fd5..41b66be 100755 (executable)
@@ -501,4 +501,44 @@ public class DACommunicator {
                        return new DAResult(ErrorCode.ERR_NO_DEVICE);
                }
        }
+       
+       public static void exportCustomPathDaemonLog(String path) {
+               DeviceInfo device = Global.getCurrentDeviceInfo();
+               if (device == null) {
+                       return;
+               }
+
+               final String from = PathConstants.DA_DAEMON_LOG_PATH;
+               String command = AnalyzerShellCommands.CMD_GET_FILE_SIZE + CommonConstants.SPACE + from;
+
+               final List<String> cmdResultMultiLines = new ArrayList<String>();
+               CommunicatorUtils.execShellCommand(device.getIDevice(), command, new MultiLineReceiver() {
+                       @Override
+                       public void processNewLines(String[] lines) {
+                               for (int i = 0; i < lines.length; i++) {
+                                       cmdResultMultiLines.add(lines[i]);
+                               }
+                       }
+               });
+
+               long filesize = -1;
+               if (cmdResultMultiLines.size() > 0) {
+                       filesize = Long.parseLong(cmdResultMultiLines.get(0));
+               }
+
+               if (filesize > 0 && filesize < DALimit.MAX_DAEMON_LOG_SIZE) {
+                       final String to = path + File.separator + DAEMONLOG_PREFIX
+                                       + PathManager.getLogPostFix();//$NON-NLS-1$ 
+                       SyncResult res = CommunicatorUtils.pull(device.getIDevice(), from, to);
+                       if (null != res && res.isOk()) {
+                               Logger.debug("daemon log copying success!!");//$NON-NLS-1$ 
+                       } else {
+                               Logger.debug("Failed to get " + from); //$NON-NLS-1$ 
+                       }
+
+                       AnalyzerUtil.checkLogs(PathManager.DA_LOG_PATH, DAEMONLOG_PREFIX, DAEMONLOG_COUNT);
+               } else {
+                       Logger.debug("daemon log file is too large or does not exist");
+               }
+       }
 }
index e7d42b2..ccbfa7c 100644 (file)
@@ -35,6 +35,7 @@ import java.util.Set;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;
+import org.tizen.dynamicanalyzer.common.DALogExport;
 import org.tizen.dynamicanalyzer.common.DAResult;
 import org.tizen.dynamicanalyzer.constant.CommonConstants;
 import org.tizen.dynamicanalyzer.nl.SummaryLabels;
@@ -64,6 +65,8 @@ import org.tizen.dynamicanalyzer.ui.userinterface.UIPage;
 import org.tizen.dynamicanalyzer.util.Logger;
 import org.tizen.dynamicanalyzer.util.WorkbenchUtil;
 import org.tizen.dynamicanalyzer.utils.AnalyzerUtil;
+import org.tizen.dynamicanalyzer.widgets.button.DACustomButton;
+import org.tizen.dynamicanalyzer.widgets.button.DACustomButtonClickEventListener;
 import org.tizen.dynamicanalyzer.widgets.da.base.DADialog;
 import org.tizen.dynamicanalyzer.widgets.da.view.DATabComposite;
 
@@ -130,6 +133,8 @@ public class UIAction {
                                DADialog dialog = new DADialog(shell, SWT.NONE, width, height);
                                dialog.setIcon(ImageResources.DIALOG_WARNING_ICON);
                                dialog.setMessage(message);
+                               dialog.setDialog(true);
+                               dialog.getExportButton().addClickListener(exportListener);
                                dialog.open();
                        }
                });
@@ -146,7 +151,9 @@ public class UIAction {
                                Shell shell = WorkbenchUtil.getWorkbenchWindow().getShell();
                                DADialog dialog = new DADialog(shell, SWT.NONE);
                                dialog.setIcon(ImageResources.DIALOG_WARNING_ICON);
-                               dialog.setMessage(message);
+                               dialog.setMessage(message);                             
+                               dialog.setDialog(true);
+                               dialog.getExportButton().addClickListener(exportListener);
                                dialog.open();
                        }
                });
@@ -164,6 +171,8 @@ public class UIAction {
                                DADialog dialog = new DADialog(shell, SWT.NONE);
                                dialog.setIcon(ImageResources.DIALOG_WARNING_ICON);
                                dialog.setMessage(message);
+                               dialog.setDialog(true);
+                               dialog.getExportButton().addClickListener(exportListener);
                                dialog.open();
                        }
                });
@@ -285,4 +294,11 @@ public class UIAction {
                        }
                });
        }
+       
+       private static DACustomButtonClickEventListener exportListener = new DACustomButtonClickEventListener() {
+               @Override
+               public void handleClickEvent(DACustomButton button) {
+                       DALogExport export = new DALogExport();
+               }
+       };
 }
index cddb673..6155fac 100644 (file)
@@ -44,8 +44,12 @@ public class DebugLog {
        private static PrintWriter dataChannelWriter = null;
 
        public static void enableDebugPrint(boolean enabled) {
+               /*
                PRINT_CONTROL_LOG_TO_FILE = enabled;
                PRINT_DATA_LOG_TO_FILE = enabled;
+               */
+               PRINT_CONTROL_LOG_TO_FILE = true;
+               PRINT_DATA_LOG_TO_FILE = true;
        }
 
        public static boolean isEnabled() {
index 7bdcf6f..46895e7 100644 (file)
@@ -179,4 +179,8 @@ public class FileExplorerDialog extends DAMessageBox {
        public void setFilter(String filter) {
                explorer.setFilterString(filter);
        }
+       
+       public void setTitle(String title) {
+               shell.setText(title);
+       }
 }
index d916539..2a32d10 100644 (file)
@@ -134,6 +134,7 @@ public class HierarchyTreeView extends DAViewComposite {
                                        DADialog dialog = new DADialog(shell, SWT.NONE);
                                        dialog.setIcon(ImageResources.DIALOG_ERROR_ICON);
                                        dialog.setMessage(UIHierarchyPageLabels.UIHIERARCHY_DIALOG_ERROR_GET_HIERARCHY);
+                                       dialog.setDialog(false);
                                        dialog.open();
                                }
                        }
index f7904a1..3f94f24 100644 (file)
@@ -109,6 +109,7 @@ public class HierarchyTreeExporter {
                dialog.setTitleText(UIHierarchyPageLabels.UIHIERARCHY_EXPORT_DIALOG_TITLE);
                dialog.setMessage(UIHierarchyPageLabels.UIHIERARCHY_EXPORT_DIALOG_ERROR_MESSAGE);
                dialog.setIcon(ImageResources.DIALOG_ERROR_ICON);
+               dialog.setDialog(false);
                dialog.open();
        }