]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/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
;
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 fleErrFile
= null;
44 static String strLogFileName
= "Log.log";
49 static String strErrFileName
= "Err.log";
52 Main class, used for test
57 public static void main(String
[] args
) {
59 Log
.log("Test", "test");
60 Log
.err("Test1", "test1");
61 Log
.err("sdfsdfsd fsdfsdfsdfsdfj dsfksdjflsdjf sdkfjsdklfjsdkf dskfsjdkfjks dskfjsdklfjsdkf sdkfjsdlf sdkfjsdk kdfjskdf sdkfjsdkf ksdjfksdfjskdf sdkfsjdfksd fskdfjsdf", "dfsdf sdfksdf sd sdfksd fsdf");
62 } catch (Exception e
) {
68 This is the default constructor
76 Call writeToLogFile to save log item and log information to log file
78 @param strItem The log item
79 @param strLog The log information
82 public static void log(String strItem
, String strLog
) {
84 writeToLogFile(strItem
+ ":" + strLog
);
85 } catch (IOException e
) {
91 Call writeToLogFile to save log information to log file
93 @param strLog The log information
96 public static void log(String strLog
) {
98 writeToLogFile(strLog
);
99 } catch (IOException e
) {
105 Call writeToErrFile to save err item and err information to err file
107 @param strItem The err item
108 @param strLog The err information
111 public static void err(String strItem
, String strErr
) {
113 writeToErrFile("Error when " + strItem
+ "::" + strErr
);
114 showErrMessage("Error when " + strItem
+ "::" + strErr
);
115 } catch (IOException e
) {
121 Call writeToErrFile to save err information to err file
123 @param strLog The err information
126 public static void err(String strErr
) {
128 writeToErrFile("Error::" + strErr
);
129 showErrMessage("Error::" + strErr
);
130 } catch (IOException e
) {
136 Brings up a dialog to show err message
137 When the message's length > defined max length, wrap the text to the next line.
139 @param strErr The input data of err message
142 private static void showErrMessage(String strErr
) {
143 int intMaxLength
= 40;
144 String strReturn
= "";
146 while (strErr
.length() > 0) {
147 if (strErr
.length() > intMaxLength
) {
148 strTemp
= strErr
.substring(0, intMaxLength
);
149 strErr
= strErr
.substring(strTemp
.length());
150 strReturn
= strReturn
+ strTemp
+ DataType
.UNIX_LINE_SEPARATOR
;
152 } else if (strErr
.length() <= intMaxLength
) {
153 strReturn
= strReturn
+ strErr
;
157 JOptionPane
.showConfirmDialog(null, strReturn
, "Error", JOptionPane
.DEFAULT_OPTION
, JOptionPane
.ERROR_MESSAGE
);
161 Open log file and write log information
163 @param strLog The log information
167 private static void writeToLogFile(String strLog
) throws IOException
{
169 if (fleLogFile
== null) {
170 fleLogFile
= new File(strLogFileName
);
171 fleLogFile
.createNewFile();
173 FileOutputStream fos
= new FileOutputStream(fleLogFile
, true);
174 fos
.write((Tools
.getCurrentDateTime() + DataType
.DOS_LINE_SEPARATOR
).getBytes());
175 fos
.write((strLog
+ DataType
.DOS_LINE_SEPARATOR
).getBytes());
178 } catch (FileNotFoundException e
) {
180 } catch (IOException e
) {
186 Open err file and write err information
188 @param strLog The log information
192 private static void writeToErrFile(String strLog
) throws IOException
{
194 if (fleErrFile
== null) {
195 fleErrFile
= new File(strErrFileName
);
196 fleErrFile
.createNewFile();
198 FileOutputStream fos
= new FileOutputStream(fleErrFile
, true);
199 fos
.write((Tools
.getCurrentDateTime() + DataType
.DOS_LINE_SEPARATOR
).getBytes());
200 fos
.write((strLog
+ DataType
.DOS_LINE_SEPARATOR
).getBytes());
203 } catch (FileNotFoundException e
) {
205 } catch (IOException e
) {