]>
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
;
26 import org
.tianocore
.frameworkwizard
.workspace
.Workspace
;
29 The class is used to provides static interfaces to save log and error information
34 //Log file directory path
36 private static String strLogDir
= Workspace
.getCurrentWorkspace() + DataType
.FILE_SEPARATOR
+ "Tools"
37 + DataType
.FILE_SEPARATOR
+ "Logs";
42 private static File fleLogFile
= null;
47 private static File fleWrnFile
= null;
52 private static File fleErrFile
= null;
57 private static String strLogFileName
= strLogDir
+ DataType
.FILE_SEPARATOR
+ "frameworkwizard.log";
62 private static String strWrnFileName
= strLogDir
+ DataType
.FILE_SEPARATOR
+ "frameworkwizard.wrn";
67 private static String strErrFileName
= strLogDir
+ DataType
.FILE_SEPARATOR
+ "frameworkwizard.err";
70 //Flag for create log or not
72 private static boolean isSaveLog
= false;
75 Main class, used for test
80 public static void main(String
[] args
) {
82 //Log.log("Test", "test");
83 //Log.err("Test1", "test1");
85 .wrn("aaa bbbbbb cccccccccccc ddddddddddd eeeeeeeeee fffffffffff gggggggggggggggggg hhhhhhhhhhhhhhhhhhhhhhhhhhhhh iiiii jjjj kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk lll mmm nn poooooooooooooooooooooooooooooooooooooooooooop");
86 Log
.wrn("Incorrect data type for ModuleEntryPoint");
87 } catch (Exception e
) {
93 Call writeToLogFile to save log item and log information to log file
95 @param strItem The log item
96 @param strLog The log information
99 public static void log(String strItem
, String strLog
) {
101 writeToLogFile(strItem
+ ":" + strLog
);
102 } catch (Exception e
) {
108 Call writeToLogFile to save log information to log file
110 @param strLog The log information
113 public static void log(String strLog
) {
115 writeToLogFile(strLog
);
116 } catch (Exception e
) {
122 Call writeToWrnFile to save wrn item and wrn information to wrn file
124 @param strItem The wrn item
125 @param strLog The wrn information
128 public static void wrn(String strItem
, String strWrn
) {
130 writeToWrnFile("Warning when " + strItem
+ "::" + strWrn
);
131 showWrnMessage(strWrn
);
132 } catch (Exception e
) {
138 Call writeToWrnFile to save wrn information to wrn file
140 @param strLog The wrn information
143 public static void wrn(String strWrn
) {
145 writeToWrnFile("Warning::" + strWrn
);
146 showWrnMessage("Warning::" + strWrn
);
147 } catch (Exception e
) {
153 Call writeToErrFile to save err item and err information to err file
155 @param strItem The err item
156 @param strLog The err information
159 public static void err(String strItem
, String strErr
) {
161 writeToErrFile("Error when " + strItem
+ "::" + strErr
);
162 } catch (Exception e
) {
168 Call writeToErrFile to save err information to err file
170 @param strLog The err information
173 public static void err(String strErr
) {
175 writeToErrFile("Error::" + strErr
);
176 } catch (Exception e
) {
182 Brings up a dialog to show err message
183 When the message's length > defined max length, wrap the text to the next line.
185 @param strErr The input data of err message
188 private static void showWrnMessage(String strErr
) {
189 String strReturn
= Tools
.wrapStringByWord(strErr
);
190 JOptionPane
.showConfirmDialog(FrameworkWizardUI
.getInstance(), strReturn
, "Warning",
191 JOptionPane
.DEFAULT_OPTION
, JOptionPane
.ERROR_MESSAGE
);
195 Open log file and write log information
197 @param strLog The log information
201 private static void writeToLogFile(String strLog
) throws Exception
{
205 if (fleLogFile
== null) {
206 fleLogFile
= new File(strLogFileName
);
208 fleLogFile
.createNewFile();
210 FileOutputStream fos
= new FileOutputStream(fleLogFile
, true);
211 fos
.write((Tools
.getCurrentDateTime() + DataType
.DOS_LINE_SEPARATOR
).getBytes());
212 fos
.write((strLog
+ DataType
.DOS_LINE_SEPARATOR
).getBytes());
215 } catch (FileNotFoundException e
) {
217 } catch (IOException e
) {
224 Open wrn file and write wrn information
226 @param strLog The log information
230 private static void writeToWrnFile(String strLog
) throws Exception
{
234 if (fleWrnFile
== null) {
235 fleWrnFile
= new File(strWrnFileName
);
237 fleWrnFile
.createNewFile();
239 FileOutputStream fos
= new FileOutputStream(fleWrnFile
, true);
240 fos
.write((Tools
.getCurrentDateTime() + DataType
.DOS_LINE_SEPARATOR
).getBytes());
241 fos
.write((strLog
+ DataType
.DOS_LINE_SEPARATOR
).getBytes());
244 } catch (FileNotFoundException e
) {
246 } catch (IOException e
) {
253 Open err file and write err information
255 @param strLog The log information
259 private static void writeToErrFile(String strLog
) throws Exception
{
263 if (fleErrFile
== null) {
264 fleErrFile
= new File(strErrFileName
);
266 fleErrFile
.createNewFile();
268 FileOutputStream fos
= new FileOutputStream(fleErrFile
, true);
269 fos
.write((Tools
.getCurrentDateTime() + DataType
.DOS_LINE_SEPARATOR
).getBytes());
270 fos
.write((strLog
+ DataType
.DOS_LINE_SEPARATOR
).getBytes());
273 } catch (FileNotFoundException e
) {
275 } catch (IOException e
) {
282 Check if directory for Logs exists or not
283 Create the directory if it doesn't exist
287 private static void createLogDir() throws Exception
{
288 File f
= new File(strLogDir
);
290 FileOperation
.newFolder(strLogDir
);
294 public static boolean isSaveLog() {
298 public static void setSaveLog(boolean isSaveLog
) {
299 Log
.isSaveLog
= isSaveLog
;