I have an Android Application.
I have captured the events by creating a method which captures various parameter /variable value from the application. The code snippet which I have written contain EventClass and EventModelClass { public class UserAccessEvent implements ILog {
private Logger mLogger = null;
UserAccessEventModel obj;
public void StoreUserAccessEvent(String Timestamp, String UserId, int FailedAttempts, int SuccessfulAttempts, int Attempts,
int NoOfRevocations, int PassCodeChange) {
obj = new UserAccessEventModel(Timestamp, UserId, SuccessfulAttempts, FailedAttempts, Attempts, NoOfRevocations, PassCodeChange);
toJsonLog();
}
public String toJsonLog() {
JSONObject event = new JSONObject();
try {
event.put("Timestamp", obj.getTimestamp());
event.put("UserId", obj.userid);
event.put("SuccessfulAttempts", obj.successfulattempts);
event.put("FailedAttempts", obj.failedattempts);
event.put("Attempts", obj.attempts);
event.put("NoOfRevocations", obj.noofrevocations);
event.put("PassCodeChange", obj.passcodechange);
//to store the log data that is stored in json object
Log.d("UserAccessEvent", event.toString());
return event.toString();
} catch (Exception e) {
Log.d("UserAccessEvent", "Exception");
throw new RuntimeException(e);
}
}
}
public class UserAccessEventModel {
private String timestamp;
public String userid;
public int successfulattempts;
public int failedattempts;
public int attempts;
public int noofrevocations;
public int passcodechange;
public void setTimestamp(String timestamp) {
this.timestamp = timestamp;
}
public void setUserid(String userid) {
this.userid = userid;
}
public void setSuccessfulattempts(int successfulattempts) { this.successfulattempts = successfulattempts; }
public void setFailedattempts(int failedattempts) {
this.failedattempts = failedattempts;
}
public void setAttempts(int attempts) {
this.attempts = attempts;
}
public void setNoofrevocations(int noofrevocations) {
this.noofrevocations = noofrevocations;
}
public void setPasscodechange(int passcodechange) {
this.passcodechange = passcodechange;
}
public String getTimestamp(){
timestamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime());
return timestamp;
}
public UserAccessEventModel() {
}
public UserAccessEventModel(String timestamp, String userid, int successfulattempts, int failedattempts, int attempts, int noofrevocations, int passcodechange) {
this.timestamp = timestamp;
this.userid = userid;
this.successfulattempts = successfulattempts;
this.failedattempts = failedattempts;
this.attempts = attempts;
this.noofrevocations = noofrevocations;
this.passcodechange = passcodechange;
}
}
I want to make changes so that I can just use JSON to log data without using model class.I want it to be more generic.....
Now I need to log the data which is in the method by just changing the JSON method key/values pair.
Is there any method where I can do this??
Please Give any Suggestions.