]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/Log.java
0607658bca7e476124adc8109ed791018a7833e4
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");
72 .wrn("aaa bbbbbb cccccccccccc ddddddddddd eeeeeeeeee fffffffffff gggggggggggggggggg hhhhhhhhhhhhhhhhhhhhhhhhhhhhh iiiii jjjj kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk lll mmm nn poooooooooooooooooooooooooooooooooooooooooooop");
73 Log
.wrn("Incorrect data type for ModuleEntryPoint");
74 } catch (Exception e
) {
80 Call writeToLogFile to save log item and log information to log file
82 @param strItem The log item
83 @param strLog The log information
86 public static void log(String strItem
, String strLog
) {
88 writeToLogFile(strItem
+ ":" + strLog
);
89 } catch (IOException e
) {
95 Call writeToLogFile to save log information to log file
97 @param strLog The log information
100 public static void log(String strLog
) {
102 writeToLogFile(strLog
);
103 } catch (IOException e
) {
109 Call writeToWrnFile to save wrn item and wrn information to wrn file
111 @param strItem The wrn item
112 @param strLog The wrn information
115 public static void wrn(String strItem
, String strWrn
) {
117 writeToWrnFile("Warning when " + strItem
+ "::" + strWrn
);
118 showWrnMessage(strWrn
);
119 } catch (IOException e
) {
125 Call writeToWrnFile to save wrn information to wrn file
127 @param strLog The wrn information
130 public static void wrn(String strWrn
) {
132 writeToWrnFile("Warning::" + strWrn
);
133 showWrnMessage("Warning::" + strWrn
);
134 } catch (IOException e
) {
140 Call writeToErrFile to save err item and err information to err file
142 @param strItem The err item
143 @param strLog The err information
146 public static void err(String strItem
, String strErr
) {
148 writeToErrFile("Error when " + strItem
+ "::" + strErr
);
149 } catch (IOException e
) {
155 Call writeToErrFile to save err information to err file
157 @param strLog The err information
160 public static void err(String strErr
) {
162 writeToErrFile("Error::" + strErr
);
163 } catch (IOException e
) {
169 Brings up a dialog to show err message
170 When the message's length > defined max length, wrap the text to the next line.
172 @param strErr The input data of err message
175 private static void showWrnMessage(String strErr
) {
176 String strReturn
= Tools
.wrapStringByWord(strErr
);
178 .showConfirmDialog(null, strReturn
, "Warning", JOptionPane
.DEFAULT_OPTION
, JOptionPane
.ERROR_MESSAGE
);
182 Open log file and write log information
184 @param strLog The log information
188 private static void writeToLogFile(String strLog
) throws IOException
{
190 if (fleLogFile
== null) {
191 fleLogFile
= new File(strLogFileName
);
192 fleLogFile
.createNewFile();
194 FileOutputStream fos
= new FileOutputStream(fleLogFile
, true);
195 fos
.write((Tools
.getCurrentDateTime() + DataType
.DOS_LINE_SEPARATOR
).getBytes());
196 fos
.write((strLog
+ DataType
.DOS_LINE_SEPARATOR
).getBytes());
199 } catch (FileNotFoundException e
) {
201 } catch (IOException e
) {
207 Open wrn file and write wrn information
209 @param strLog The log information
213 private static void writeToWrnFile(String strLog
) throws IOException
{
215 if (fleWrnFile
== null) {
216 fleWrnFile
= new File(strWrnFileName
);
217 fleWrnFile
.createNewFile();
219 FileOutputStream fos
= new FileOutputStream(fleWrnFile
, true);
220 fos
.write((Tools
.getCurrentDateTime() + DataType
.DOS_LINE_SEPARATOR
).getBytes());
221 fos
.write((strLog
+ DataType
.DOS_LINE_SEPARATOR
).getBytes());
224 } catch (FileNotFoundException e
) {
226 } catch (IOException e
) {
232 Open err file and write err information
234 @param strLog The log information
238 private static void writeToErrFile(String strLog
) throws IOException
{
240 if (fleErrFile
== null) {
241 fleErrFile
= new File(strErrFileName
);
242 fleErrFile
.createNewFile();
244 FileOutputStream fos
= new FileOutputStream(fleErrFile
, true);
245 fos
.write((Tools
.getCurrentDateTime() + DataType
.DOS_LINE_SEPARATOR
).getBytes());
246 fos
.write((strLog
+ DataType
.DOS_LINE_SEPARATOR
).getBytes());
249 } catch (FileNotFoundException e
) {
251 } catch (IOException e
) {