]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/CreateMdkPkg/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 CreateMdkPkg 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 } catch (Exception e
) {
69 This is the default constructor
77 Call writeToLogFile to save log item and log information to log file
79 @param strItem The log item
80 @param strLog The log information
83 public static void log(String strItem
, String strLog
) {
85 writeToLogFile(strItem
+ ":" + strLog
);
86 } catch (IOException e
) {
92 Call writeToLogFile to save log information to log file
94 @param strLog The log information
97 public static void log(String strLog
) {
99 writeToLogFile(strLog
);
100 } catch (IOException e
) {
106 Call writeToErrFile to save err item and err information to err file
108 @param strItem The err item
109 @param strLog The err information
112 public static void err(String strItem
, String strErr
) {
114 writeToErrFile("Error when " + strItem
+ ":" + strErr
);
115 JOptionPane
.showConfirmDialog(null, "Error when " + strItem
+ "::" + strErr
, "Error",
116 JOptionPane
.DEFAULT_OPTION
, JOptionPane
.ERROR_MESSAGE
);
118 } catch (IOException e
) {
124 Call writeToErrFile to save err information to err file
126 @param strLog The err information
129 public static void err(String strErr
) {
131 writeToErrFile("Error::" + strErr
);
132 JOptionPane
.showConfirmDialog(null, "Error::" + strErr
, "Error", JOptionPane
.DEFAULT_OPTION
,
133 JOptionPane
.ERROR_MESSAGE
);
134 } catch (IOException e
) {
140 Open log file and write log information
142 @param strLog The log information
146 private static void writeToLogFile(String strLog
) throws IOException
{
148 if (fleLogFile
== null) {
149 fleLogFile
= new File(strLogFileName
);
150 fleLogFile
.createNewFile();
152 FileOutputStream fos
= new FileOutputStream(fleLogFile
, true);
153 fos
.write((Tools
.getCurrentDateTime() + "\r\n").getBytes());
154 fos
.write((strLog
+ "\r\n").getBytes());
157 } catch (FileNotFoundException e
) {
159 } catch (IOException e
) {
165 Open err file and write err information
167 @param strLog The log information
171 private static void writeToErrFile(String strLog
) throws IOException
{
173 if (fleErrFile
== null) {
174 fleErrFile
= new File(strErrFileName
);
175 fleErrFile
.createNewFile();
177 FileOutputStream fos
= new FileOutputStream(fleErrFile
, true);
178 fos
.write((Tools
.getCurrentDateTime() + "\r\n").getBytes());
179 fos
.write((strLog
+ "\r\n").getBytes());
182 } catch (FileNotFoundException e
) {
184 } catch (IOException e
) {