0

I tried to enable simple logging for my TCP Server. For this purpose I thought that java.util.logging would do its job fine.

Here is the code that I use to configure my log file:

System.setProperty("java.util.logging.SimpleFormatter.format", "[%1$tF %1$tT] [%4$-7s] [%3s] %5$s %n");

    try {
        FileHandler fileHandler = new FileHandler(System.getProperty("user.dir") +
                                                "/log/RemasteredServer_%u.log", false);
        fileHandler.setFormatter(new SimpleFormatter());
        Logger.getGlobal().addHandler(fileHandler);
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(1);
    }

    logger = Logger.getLogger(ServerMain.class.getName());

When I try to run this I get the following exception:

java.nio.file.NoSuchFileException: C:\Users\samue\log\RemasteredServer_0.log.lck

I already tried different patterns but none of them worked. Thanks for help!

Edit: I wouldn't know why this should be a problem but I use gradle to build and run the server

elsamuray7
  • 79
  • 1
  • 10
  • 3
    Does folder `C:\Users\samue\log` exist? Does the user running the Java program have access to that folder? – Andreas Aug 27 '20 at 23:49
  • What is the full exact version of Java you are using? – jmehrens Aug 28 '20 at 03:08
  • Does this answer your question? [How to create directories for Logger files through FileHandler](https://stackoverflow.com/questions/22732247/how-to-create-directories-for-logger-files-through-filehandler) – jmehrens Aug 28 '20 at 14:49

1 Answers1

0

Ok, I expected that the FileHandler would create the directories to the log file, creating the log folder myself solved the problem, I'm sorry!

elsamuray7
  • 79
  • 1
  • 10