0de6aa78f011725c0d50ad5214c09986093660ad
3 The file is used to provides static interfaces to save log and error information
5 Copyright (c) 2006, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 package org
.tianocore
.frameworkwizard
.common
;
19 import java
.io
.FileNotFoundException
;
20 import java
.io
.FileOutputStream
;
21 import java
.io
.IOException
;
23 import javax
.swing
.JOptionPane
;
26 The class is used to provides static interfaces to save log and error information
34 private static File fleLogFile
= null;
39 private static File fleWrnFile
= null;
44 private static File fleErrFile
= null;
49 static String strLogFileName
= "Log.log";
54 static String strWrnFileName
= "Wrn.log";
59 static String strErrFileName
= "Err.log";
62 Main class, used for test
67 public static void main(String
[] args
) {
69 //Log.log("Test", "test");
70 //Log.err("Test1", "test1");
74 "aaa bbbbbb cccccccccccc ddddddddddd eeeeeeeeee fffffffffff gggggggggggggggggg hhhhhhhhhhhhhhhhhhhhhhhhhhhhh",
75 "iiiiii jjjj kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk lll mmm nn poooooooooooooooooooooooooooooooooooooooooooop");
76 } catch (Exception e
) {
82 Call writeToLogFile to save log item and log information to log file
84 @param strItem The log item
85 @param strLog The log information
88 public static void log(String strItem
, String strLog
) {
90 writeToLogFile(strItem
+ ":" + strLog
);
91 } catch (IOException e
) {
97 Call writeToLogFile to save log information to log file
99 @param strLog The log information
102 public static void log(String strLog
) {
104 writeToLogFile(strLog
);
105 } catch (IOException e
) {
111 Call writeToWrnFile to save wrn item and wrn information to wrn file
113 @param strItem The wrn item
114 @param strLog The wrn information
117 public static void wrn(String strItem
, String strWrn
) {
119 writeToWrnFile("Warning when " + strItem
+ "::" + strWrn
);
120 showWrnMessage(strWrn
);
121 } catch (IOException e
) {
127 Call writeToWrnFile to save wrn information to wrn file
129 @param strLog The wrn information
132 public static void wrn(String strWrn
) {
134 writeToWrnFile("Warning::" + strWrn
);
135 showWrnMessage("Warning::" + strWrn
);
136 } catch (IOException e
) {
142 Call writeToErrFile to save err item and err information to err file
144 @param strItem The err item
145 @param strLog The err information
148 public static void err(String strItem
, String strErr
) {
150 writeToErrFile("Error when " + strItem
+ "::" + strErr
);
151 } catch (IOException e
) {
157 Call writeToErrFile to save err information to err file
159 @param strLog The err information
162 public static void err(String strErr
) {
164 writeToErrFile("Error::" + strErr
);
165 } catch (IOException e
) {
171 Brings up a dialog to show err message
172 When the message's length > defined max length, wrap the text to the next line.
174 @param strErr The input data of err message
177 private static void showWrnMessage(String strErr
) {
178 String strReturn
= Tools
.wrapStringByWord(strErr
);
179 JOptionPane
.showConfirmDialog(null, strReturn
, "Warning", JOptionPane
.DEFAULT_OPTION
, JOptionPane
.ERROR_MESSAGE
);
183 Open log file and write log information
185 @param strLog The log information
189 private static void writeToLogFile(String strLog
) throws IOException
{
191 if (fleLogFile
== null) {
192 fleLogFile
= new File(strLogFileName
);
193 fleLogFile
.createNewFile();
195 FileOutputStream fos
= new FileOutputStream(fleLogFile
, true);
196 fos
.write((Tools
.getCurrentDateTime() + DataType
.DOS_LINE_SEPARATOR
).getBytes());
197 fos
.write((strLog
+ DataType
.DOS_LINE_SEPARATOR
).getBytes());
200 } catch (FileNotFoundException e
) {
202 } catch (IOException e
) {
208 Open wrn file and write wrn information
210 @param strLog The log information
214 private static void writeToWrnFile(String strLog
) throws IOException
{
216 if (fleWrnFile
== null) {
217 fleWrnFile
= new File(strWrnFileName
);
218 fleWrnFile
.createNewFile();
220 FileOutputStream fos
= new FileOutputStream(fleWrnFile
, true);
221 fos
.write((Tools
.getCurrentDateTime() + DataType
.DOS_LINE_SEPARATOR
).getBytes());
222 fos
.write((strLog
+ DataType
.DOS_LINE_SEPARATOR
).getBytes());
225 } catch (FileNotFoundException e
) {
227 } catch (IOException e
) {
233 Open err file and write err information
235 @param strLog The log information
239 private static void writeToErrFile(String strLog
) throws IOException
{
241 if (fleErrFile
== null) {
242 fleErrFile
= new File(strErrFileName
);
243 fleErrFile
.createNewFile();
245 FileOutputStream fos
= new FileOutputStream(fleErrFile
, true);
246 fos
.write((Tools
.getCurrentDateTime() + DataType
.DOS_LINE_SEPARATOR
).getBytes());
247 fos
.write((strLog
+ DataType
.DOS_LINE_SEPARATOR
).getBytes());
250 } catch (FileNotFoundException e
) {
252 } catch (IOException e
) {