]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/Log.java
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
;
25 import org
.tianocore
.frameworkwizard
.FrameworkWizardUI
;
28 The class is used to provides static interfaces to save log and error information
36 private static File fleLogFile
= null;
41 private static File fleWrnFile
= null;
46 private static File fleErrFile
= null;
51 static String strLogFileName
= "Log.log";
56 static String strWrnFileName
= "Wrn.log";
61 static String strErrFileName
= "Err.log";
64 Main class, used for test
69 public static void main(String
[] args
) {
71 //Log.log("Test", "test");
72 //Log.err("Test1", "test1");
74 .wrn("aaa bbbbbb cccccccccccc ddddddddddd eeeeeeeeee fffffffffff gggggggggggggggggg hhhhhhhhhhhhhhhhhhhhhhhhhhhhh iiiii jjjj kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk lll mmm nn poooooooooooooooooooooooooooooooooooooooooooop");
75 Log
.wrn("Incorrect data type for ModuleEntryPoint");
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
);
180 .showConfirmDialog(FrameworkWizardUI
.getInstance(), strReturn
, "Warning", JOptionPane
.DEFAULT_OPTION
, JOptionPane
.ERROR_MESSAGE
);
184 Open log file and write log information
186 @param strLog The log information
190 private static void writeToLogFile(String strLog
) throws IOException
{
192 if (fleLogFile
== null) {
193 fleLogFile
= new File(strLogFileName
);
194 fleLogFile
.createNewFile();
196 FileOutputStream fos
= new FileOutputStream(fleLogFile
, true);
197 fos
.write((Tools
.getCurrentDateTime() + DataType
.DOS_LINE_SEPARATOR
).getBytes());
198 fos
.write((strLog
+ DataType
.DOS_LINE_SEPARATOR
).getBytes());
201 } catch (FileNotFoundException e
) {
203 } catch (IOException e
) {
209 Open wrn file and write wrn information
211 @param strLog The log information
215 private static void writeToWrnFile(String strLog
) throws IOException
{
217 if (fleWrnFile
== null) {
218 fleWrnFile
= new File(strWrnFileName
);
219 fleWrnFile
.createNewFile();
221 FileOutputStream fos
= new FileOutputStream(fleWrnFile
, true);
222 fos
.write((Tools
.getCurrentDateTime() + DataType
.DOS_LINE_SEPARATOR
).getBytes());
223 fos
.write((strLog
+ DataType
.DOS_LINE_SEPARATOR
).getBytes());
226 } catch (FileNotFoundException e
) {
228 } catch (IOException e
) {
234 Open err file and write err information
236 @param strLog The log information
240 private static void writeToErrFile(String strLog
) throws IOException
{
242 if (fleErrFile
== null) {
243 fleErrFile
= new File(strErrFileName
);
244 fleErrFile
.createNewFile();
246 FileOutputStream fos
= new FileOutputStream(fleErrFile
, true);
247 fos
.write((Tools
.getCurrentDateTime() + DataType
.DOS_LINE_SEPARATOR
).getBytes());
248 fos
.write((strLog
+ DataType
.DOS_LINE_SEPARATOR
).getBytes());
251 } catch (FileNotFoundException e
) {
253 } catch (IOException e
) {