+++ /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.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
-/**\r
- The class is used to provides static interfaces to save log and error information\r
- \r
- @since CreateMdkPkg 1.0\r
- \r
- **/\r
-public class Log {\r
-\r
- //\r
- //Log file\r
- //\r
- private static File fleLogFile = null;\r
-\r
- //\r
- //Err file\r
- //\r
- private static File fleErrFile = null;\r
-\r
- //\r
- //Log file name\r
- //\r
- static String strLogFileName = "Log.log";\r
-\r
- //\r
- //Err file name\r
- //\r
- static String strErrFileName = "Err.log";\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
- } catch (Exception e) {\r
- e.printStackTrace();\r
- }\r
- }\r
-\r
- /**\r
- This is the default constructor\r
- Do nothing\r
- \r
- **/\r
- public Log() {\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 (IOException 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 (IOException 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
- JOptionPane.showConfirmDialog(null, "Error when " + strItem + "::" + strErr, "Error",\r
- JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);\r
-\r
- } catch (IOException 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
- JOptionPane.showConfirmDialog(null, "Error::" + strErr, "Error", JOptionPane.DEFAULT_OPTION,\r
- JOptionPane.ERROR_MESSAGE);\r
- } catch (IOException e) {\r
- e.printStackTrace();\r
- }\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 IOException {\r
- try {\r
- if (fleLogFile == null) {\r
- fleLogFile = new File(strLogFileName);\r
- fleLogFile.createNewFile();\r
- }\r
- FileOutputStream fos = new FileOutputStream(fleLogFile, true);\r
- fos.write((Tools.getCurrentDateTime() + "\r\n").getBytes());\r
- fos.write((strLog + "\r\n").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
- 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 IOException {\r
- try {\r
- if (fleErrFile == null) {\r
- fleErrFile = new File(strErrFileName);\r
- fleErrFile.createNewFile();\r
- }\r
- FileOutputStream fos = new FileOutputStream(fleErrFile, true);\r
- fos.write((Tools.getCurrentDateTime() + "\r\n").getBytes());\r
- fos.write((strLog + "\r\n").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