source: trunk/src/main/java/omq/common/util/Log.java @ 47

Last change on this file since 47 was 47, checked in by stoda, 11 years ago

Refactoring Environment class - deleted.
StopBroker? problems solved (?)
Server can receive send and receive messages in different formats.
Some tests modified

TODO: finish all the tests, add log4j

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.common.broker.Broker;
10
11public class Log {
12
13        public static void saveLog(String processName, byte[] bytesResponse) throws IOException {
14
15                Properties env = Broker.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 +
25                        // processName);
26                        // outputFolder.mkdirs();
27
28                        // File outputFileContent = new
29                        // File(outputFolder.getAbsoluteFile() + File.separator +
30                        // "content_" + timeNow);
31                        // FileOutputStream outputStream = new
32                        // FileOutputStream(outputFileContent);
33                        // IOUtils.write(bytesResponse, outputStream);
34                        // outputStream.close();
35
36                        File outputFileLog = new File(debugPath + File.separator + "log");
37                        boolean exist = outputFileLog.exists();
38
39                        FileWriter fw = new FileWriter(outputFileLog, true); // the true
40                                                                                                                                        // will
41                                                                                                                                        // append
42                                                                                                                                        // the
43                                                                                                                                        // new
44                                                                                                                                        // data
45                        if (!exist) {
46                                fw.write("#ProcessName\t\tFile\t\t\t\t\tDate\t\t\tSize\n");
47                        }
48                        fw.write(processName + "\t" + "content_" + timeNow + "\t" + timeNow + "\t" + bytesResponse.length + "\tbytes\n");
49                        fw.close();
50                }
51
52        }
53
54        public static void saveTimeSendRequestLog(String processName, String coorId, String method, long timeNow) throws IOException {
55
56                Properties env = Broker.getEnvironment();
57
58                String debugPath = env.getProperty(ParameterQueue.DEBUGFILE, "");
59                if (debugPath.length() > 0) {
60                        File outputFolder = new File(debugPath + File.separator + processName);
61                        outputFolder.mkdirs();
62
63                        File outputFileLog = new File(outputFolder + File.separator + "log");
64                        boolean exist = outputFileLog.exists();
65
66                        FileWriter fw = new FileWriter(outputFileLog, true); // the true
67                                                                                                                                        // will
68                                                                                                                                        // append
69                                                                                                                                        // the
70                                                                                                                                        // new
71                                                                                                                                        // data
72                        if (!exist) {
73                                fw.write("#CoorId\tMethod\tDate\n");
74                        }
75                        fw.write(coorId + "\t" + method + "\t" + timeNow + "\n");
76                        fw.close();
77                }
78
79        }
80}
Note: See TracBrowser for help on using the repository browser.