We are using slf4jlogger
to log files. After the completion of the processes the log file is automatically saved in a restricted location. Since, I don't have access to download this file later, I want to create the log file manually following the slf4jlogger
.
I have the following code:
test class
package com.worksap.company.hue.controller.com.ifx.inputengine.imports.sample;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class test {
Logger logger = LoggerFactory.getLogger(this.getClass());
@Test
public void testFunction() {
test2 t = new test2();
StringBuilder execLog = new StringBuilder("");
logger.info("Starting execution" + System.getProperty("line.separator"));
execLog.append("Starting execution" + System.getProperty("line.separator"));
t.executeProcess(execLog);
logger.info("ending exection");
execLog.append(String.format("ending execution" + System.getProperty("line.separator")));
System.out.println(execLog);
}
}
test2 class
package com.worksap.company.hue.controller.com.ifx.inputengine.imports.sample;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class test2 {
Logger logger = LoggerFactory.getLogger(this.getClass());
public void executeProcess(StringBuilder execLog) {
logger.info("execution step");
execLog.append(String.format("execution step" + System.getProperty("line.separator")));
}
}
I then want to push the execLog
content to AWS S3 so that I can have access to the log files later. I have the following questions:
- Is this a good way to reproduce the logs or is there a better way to do it?
- How can I avoid repetition of the same string content?
e.g.
logger.info("Starting execution" + System.getProperty("line.separator"));
execLog.append("Starting execution" + System.getProperty("line.separator"));