Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
308 ashish 1
package in.shop2020.utils;
2
 
3
import in.shop2020.datalogger.MsgType;
4
import in.shop2020.thrift.clients.DataLoggingClient;
5
 
6
import java.util.HashMap;
7
import java.util.Map;
8
import java.util.Map.Entry;
9
 
10
import org.apache.thrift.TException;
11
 
12
public class DataLogEntry {
13
 
14
	public static enum LogKeys{
15
		USERID,
16
		IP,
17
		STATUS,
18
		ITEMID,
19
		CARTID,
20
		PAYMENT_ID,
21
		TRANSACTION_ID
22
	}
23
 
24
	private final MsgType type;
25
 
26
	private final Map<String, String> values;
27
 
28
	public DataLogEntry(MsgType type){
29
		values =  new HashMap<String, String>();
30
		this.type = type;
31
	}
32
 
33
	public DataLogEntry(MsgType type, String userId, String ip){
34
		values =  new HashMap<String, String>();
35
		values.put(LogKeys.USERID.toString(), userId);
36
		values.put(LogKeys.IP.toString(), ip);
37
		this.type = type;
38
	}
39
 
40
	public DataLogEntry(MsgType type, long userId, String ip){
41
		values =  new HashMap<String, String>();
42
		values.put(LogKeys.USERID.toString(), userId+"");
43
		values.put(LogKeys.IP.toString(), ip);
44
		this.type = type;
45
	}
46
 
47
	public void addLogUnit(String key, String value){
48
		values.put(key, value);
49
	}
50
 
51
	public void log(){
52
		String s = new String();
53
 
54
		for(Entry<String, String> e: values.entrySet()){
55
			s += e.getKey()+"="+e.getValue();
56
		}
57
		s+= "\n";
58
 
59
		submit(s);
60
	}
61
 
62
	private void submit(String message){
63
 
64
		try {
65
			DataLoggingClient client = new DataLoggingClient();
66
 
67
			client.getClient().log(type, message);
68
		} catch (TException e) {
69
 
70
			e.printStackTrace();
71
		} catch (Exception e) {
72
 
73
			e.printStackTrace();
74
		}	
75
	}
76
}