I made a logging system, but I need to write the log messages in a seperate log/txt file.
I came up with this:
public class UIRestService {
private static final Logger LOGGER = Logger.getLogger(UIRestService.class.toString());
FileHandler fh;
public UIRestService() {
try {
fh = new FileHandler("E:/MyLog.log");
LOGGER.addHandler(fh);
SimpleFormatter formatter = new SimpleFormatter();
fh.setFormatter(formatter);
} catch (IOException e){
e.printStackTrace();
}
}
public MainDTO registerEORI(@RequestBody EoriRegistration json){
long startTime = System.currentTimeMillis();
try {
LOGGER.info("--- Start EORI registration ---");
EoriData entity = Converter.convertDTO2Entity(json);
LOGGER.info("Converted DTO to Entity");
MainDTO dto = dataManager.registration(entity);
if (dto instanceof EoriRegistration) {
msgManager.writeMsg(json.getState(), json.getC8_number() == null ? "test" : json.getC8_number());//TODO remove after IAM json.getC8_number()
}
return dto;
} catch (Exception e){
LOGGER.info("Exception in registerEORI");
e.printStackTrace();
Error error = new Error(Constants.TYPE_DTO2);
error.setErrorDescription(e.getMessage());
LOGGER.info("Exception in registerEORI" + error);
return error;
} finally {
long endTime = System.currentTimeMillis();
LOGGER.info("Registering EORI id: " + json.getId() + " , eori number:" + json.getEoriNumber() + " , elapsed:" + (endTime - startTime));
}
}
}
I manually created MyLog.log file in E:/ , but there is nothing. I tried with no manual created file - again nothing. It says that constructor is never used. Can you tell me what I am doing wrong? I used this example - Example