View Javadoc

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    public Logger(String dir) {
20      this.dir = dir;
21    }
22  
23    public void logUsersIp(String ipAddress) {
24     this.ipAddress = ipAddress;
25    }
26  
27    public void logWhereClause(String whereClause) {
28      this.whereClause = whereClause;
29    }
30  
31    public void writeLog() {
32      if (troid != null && hits == 1) {
33        return;
34      }
35      try {
36        FileWriter writer = new FileWriter(new File(dir, "search.log"), true);
37        writer.write(new Date() + "\t" + ipAddress + "\t" + hits + "\t" + type + "\t" + age + "\t" + price + "\t" + description + "\n");
38        writer.close();
39      } catch (Exception e) {
40        e.printStackTrace(System.err);
41      }
42    }
43  
44    public void logHits(int hits) {
45      this.hits = hits;
46    }
47  
48    public void logTroid(Integer troid) {
49      this.troid = troid;
50    }
51  
52    public void logPrice(String price) {
53      this.price = price;
54    }
55  
56    public void logDescription(String description) {
57      this.description = description;
58    }
59  
60    public void logType(SearchType type) {
61      this.type = type;
62    }
63  
64    public void logAge(String age) {
65      this.age = age;
66    }
67  
68  
69  }