I am trying to create a java logger file that will write output to a file within the project folder (NetBeans, MacOS). I'm doing this for a school project so I can't use Log4j. I have reviewed previously asked questions regarding this subject and tried to implement those solutions but I'm still not seeing any success. Do I need to extend the file path, or is there a major component that I'm missing out on? Any steps in the right direction would be helpful, thank you.
I have tried extending the file path to go from the users folder all the way down to the individual project folder in netbeans. I have looked at quite a few resources and examples but whatever element I'm missing I haven't managed to find out.
public class log {
private final static Logger LOGGER =
Logger.getLogger(log.class.getName());
private final static FileHandler handleLog = null;
public static void start() throws IOException,
SecurityException{
FileHandler handleLog = new
FileHandler("/Users/cassie/NetBeansProjects/GlobalConsulting-
userLog.%u.%g.txt", 1024 * 1024, 10, true);
SimpleFormatter simple = new SimpleFormatter();
handleLog.setFormatter(simple);
LOGGER.addHandler(handleLog);
LOGGER.setLevel(Level.INFO);
}
public static void main(String[] args) throws IOException,
SecurityException{
start();
LOGGER.info("------------------START--------------------");
}
}
When I call it in another file, this is how I did it.
LOGGER.log(Level.INFO, "{0} logged in", currentUser.getUsername());
What I was hoping was that when the program was run, the output (user logged in) would print to a log file within the project folder and would update 10 times before rewriting. I don't get any error messages but all output goes straight to console instead.