1 | package omq.common.util; |
---|
2 | |
---|
3 | import java.io.File; |
---|
4 | import java.io.FileWriter; |
---|
5 | import java.io.IOException; |
---|
6 | import java.util.Date; |
---|
7 | import java.util.Properties; |
---|
8 | |
---|
9 | import omq.common.broker.Broker; |
---|
10 | |
---|
11 | public 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 | } |
---|