]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/ModuleEditor/src/org/tianocore/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
.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
28 @since ModuleEditor 1.0
36 private static File fleLogFile
= null;
41 private static File fleErrFile
= null;
46 static String strLogFileName
= "Log.log";
51 static String strErrFileName
= "Err.log";
54 Main class, used for test
59 public static void main(String
[] args
) {
61 Log
.log("Test", "test");
62 Log
.err("Test1", "test1");
63 Log
.err("sdfsdfsd fsdfsdfsdfsdfj dsfksdjflsdjf sdkfjsdklfjsdkf dskfsjdkfjks dskfjsdklfjsdkf sdkfjsdlf sdkfjsdk kdfjskdf sdkfjsdkf ksdjfksdfjskdf sdkfsjdfksd fskdfjsdf", "dfsdf sdfksdf sd sdfksd fsdf");
64 } catch (Exception e
) {
70 This is the default constructor
78 Call writeToLogFile to save log item and log information to log file
80 @param strItem The log item
81 @param strLog The log information
84 public static void log(String strItem
, String strLog
) {
86 writeToLogFile(strItem
+ ":" + strLog
);
87 } catch (IOException e
) {
93 Call writeToLogFile to save log information to log file
95 @param strLog The log information
98 public static void log(String strLog
) {
100 writeToLogFile(strLog
);
101 } catch (IOException e
) {
107 Call writeToErrFile to save err item and err information to err file
109 @param strItem The err item
110 @param strLog The err information
113 public static void err(String strItem
, String strErr
) {
115 writeToErrFile("Error when " + strItem
+ "::" + strErr
);
116 showErrMessage("Error when " + strItem
+ "::" + strErr
);
117 } catch (IOException e
) {
123 Call writeToErrFile to save err information to err file
125 @param strLog The err information
128 public static void err(String strErr
) {
130 writeToErrFile("Error::" + strErr
);
131 showErrMessage("Error::" + strErr
);
132 } catch (IOException e
) {
138 Brings up a dialog to show err message
139 When the message's length > defined max length, wrap the text to the next line.
141 @param strErr The input data of err message
144 private static void showErrMessage(String strErr
) {
145 int intMaxLength
= 40;
146 String strReturn
= "";
148 while (strErr
.length() > 0) {
149 if (strErr
.length() > intMaxLength
) {
150 strTemp
= strErr
.substring(0, intMaxLength
);
151 strErr
= strErr
.substring(strTemp
.length());
152 strReturn
= strReturn
+ strTemp
+ DataType
.UNXI_LINE_SEPARATOR
;
154 } else if (strErr
.length() <= intMaxLength
) {
155 strReturn
= strReturn
+ strErr
;
159 JOptionPane
.showConfirmDialog(null, strReturn
, "Error", JOptionPane
.DEFAULT_OPTION
, JOptionPane
.ERROR_MESSAGE
);
163 Open log file and write log information
165 @param strLog The log information
169 private static void writeToLogFile(String strLog
) throws IOException
{
171 if (fleLogFile
== null) {
172 fleLogFile
= new File(strLogFileName
);
173 fleLogFile
.createNewFile();
175 FileOutputStream fos
= new FileOutputStream(fleLogFile
, true);
176 fos
.write((Tools
.getCurrentDateTime() + DataType
.DOS_LINE_SEPARATOR
).getBytes());
177 fos
.write((strLog
+ DataType
.DOS_LINE_SEPARATOR
).getBytes());
180 } catch (FileNotFoundException e
) {
182 } catch (IOException e
) {
188 Open err file and write err information
190 @param strLog The log information
194 private static void writeToErrFile(String strLog
) throws IOException
{
196 if (fleErrFile
== null) {
197 fleErrFile
= new File(strErrFileName
);
198 fleErrFile
.createNewFile();
200 FileOutputStream fos
= new FileOutputStream(fleErrFile
, true);
201 fos
.write((Tools
.getCurrentDateTime() + DataType
.DOS_LINE_SEPARATOR
).getBytes());
202 fos
.write((strLog
+ DataType
.DOS_LINE_SEPARATOR
).getBytes());
205 } catch (FileNotFoundException e
) {
207 } catch (IOException e
) {