Create a File logging Utility using Java Code
Many times during coding, we need to log our outputs or comments. Usual way to do that is to print the log on the Console using System.out.println() function. However, there can be a requirement to print the output or comments to a file so that it can be referenced later. One option is to use log4j library which is a standard logging utility. However, you can also create your own utility using a few lines of Java Code! Let's check out how. We'll try to cover the following utilities which can form the base of a logging tool: 1. File logging by passing the value and the file path. 2. File logging by passing the value and setting the log path in a properties file. 3. Clear the log file. Let's first take a look at a basic File logging utility. 1. File logging by passing the value and the file path. /** * Writes data/logs to a file. We'll pass both the filePath where the log needs to be written, and the fileValue which needs to be written. ...