class LogFormatter extends Formatter {

	public String format(LogRecord record) {
		IOFogNetworkInterfaceManager fogNetworkInterfaceManager = IOFogNetworkInterfaceManager.getInstance();
		final DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
		JsonBuilderFactory factory = Json.createBuilderFactory(null);
		JsonObjectBuilder jsonObjectBuilder = factory.createObjectBuilder();
		jsonObjectBuilder.add("timestamp", df.format(System.currentTimeMillis()));
		jsonObjectBuilder.add("level", record.getLevel().toString());
		jsonObjectBuilder.add("agent_id", Configuration.getIofogUuid());
		jsonObjectBuilder.add("pid", fogNetworkInterfaceManager.getPid() != 0 ? fogNetworkInterfaceManager.getPid() : fogNetworkInterfaceManager.getFogPid());
		jsonObjectBuilder.add("hostname", fogNetworkInterfaceManager.getHostName() != null ? fogNetworkInterfaceManager.getHostName(): IOFogNetworkInterface.getHostName());
		jsonObjectBuilder.add("thread", record.getSourceClassName());
		jsonObjectBuilder.add("module", record.getSourceMethodName());
		jsonObjectBuilder.add("message", record.getMessage());
		if (record.getThrown() != null) {
			jsonObjectBuilder.add("exception_message", record.getThrown().getLocalizedMessage());
			jsonObjectBuilder.add("stacktrace", ExceptionUtils.getFullStackTrace(record.getThrown()));
		}
		return jsonObjectBuilder.build().toString().concat("\n");
	}

}