In the first task, you need to update/change lines 4-8 and 14.
Information on RollingFileAppender can be found here.
If you want to test your logs from task 2, you will need to:
1) create a log4j.properties file and save it in the root of the project folder.
2) copy/paste log4j file info from task 1.
3) in line 1 set the rootLogger to =TRACE, stdout.
4) in line 5 set the threshold to DEBUG
5) in line 6 set the desired path to the .log file
6) in line 14 set the direct log message to stdout threshold to ALL
7) delete the ConversionPattern line
8) set the three framework levels to DEBUG
9) in the Solution class add import org.apache.log4j.PropertyConfigurator;
10) in main() add the following test code:
String logProperties = "log4j.properties";
PropertyConfigurator.configure(logProperties);
Path path = Paths.get(logProperties).toAbsolutePath();
try (InputStream is = new FileInputStream(path.toFile())) {
Properties properties = new Properties();
properties.load(is);
System.out.println("See detailed log in file: " + properties.getProperty("log4j.appender.file.File"));
} catch (IOException e) { e.printStackTrace(); }
System.out.println("\nLOG STARTED");
System.out.println("=====================");
Solution solution = new Solution(150, "Skynet", new Date());
solution.calculateAndSetValue3(5555L);
solution.printString();
solution.printDateAsLong();
solution.divide(10, 5);
solution.divide(10, 0);
solution.setValue1(999);
solution.setValue2("Test string");
solution.setValue3(new Date());
11) You will need to comment out/remove the PropertyConfigurator import before sending your code for validation.
Here is how slf4j-log4j works for me into Idea:
1) Download 3 files: slf4j-log4j12-1.7.12 and slf4j-api-1.7.12 jar files, and log4j-1.2.17 zip file, in the last one extract and get the jar file.
2) In Intellij: Go to File -> Project Sturcture -> libraries; Find "+" button and add downloaded files
3) You can set the location of your log4j.properties from inside your java app by using:
org.apache.log4j.PropertyConfigurator.configure(file/location/log4j.properties)
GO TO FULL VERSION