]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/Log.java
Make opening dialogs re-gain focus when user switch back to main UI from other window...
[mirror_edk2.git] / Tools / Java / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / common / Log.java
1 /** @file
2
3 The file is used to provides static interfaces to save log and error information
4
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
10
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.
13
14 **/
15
16 package org.tianocore.frameworkwizard.common;
17
18 import java.io.File;
19 import java.io.FileNotFoundException;
20 import java.io.FileOutputStream;
21 import java.io.IOException;
22
23 import javax.swing.JOptionPane;
24
25 import org.tianocore.frameworkwizard.FrameworkWizardUI;
26
27 /**
28 The class is used to provides static interfaces to save log and error information
29
30 **/
31 public class Log {
32
33 //
34 //Log file
35 //
36 private static File fleLogFile = null;
37
38 //
39 //Wrn file
40 //
41 private static File fleWrnFile = null;
42
43 //
44 //Err file
45 //
46 private static File fleErrFile = null;
47
48 //
49 //Log file name
50 //
51 static String strLogFileName = "Log.log";
52
53 //
54 //Wrn file name
55 //
56 static String strWrnFileName = "Wrn.log";
57
58 //
59 //Err file name
60 //
61 static String strErrFileName = "Err.log";
62
63 /**
64 Main class, used for test
65
66 @param args
67
68 **/
69 public static void main(String[] args) {
70 try {
71 //Log.log("Test", "test");
72 //Log.err("Test1", "test1");
73 Log
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) {
77 e.printStackTrace();
78 }
79 }
80
81 /**
82 Call writeToLogFile to save log item and log information to log file
83
84 @param strItem The log item
85 @param strLog The log information
86
87 **/
88 public static void log(String strItem, String strLog) {
89 try {
90 writeToLogFile(strItem + ":" + strLog);
91 } catch (IOException e) {
92 e.printStackTrace();
93 }
94 }
95
96 /**
97 Call writeToLogFile to save log information to log file
98
99 @param strLog The log information
100
101 **/
102 public static void log(String strLog) {
103 try {
104 writeToLogFile(strLog);
105 } catch (IOException e) {
106 e.printStackTrace();
107 }
108 }
109
110 /**
111 Call writeToWrnFile to save wrn item and wrn information to wrn file
112
113 @param strItem The wrn item
114 @param strLog The wrn information
115
116 **/
117 public static void wrn(String strItem, String strWrn) {
118 try {
119 writeToWrnFile("Warning when " + strItem + "::" + strWrn);
120 showWrnMessage(strWrn);
121 } catch (IOException e) {
122 e.printStackTrace();
123 }
124 }
125
126 /**
127 Call writeToWrnFile to save wrn information to wrn file
128
129 @param strLog The wrn information
130
131 **/
132 public static void wrn(String strWrn) {
133 try {
134 writeToWrnFile("Warning::" + strWrn);
135 showWrnMessage("Warning::" + strWrn);
136 } catch (IOException e) {
137 e.printStackTrace();
138 }
139 }
140
141 /**
142 Call writeToErrFile to save err item and err information to err file
143
144 @param strItem The err item
145 @param strLog The err information
146
147 **/
148 public static void err(String strItem, String strErr) {
149 try {
150 writeToErrFile("Error when " + strItem + "::" + strErr);
151 } catch (IOException e) {
152 e.printStackTrace();
153 }
154 }
155
156 /**
157 Call writeToErrFile to save err information to err file
158
159 @param strLog The err information
160
161 **/
162 public static void err(String strErr) {
163 try {
164 writeToErrFile("Error::" + strErr);
165 } catch (IOException e) {
166 e.printStackTrace();
167 }
168 }
169
170 /**
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.
173
174 @param strErr The input data of err message
175
176 **/
177 private static void showWrnMessage(String strErr) {
178 String strReturn = Tools.wrapStringByWord(strErr);
179 JOptionPane
180 .showConfirmDialog(FrameworkWizardUI.getInstance(), strReturn, "Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
181 }
182
183 /**
184 Open log file and write log information
185
186 @param strLog The log information
187 @throws IOException
188
189 **/
190 private static void writeToLogFile(String strLog) throws IOException {
191 try {
192 if (fleLogFile == null) {
193 fleLogFile = new File(strLogFileName);
194 fleLogFile.createNewFile();
195 }
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());
199 fos.flush();
200 fos.close();
201 } catch (FileNotFoundException e) {
202 e.printStackTrace();
203 } catch (IOException e) {
204 e.printStackTrace();
205 }
206 }
207
208 /**
209 Open wrn file and write wrn information
210
211 @param strLog The log information
212 @throws IOException
213
214 **/
215 private static void writeToWrnFile(String strLog) throws IOException {
216 try {
217 if (fleWrnFile == null) {
218 fleWrnFile = new File(strWrnFileName);
219 fleWrnFile.createNewFile();
220 }
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());
224 fos.flush();
225 fos.close();
226 } catch (FileNotFoundException e) {
227 e.printStackTrace();
228 } catch (IOException e) {
229 e.printStackTrace();
230 }
231 }
232
233 /**
234 Open err file and write err information
235
236 @param strLog The log information
237 @throws IOException
238
239 **/
240 private static void writeToErrFile(String strLog) throws IOException {
241 try {
242 if (fleErrFile == null) {
243 fleErrFile = new File(strErrFileName);
244 fleErrFile.createNewFile();
245 }
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());
249 fos.flush();
250 fos.close();
251 } catch (FileNotFoundException e) {
252 e.printStackTrace();
253 } catch (IOException e) {
254 e.printStackTrace();
255 }
256 }
257 }