+++ /dev/null
-/** @file\r
- \r
- The file is used to provides static interfaces to save log and error information \r
- \r
- Copyright (c) 2006, Intel Corporation\r
- All rights reserved. This program and the accompanying materials\r
- are licensed and made available under the terms and conditions of the BSD License\r
- which accompanies this distribution. The full text of the license may be found at\r
- http://opensource.org/licenses/bsd-license.php\r
- \r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
- \r
- **/\r
-\r
-package org.tianocore.frameworkwizard.common;\r
-\r
-import java.io.File;\r
-import java.io.FileNotFoundException;\r
-import java.io.FileOutputStream;\r
-import java.io.IOException;\r
-\r
-import javax.swing.JOptionPane;\r
-\r
-import org.tianocore.frameworkwizard.FrameworkWizardUI;\r
-import org.tianocore.frameworkwizard.workspace.Workspace;\r
-\r
-/**\r
- The class is used to provides static interfaces to save log and error information\r
- \r
- **/\r
-public class Log {\r
- //\r
- //Log file directory path\r
- //\r
- private static String strLogDir = Workspace.getCurrentWorkspace() + DataType.FILE_SEPARATOR + "Tools"\r
- + DataType.FILE_SEPARATOR + "Logs";\r
-\r
- //\r
- //Log file\r
- //\r
- private static File fleLogFile = null;\r
-\r
- //\r
- //Wrn file\r
- //\r
- private static File fleWrnFile = null;\r
-\r
- //\r
- //Err file\r
- //\r
- private static File fleErrFile = null;\r
-\r
- //\r
- //Log file name\r
- //\r
- private static String strLogFileName = strLogDir + DataType.FILE_SEPARATOR + "frameworkwizard.log";\r
-\r
- //\r
- //Wrn file name\r
- //\r
- private static String strWrnFileName = strLogDir + DataType.FILE_SEPARATOR + "frameworkwizard.wrn";\r
-\r
- //\r
- //Err file name\r
- //\r
- private static String strErrFileName = strLogDir + DataType.FILE_SEPARATOR + "frameworkwizard.err";\r
-\r
- //\r
- //Flag for create log or not\r
- //\r
- private static boolean isSaveLog = false;\r
-\r
- /**\r
- Main class, used for test\r
- \r
- @param args\r
- \r
- **/\r
- public static void main(String[] args) {\r
- try {\r
- //Log.log("Test", "test");\r
- //Log.err("Test1", "test1");\r
- Log\r
- .wrn("aaa bbbbbb cccccccccccc ddddddddddd eeeeeeeeee fffffffffff gggggggggggggggggg hhhhhhhhhhhhhhhhhhhhhhhhhhhhh iiiii jjjj kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk lll mmm nn poooooooooooooooooooooooooooooooooooooooooooop");\r
- Log.wrn("Incorrect data type for ModuleEntryPoint");\r
- } catch (Exception e) {\r
- e.printStackTrace();\r
- }\r
- }\r
-\r
- /**\r
- Call writeToLogFile to save log item and log information to log file\r
- \r
- @param strItem The log item\r
- @param strLog The log information\r
- \r
- **/\r
- public static void log(String strItem, String strLog) {\r
- try {\r
- writeToLogFile(strItem + ":" + strLog);\r
- } catch (Exception e) {\r
- e.printStackTrace();\r
- }\r
- }\r
-\r
- /**\r
- Call writeToLogFile to save log information to log file\r
- \r
- @param strLog The log information\r
- \r
- **/\r
- public static void log(String strLog) {\r
- try {\r
- writeToLogFile(strLog);\r
- } catch (Exception e) {\r
- e.printStackTrace();\r
- }\r
- }\r
-\r
- /**\r
- Call writeToWrnFile to save wrn item and wrn information to wrn file\r
- \r
- @param strItem The wrn item\r
- @param strLog The wrn information\r
- \r
- **/\r
- public static void wrn(String strItem, String strWrn) {\r
- try {\r
- writeToWrnFile("Warning when " + strItem + "::" + strWrn);\r
- showWrnMessage(strWrn);\r
- } catch (Exception e) {\r
- e.printStackTrace();\r
- }\r
- }\r
-\r
- /**\r
- Call writeToWrnFile to save wrn information to wrn file\r
- \r
- @param strLog The wrn information\r
- \r
- **/\r
- public static void wrn(String strWrn) {\r
- try {\r
- writeToWrnFile("Warning::" + strWrn);\r
- showWrnMessage("Warning::" + strWrn);\r
- } catch (Exception e) {\r
- e.printStackTrace();\r
- }\r
- }\r
-\r
- /**\r
- Call writeToErrFile to save err item and err information to err file\r
- \r
- @param strItem The err item\r
- @param strLog The err information\r
- \r
- **/\r
- public static void err(String strItem, String strErr) {\r
- try {\r
- writeToErrFile("Error when " + strItem + "::" + strErr);\r
- } catch (Exception e) {\r
- e.printStackTrace();\r
- }\r
- }\r
-\r
- /**\r
- Call writeToErrFile to save err information to err file\r
- \r
- @param strLog The err information\r
- \r
- **/\r
- public static void err(String strErr) {\r
- try {\r
- writeToErrFile("Error::" + strErr);\r
- } catch (Exception e) {\r
- e.printStackTrace();\r
- }\r
- }\r
-\r
- /**\r
- Brings up a dialog to show err message\r
- When the message's length > defined max length, wrap the text to the next line.\r
- \r
- @param strErr The input data of err message\r
- \r
- **/\r
- private static void showWrnMessage(String strErr) {\r
- String strReturn = Tools.wrapStringByWord(strErr);\r
- JOptionPane.showConfirmDialog(FrameworkWizardUI.getInstance(), strReturn, "Warning",\r
- JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);\r
- }\r
-\r
- /**\r
- Open log file and write log information\r
- \r
- @param strLog The log information\r
- @throws IOException\r
- \r
- **/\r
- private static void writeToLogFile(String strLog) throws Exception {\r
- if (isSaveLog) {\r
- try {\r
- createLogDir();\r
- if (fleLogFile == null) {\r
- fleLogFile = new File(strLogFileName);\r
- fleLogFile.delete();\r
- fleLogFile.createNewFile();\r
- }\r
- FileOutputStream fos = new FileOutputStream(fleLogFile, true);\r
- fos.write((Tools.getCurrentDateTime() + DataType.DOS_LINE_SEPARATOR).getBytes());\r
- fos.write((strLog + DataType.DOS_LINE_SEPARATOR).getBytes());\r
- fos.flush();\r
- fos.close();\r
- } catch (FileNotFoundException e) {\r
- e.printStackTrace();\r
- } catch (IOException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
- }\r
-\r
- /**\r
- Open wrn file and write wrn information\r
- \r
- @param strLog The log information\r
- * @throws Exception \r
- \r
- **/\r
- private static void writeToWrnFile(String strLog) throws Exception {\r
- if (isSaveLog) {\r
- try {\r
- createLogDir();\r
- if (fleWrnFile == null) {\r
- fleWrnFile = new File(strWrnFileName);\r
- fleWrnFile.delete();\r
- fleWrnFile.createNewFile();\r
- }\r
- FileOutputStream fos = new FileOutputStream(fleWrnFile, true);\r
- fos.write((Tools.getCurrentDateTime() + DataType.DOS_LINE_SEPARATOR).getBytes());\r
- fos.write((strLog + DataType.DOS_LINE_SEPARATOR).getBytes());\r
- fos.flush();\r
- fos.close();\r
- } catch (FileNotFoundException e) {\r
- e.printStackTrace();\r
- } catch (IOException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
- }\r
-\r
- /**\r
- Open err file and write err information\r
- \r
- @param strLog The log information\r
- @throws IOException\r
- \r
- **/\r
- private static void writeToErrFile(String strLog) throws Exception {\r
- if (isSaveLog) {\r
- try {\r
- createLogDir();\r
- if (fleErrFile == null) {\r
- fleErrFile = new File(strErrFileName);\r
- fleErrFile.delete();\r
- fleErrFile.createNewFile();\r
- }\r
- FileOutputStream fos = new FileOutputStream(fleErrFile, true);\r
- fos.write((Tools.getCurrentDateTime() + DataType.DOS_LINE_SEPARATOR).getBytes());\r
- fos.write((strLog + DataType.DOS_LINE_SEPARATOR).getBytes());\r
- fos.flush();\r
- fos.close();\r
- } catch (FileNotFoundException e) {\r
- e.printStackTrace();\r
- } catch (IOException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
- }\r
-\r
- /**\r
- Check if directory for Logs exists or not\r
- Create the directory if it doesn't exist \r
- * @throws Exception \r
- \r
- **/\r
- private static void createLogDir() throws Exception {\r
- File f = new File(strLogDir);\r
- if (!f.exists()) {\r
- FileOperation.newFolder(strLogDir);\r
- }\r
- }\r
-\r
- public static boolean isSaveLog() {\r
- return isSaveLog;\r
- }\r
-\r
- public static void setSaveLog(boolean isSaveLog) {\r
- Log.isSaveLog = isSaveLog;\r
- }\r
-}\r