source: branches/objectmq-1.0/src/omq/common/util/Log.java @ 33

Last change on this file since 33 was 33, checked in by amoreno, 11 years ago

new release version

File size: 2.4 KB
Line 
1package omq.common.util;
2
3import java.io.File;
4import java.io.FileWriter;
5import java.io.IOException;
6import java.util.Date;
7import java.util.Properties;
8
9import omq.exception.EnvironmentException;
10
11public class Log {
12
13        public static void saveLog(String processName, byte[] bytesResponse) throws IOException {
14                try {
15                        Properties env = Environment.getEnvironment();
16
17                        String debugPath = env.getProperty(ParameterQueue.DEBUGFILE, "");
18                        if (debugPath.length() > 0) {
19                                long timeNow = (new Date()).getTime();
20
21                                File outputFolder = new File(debugPath + File.separator);
22                                outputFolder.mkdirs();
23                               
24//                              File outputFolder = new File(debugPath + File.separator + processName);
25//                              outputFolder.mkdirs();
26
27//                              File outputFileContent = new File(outputFolder.getAbsoluteFile() + File.separator + "content_" + timeNow);
28//                              FileOutputStream outputStream = new FileOutputStream(outputFileContent);
29//                              IOUtils.write(bytesResponse, outputStream);
30//                              outputStream.close();
31
32                                File outputFileLog = new File(debugPath + File.separator + "log");
33                                boolean exist = outputFileLog.exists();
34                               
35                                FileWriter fw = new FileWriter(outputFileLog, true); // the true will append the new data
36                                if(!exist){
37                                        fw.write("#ProcessName\t\tFile\t\t\t\t\tDate\t\t\tSize\n");
38                                }
39                                fw.write(processName + "\t" + "content_" + timeNow + "\t" + timeNow + "\t" + bytesResponse.length + "\tbytes\n");
40                                fw.close();
41                        }
42                } catch (EnvironmentException e) {
43                        throw new IOException(e.getMessage(), e);
44                }
45        }
46       
47        public static void saveTimeSendRequestLog(String processName, String coorId, String method, long timeNow) throws IOException {
48                try {
49                        Properties env = Environment.getEnvironment();
50
51                        String debugPath = env.getProperty(ParameterQueue.DEBUGFILE, "");
52                        if (debugPath.length() > 0) {                   
53                                File outputFolder = new File(debugPath + File.separator + processName);
54                                outputFolder.mkdirs();
55                               
56                                File outputFileLog = new File(outputFolder + File.separator + "log");
57                                boolean exist = outputFileLog.exists();
58                               
59                                FileWriter fw = new FileWriter(outputFileLog, true); // the true will append the new data
60                                if(!exist){
61                                        fw.write("#CoorId\tMethod\tDate\n");
62                                }
63                                fw.write(coorId + "\t" + method + "\t" + timeNow + "\n");
64                                fw.close();
65                        }
66                } catch (EnvironmentException e) {
67                        throw new IOException(e.getMessage(), e);
68                }
69        }       
70}
Note: See TracBrowser for help on using the repository browser.