[44] | 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 | |
---|
[47] | 9 | import omq.common.broker.Broker; |
---|
[44] | 10 | |
---|
| 11 | public class Log { |
---|
| 12 | |
---|
| 13 | public static void saveLog(String processName, byte[] bytesResponse) throws IOException { |
---|
| 14 | |
---|
[47] | 15 | Properties env = Broker.getEnvironment(); |
---|
[44] | 16 | |
---|
[47] | 17 | String debugPath = env.getProperty(ParameterQueue.DEBUGFILE, ""); |
---|
| 18 | if (debugPath.length() > 0) { |
---|
| 19 | long timeNow = (new Date()).getTime(); |
---|
[44] | 20 | |
---|
[47] | 21 | File outputFolder = new File(debugPath + File.separator); |
---|
| 22 | outputFolder.mkdirs(); |
---|
[44] | 23 | |
---|
[47] | 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"); |
---|
[44] | 47 | } |
---|
[47] | 48 | fw.write(processName + "\t" + "content_" + timeNow + "\t" + timeNow + "\t" + bytesResponse.length + "\tbytes\n"); |
---|
| 49 | fw.close(); |
---|
[44] | 50 | } |
---|
[47] | 51 | |
---|
[44] | 52 | } |
---|
[47] | 53 | |
---|
[44] | 54 | public static void saveTimeSendRequestLog(String processName, String coorId, String method, long timeNow) throws IOException { |
---|
| 55 | |
---|
[47] | 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"); |
---|
[44] | 74 | } |
---|
[47] | 75 | fw.write(coorId + "\t" + method + "\t" + timeNow + "\n"); |
---|
| 76 | fw.close(); |
---|
[44] | 77 | } |
---|
[47] | 78 | |
---|
| 79 | } |
---|
[44] | 80 | } |
---|