]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/Log.java
Restructuring for better separation of Tool packages.
[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 /**
26 The class is used to provides static interfaces to save log and error information
27
28 **/
29 public class Log {
30
31 //
32 //Log file
33 //
34 private static File fleLogFile = null;
35
36 //
37 //Wrn file
38 //
39 private static File fleWrnFile = null;
40
41 //
42 //Err file
43 //
44 private static File fleErrFile = null;
45
46 //
47 //Log file name
48 //
49 static String strLogFileName = "Log.log";
50
51 //
52 //Wrn file name
53 //
54 static String strWrnFileName = "Wrn.log";
55
56 //
57 //Err file name
58 //
59 static String strErrFileName = "Err.log";
60
61 /**
62 Main class, used for test
63
64 @param args
65
66 **/
67 public static void main(String[] args) {
68 try {
69 //Log.log("Test", "test");
70 //Log.err("Test1", "test1");
71 Log
72 .wrn("aaa bbbbbb cccccccccccc ddddddddddd eeeeeeeeee fffffffffff gggggggggggggggggg hhhhhhhhhhhhhhhhhhhhhhhhhhhhh iiiii jjjj kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk lll mmm nn poooooooooooooooooooooooooooooooooooooooooooop");
73 Log.wrn("Incorrect data type for ModuleEntryPoint");
74 } catch (Exception e) {
75 e.printStackTrace();
76 }
77 }
78
79 /**
80 Call writeToLogFile to save log item and log information to log file
81
82 @param strItem The log item
83 @param strLog The log information
84
85 **/
86 public static void log(String strItem, String strLog) {
87 try {
88 writeToLogFile(strItem + ":" + strLog);
89 } catch (IOException e) {
90 e.printStackTrace();
91 }
92 }
93
94 /**
95 Call writeToLogFile to save log information to log file
96
97 @param strLog The log information
98
99 **/
100 public static void log(String strLog) {
101 try {
102 writeToLogFile(strLog);
103 } catch (IOException e) {
104 e.printStackTrace();
105 }
106 }
107
108 /**
109 Call writeToWrnFile to save wrn item and wrn information to wrn file
110
111 @param strItem The wrn item
112 @param strLog The wrn information
113
114 **/
115 public static void wrn(String strItem, String strWrn) {
116 try {
117 writeToWrnFile("Warning when " + strItem + "::" + strWrn);
118 showWrnMessage(strWrn);
119 } catch (IOException e) {
120 e.printStackTrace();
121 }
122 }
123
124 /**
125 Call writeToWrnFile to save wrn information to wrn file
126
127 @param strLog The wrn information
128
129 **/
130 public static void wrn(String strWrn) {
131 try {
132 writeToWrnFile("Warning::" + strWrn);
133 showWrnMessage("Warning::" + strWrn);
134 } catch (IOException e) {
135 e.printStackTrace();
136 }
137 }
138
139 /**
140 Call writeToErrFile to save err item and err information to err file
141
142 @param strItem The err item
143 @param strLog The err information
144
145 **/
146 public static void err(String strItem, String strErr) {
147 try {
148 writeToErrFile("Error when " + strItem + "::" + strErr);
149 } catch (IOException e) {
150 e.printStackTrace();
151 }
152 }
153
154 /**
155 Call writeToErrFile to save err information to err file
156
157 @param strLog The err information
158
159 **/
160 public static void err(String strErr) {
161 try {
162 writeToErrFile("Error::" + strErr);
163 } catch (IOException e) {
164 e.printStackTrace();
165 }
166 }
167
168 /**
169 Brings up a dialog to show err message
170 When the message's length > defined max length, wrap the text to the next line.
171
172 @param strErr The input data of err message
173
174 **/
175 private static void showWrnMessage(String strErr) {
176 String strReturn = Tools.wrapStringByWord(strErr);
177 JOptionPane
178 .showConfirmDialog(null, strReturn, "Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
179 }
180
181 /**
182 Open log file and write log information
183
184 @param strLog The log information
185 @throws IOException
186
187 **/
188 private static void writeToLogFile(String strLog) throws IOException {
189 try {
190 if (fleLogFile == null) {
191 fleLogFile = new File(strLogFileName);
192 fleLogFile.createNewFile();
193 }
194 FileOutputStream fos = new FileOutputStream(fleLogFile, true);
195 fos.write((Tools.getCurrentDateTime() + DataType.DOS_LINE_SEPARATOR).getBytes());
196 fos.write((strLog + DataType.DOS_LINE_SEPARATOR).getBytes());
197 fos.flush();
198 fos.close();
199 } catch (FileNotFoundException e) {
200 e.printStackTrace();
201 } catch (IOException e) {
202 e.printStackTrace();
203 }
204 }
205
206 /**
207 Open wrn file and write wrn information
208
209 @param strLog The log information
210 @throws IOException
211
212 **/
213 private static void writeToWrnFile(String strLog) throws IOException {
214 try {
215 if (fleWrnFile == null) {
216 fleWrnFile = new File(strWrnFileName);
217 fleWrnFile.createNewFile();
218 }
219 FileOutputStream fos = new FileOutputStream(fleWrnFile, true);
220 fos.write((Tools.getCurrentDateTime() + DataType.DOS_LINE_SEPARATOR).getBytes());
221 fos.write((strLog + DataType.DOS_LINE_SEPARATOR).getBytes());
222 fos.flush();
223 fos.close();
224 } catch (FileNotFoundException e) {
225 e.printStackTrace();
226 } catch (IOException e) {
227 e.printStackTrace();
228 }
229 }
230
231 /**
232 Open err file and write err information
233
234 @param strLog The log information
235 @throws IOException
236
237 **/
238 private static void writeToErrFile(String strLog) throws IOException {
239 try {
240 if (fleErrFile == null) {
241 fleErrFile = new File(strErrFileName);
242 fleErrFile.createNewFile();
243 }
244 FileOutputStream fos = new FileOutputStream(fleErrFile, true);
245 fos.write((Tools.getCurrentDateTime() + DataType.DOS_LINE_SEPARATOR).getBytes());
246 fos.write((strLog + DataType.DOS_LINE_SEPARATOR).getBytes());
247 fos.flush();
248 fos.close();
249 } catch (FileNotFoundException e) {
250 e.printStackTrace();
251 } catch (IOException e) {
252 e.printStackTrace();
253 }
254 }
255 }