Java Logging - where is my log file?

前端 未结 7 870
隐瞒了意图╮
隐瞒了意图╮ 2021-01-01 11:47

I\'m having trouble finding my log files.

I\'m using Java Logging - java.util.logging - in Eclipse 3.7.1 on Windows XP. The relevant lines of my

7条回答
  •  悲哀的现实
    2021-01-01 12:03

    1. Debug the your variable or logger.getHandlers(): just for the instances of FileHandler, and look for its private field: files
    2. Make sure that your logger level including your log.
    3. Make sure that your handler level including your log.
    4. It will be sent to your home directory. If there's no that directory in your operate system, such as windows 95/98/ME, the file should be saved to the default path like C:\Windows\.
    5. Reflect, the same as tip 1

      Field[] handlerFiles = handler.getClass().getDeclaredFields();
      AccessibleObject.setAccessible(handlerFiles, true);
      
      for (Field field : handlerFiles) {
          if (field.getName().equals("files")) {
              File[] files = (File[]) field.get(handler);
              System.out.println(Arrays.toString(files));
          }
      }
      
    6. The log manager will be initialized during JVM startup and completed before the main method. You can also re-initialize it in main method with System.setProperty("java.util.logging.config.file", file), which will call LogManager.readConfiguration().

提交回复
热议问题