]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/Log.java
Removed DEFAULT Usage type - it is not valid, and should have been removed a while...
[mirror_edk2.git] / Tools / 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
25/**\r
26 The class is used to provides static interfaces to save log and error information\r
27 \r
28 **/\r
29public class Log {\r
30\r
31 //\r
32 //Log file\r
33 //\r
34 private static File fleLogFile = null;\r
35\r
ed1665f2 36 //\r
37 //Wrn file\r
38 //\r
39 private static File fleWrnFile = null;\r
40\r
a13899c5 41 //\r
42 //Err file\r
43 //\r
44 private static File fleErrFile = null;\r
45\r
46 //\r
47 //Log file name\r
48 //\r
49 static String strLogFileName = "Log.log";\r
50\r
ed1665f2 51 //\r
52 //Wrn file name\r
53 //\r
54 static String strWrnFileName = "Wrn.log";\r
55\r
a13899c5 56 //\r
57 //Err file name\r
58 //\r
59 static String strErrFileName = "Err.log";\r
60\r
61 /**\r
62 Main class, used for test\r
63 \r
64 @param args\r
65 \r
66 **/\r
67 public static void main(String[] args) {\r
68 try {\r
ed1665f2 69 //Log.log("Test", "test");\r
70 //Log.err("Test1", "test1");\r
71 Log.wrn("1");\r
72 Log\r
73 .wrn(\r
74 "aaa bbbbbb cccccccccccc ddddddddddd eeeeeeeeee fffffffffff gggggggggggggggggg hhhhhhhhhhhhhhhhhhhhhhhhhhhhh",\r
75 "iiiiii jjjj kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk lll mmm nn poooooooooooooooooooooooooooooooooooooooooooop");\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
179 JOptionPane.showConfirmDialog(null, strReturn, "Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);\r
a13899c5 180 }\r
181\r
182 /**\r
183 Open log file and write log information\r
184 \r
185 @param strLog The log information\r
186 @throws IOException\r
187 \r
188 **/\r
189 private static void writeToLogFile(String strLog) throws IOException {\r
190 try {\r
191 if (fleLogFile == null) {\r
192 fleLogFile = new File(strLogFileName);\r
193 fleLogFile.createNewFile();\r
194 }\r
195 FileOutputStream fos = new FileOutputStream(fleLogFile, true);\r
196 fos.write((Tools.getCurrentDateTime() + DataType.DOS_LINE_SEPARATOR).getBytes());\r
197 fos.write((strLog + DataType.DOS_LINE_SEPARATOR).getBytes());\r
198 fos.flush();\r
199 fos.close();\r
200 } catch (FileNotFoundException e) {\r
ed1665f2 201 e.printStackTrace();\r
202 } catch (IOException e) {\r
203 e.printStackTrace();\r
204 }\r
205 }\r
206\r
207 /**\r
208 Open wrn file and write wrn information\r
209 \r
210 @param strLog The log information\r
211 @throws IOException\r
212 \r
213 **/\r
214 private static void writeToWrnFile(String strLog) throws IOException {\r
215 try {\r
216 if (fleWrnFile == null) {\r
217 fleWrnFile = new File(strWrnFileName);\r
218 fleWrnFile.createNewFile();\r
219 }\r
220 FileOutputStream fos = new FileOutputStream(fleWrnFile, true);\r
221 fos.write((Tools.getCurrentDateTime() + DataType.DOS_LINE_SEPARATOR).getBytes());\r
222 fos.write((strLog + DataType.DOS_LINE_SEPARATOR).getBytes());\r
223 fos.flush();\r
224 fos.close();\r
225 } catch (FileNotFoundException e) {\r
a13899c5 226 e.printStackTrace();\r
227 } catch (IOException e) {\r
228 e.printStackTrace();\r
229 }\r
230 }\r
231\r
232 /**\r
233 Open err file and write err information\r
234 \r
235 @param strLog The log information\r
236 @throws IOException\r
237 \r
238 **/\r
239 private static void writeToErrFile(String strLog) throws IOException {\r
240 try {\r
241 if (fleErrFile == null) {\r
242 fleErrFile = new File(strErrFileName);\r
243 fleErrFile.createNewFile();\r
244 }\r
245 FileOutputStream fos = new FileOutputStream(fleErrFile, true);\r
246 fos.write((Tools.getCurrentDateTime() + DataType.DOS_LINE_SEPARATOR).getBytes());\r
247 fos.write((strLog + DataType.DOS_LINE_SEPARATOR).getBytes());\r
248 fos.flush();\r
249 fos.close();\r
250 } catch (FileNotFoundException e) {\r
251 e.printStackTrace();\r
252 } catch (IOException e) {\r
253 e.printStackTrace();\r
254 }\r
255 }\r
256}\r