]> git.proxmox.com Git - mirror_edk2.git/blame - 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
CommitLineData
a13899c5 1/** @file\r
2 \r
3 The file is used to provides static interfaces to save log and error information \r
4 \r
5 Copyright (c) 2006, Intel Corporation\r
6 All rights reserved. This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10 \r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13 \r
14 **/\r
15\r
16package org.tianocore.frameworkwizard.common;\r
17\r
18import java.io.File;\r
19import java.io.FileNotFoundException;\r
20import java.io.FileOutputStream;\r
21import java.io.IOException;\r
22\r
23import javax.swing.JOptionPane;\r
24\r
82484861 25import org.tianocore.frameworkwizard.FrameworkWizardUI;\r
26\r
a13899c5 27/**\r
28 The class is used to provides static interfaces to save log and error information\r
29 \r
30 **/\r
31public class Log {\r
32\r
33 //\r
34 //Log file\r
35 //\r
36 private static File fleLogFile = null;\r
37\r
ed1665f2 38 //\r
39 //Wrn file\r
40 //\r
41 private static File fleWrnFile = null;\r
42\r
a13899c5 43 //\r
44 //Err file\r
45 //\r
46 private static File fleErrFile = null;\r
47\r
48 //\r
49 //Log file name\r
50 //\r
51 static String strLogFileName = "Log.log";\r
52\r
ed1665f2 53 //\r
54 //Wrn file name\r
55 //\r
56 static String strWrnFileName = "Wrn.log";\r
57\r
a13899c5 58 //\r
59 //Err file name\r
60 //\r
61 static String strErrFileName = "Err.log";\r
62\r
63 /**\r
64 Main class, used for test\r
65 \r
66 @param args\r
67 \r
68 **/\r
69 public static void main(String[] args) {\r
70 try {\r
ed1665f2 71 //Log.log("Test", "test");\r
72 //Log.err("Test1", "test1");\r
ed1665f2 73 Log\r
d933fc5f 74 .wrn("aaa bbbbbb cccccccccccc ddddddddddd eeeeeeeeee fffffffffff gggggggggggggggggg hhhhhhhhhhhhhhhhhhhhhhhhhhhhh iiiii jjjj kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk lll mmm nn poooooooooooooooooooooooooooooooooooooooooooop");\r
75 Log.wrn("Incorrect data type for ModuleEntryPoint");\r
a13899c5 76 } catch (Exception e) {\r
77 e.printStackTrace();\r
78 }\r
79 }\r
80\r
a13899c5 81 /**\r
82 Call writeToLogFile to save log item and log information to log file\r
83 \r
84 @param strItem The log item\r
85 @param strLog The log information\r
86 \r
87 **/\r
88 public static void log(String strItem, String strLog) {\r
89 try {\r
90 writeToLogFile(strItem + ":" + strLog);\r
91 } catch (IOException e) {\r
92 e.printStackTrace();\r
93 }\r
94 }\r
95\r
96 /**\r
97 Call writeToLogFile to save log information to log file\r
98 \r
99 @param strLog The log information\r
100 \r
101 **/\r
102 public static void log(String strLog) {\r
103 try {\r
104 writeToLogFile(strLog);\r
105 } catch (IOException e) {\r
106 e.printStackTrace();\r
107 }\r
108 }\r
109\r
ed1665f2 110 /**\r
111 Call writeToWrnFile to save wrn item and wrn information to wrn file\r
112 \r
113 @param strItem The wrn item\r
114 @param strLog The wrn information\r
115 \r
116 **/\r
117 public static void wrn(String strItem, String strWrn) {\r
118 try {\r
119 writeToWrnFile("Warning when " + strItem + "::" + strWrn);\r
120 showWrnMessage(strWrn);\r
121 } catch (IOException e) {\r
122 e.printStackTrace();\r
123 }\r
124 }\r
125\r
126 /**\r
127 Call writeToWrnFile to save wrn information to wrn file\r
128 \r
129 @param strLog The wrn information\r
130 \r
131 **/\r
132 public static void wrn(String strWrn) {\r
133 try {\r
134 writeToWrnFile("Warning::" + strWrn);\r
135 showWrnMessage("Warning::" + strWrn);\r
136 } catch (IOException e) {\r
137 e.printStackTrace();\r
138 }\r
139 }\r
140\r
a13899c5 141 /**\r
142 Call writeToErrFile to save err item and err information to err file\r
143 \r
144 @param strItem The err item\r
145 @param strLog The err information\r
146 \r
147 **/\r
148 public static void err(String strItem, String strErr) {\r
149 try {\r
150 writeToErrFile("Error when " + strItem + "::" + strErr);\r
a13899c5 151 } catch (IOException e) {\r
152 e.printStackTrace();\r
153 }\r
154 }\r
155\r
156 /**\r
157 Call writeToErrFile to save err information to err file\r
158 \r
159 @param strLog The err information\r
160 \r
161 **/\r
162 public static void err(String strErr) {\r
163 try {\r
164 writeToErrFile("Error::" + strErr);\r
a13899c5 165 } catch (IOException e) {\r
166 e.printStackTrace();\r
167 }\r
168 }\r
169\r
170 /**\r
171 Brings up a dialog to show err message\r
172 When the message's length > defined max length, wrap the text to the next line.\r
173 \r
174 @param strErr The input data of err message\r
175 \r
176 **/\r
ed1665f2 177 private static void showWrnMessage(String strErr) {\r
178 String strReturn = Tools.wrapStringByWord(strErr);\r
d933fc5f 179 JOptionPane\r
82484861 180 .showConfirmDialog(FrameworkWizardUI.getInstance(), strReturn, "Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);\r
a13899c5 181 }\r
182\r
183 /**\r
184 Open log file and write log information\r
185 \r
186 @param strLog The log information\r
187 @throws IOException\r
188 \r
189 **/\r
190 private static void writeToLogFile(String strLog) throws IOException {\r
191 try {\r
192 if (fleLogFile == null) {\r
193 fleLogFile = new File(strLogFileName);\r
194 fleLogFile.createNewFile();\r
195 }\r
196 FileOutputStream fos = new FileOutputStream(fleLogFile, true);\r
197 fos.write((Tools.getCurrentDateTime() + DataType.DOS_LINE_SEPARATOR).getBytes());\r
198 fos.write((strLog + DataType.DOS_LINE_SEPARATOR).getBytes());\r
199 fos.flush();\r
200 fos.close();\r
201 } catch (FileNotFoundException e) {\r
ed1665f2 202 e.printStackTrace();\r
203 } catch (IOException e) {\r
204 e.printStackTrace();\r
205 }\r
206 }\r
207\r
208 /**\r
209 Open wrn file and write wrn information\r
210 \r
211 @param strLog The log information\r
212 @throws IOException\r
213 \r
214 **/\r
215 private static void writeToWrnFile(String strLog) throws IOException {\r
216 try {\r
217 if (fleWrnFile == null) {\r
218 fleWrnFile = new File(strWrnFileName);\r
219 fleWrnFile.createNewFile();\r
220 }\r
221 FileOutputStream fos = new FileOutputStream(fleWrnFile, true);\r
222 fos.write((Tools.getCurrentDateTime() + DataType.DOS_LINE_SEPARATOR).getBytes());\r
223 fos.write((strLog + DataType.DOS_LINE_SEPARATOR).getBytes());\r
224 fos.flush();\r
225 fos.close();\r
226 } catch (FileNotFoundException e) {\r
a13899c5 227 e.printStackTrace();\r
228 } catch (IOException e) {\r
229 e.printStackTrace();\r
230 }\r
231 }\r
232\r
233 /**\r
234 Open err file and write err information\r
235 \r
236 @param strLog The log information\r
237 @throws IOException\r
238 \r
239 **/\r
240 private static void writeToErrFile(String strLog) throws IOException {\r
241 try {\r
242 if (fleErrFile == null) {\r
243 fleErrFile = new File(strErrFileName);\r
244 fleErrFile.createNewFile();\r
245 }\r
246 FileOutputStream fos = new FileOutputStream(fleErrFile, true);\r
247 fos.write((Tools.getCurrentDateTime() + DataType.DOS_LINE_SEPARATOR).getBytes());\r
248 fos.write((strLog + DataType.DOS_LINE_SEPARATOR).getBytes());\r
249 fos.flush();\r
250 fos.close();\r
251 } catch (FileNotFoundException e) {\r
252 e.printStackTrace();\r
253 } catch (IOException e) {\r
254 e.printStackTrace();\r
255 }\r
256 }\r
257}\r