1 | |
package org.paneris.jammyjoes.controller; |
2 | |
|
3 | |
import java.io.File; |
4 | |
import java.io.FileWriter; |
5 | |
import java.util.Date; |
6 | |
|
7 | |
public class Logger { |
8 | |
|
9 | |
private String dir; |
10 | |
private String ipAddress; |
11 | |
private String whereClause; |
12 | |
private int hits; |
13 | |
private Integer troid; |
14 | |
private String price; |
15 | |
private String description; |
16 | |
private SearchType type; |
17 | |
private String age; |
18 | |
|
19 | 0 | public Logger(String dir) { |
20 | 0 | this.dir = dir; |
21 | 0 | } |
22 | |
|
23 | |
public void logUsersIp(String ipAddress) { |
24 | 0 | this.ipAddress = ipAddress; |
25 | 0 | } |
26 | |
|
27 | |
public void logWhereClause(String whereClause) { |
28 | 0 | this.whereClause = whereClause; |
29 | 0 | } |
30 | |
|
31 | |
public void writeLog() { |
32 | 0 | if (troid != null && hits == 1) { |
33 | 0 | return; |
34 | |
} |
35 | |
try { |
36 | 0 | FileWriter writer = new FileWriter(new File(dir, "search.log"), true); |
37 | 0 | writer.write(new Date() + "\t" + ipAddress + "\t" + hits + "\t" + type + "\t" + age + "\t" + price + "\t" + description + "\n"); |
38 | 0 | writer.close(); |
39 | 0 | } catch (Exception e) { |
40 | 0 | e.printStackTrace(System.err); |
41 | 0 | } |
42 | 0 | } |
43 | |
|
44 | |
public void logHits(int hits) { |
45 | 0 | this.hits = hits; |
46 | 0 | } |
47 | |
|
48 | |
public void logTroid(Integer troid) { |
49 | 0 | this.troid = troid; |
50 | 0 | } |
51 | |
|
52 | |
public void logPrice(String price) { |
53 | 0 | this.price = price; |
54 | 0 | } |
55 | |
|
56 | |
public void logDescription(String description) { |
57 | 0 | this.description = description; |
58 | 0 | } |
59 | |
|
60 | |
public void logType(SearchType type) { |
61 | 0 | this.type = type; |
62 | 0 | } |
63 | |
|
64 | |
public void logAge(String age) { |
65 | 0 | this.age = age; |
66 | 0 | } |
67 | |
|
68 | |
|
69 | |
} |