Logging { private static void recoverTempFiles(String logPath) { File logPathFile = new File(logPath).getParentFile(); File[] tempFiles = logPathFile.listFiles((dir, name) -> name.endsWith(TEMP_FILE_EXTENSION)); if (tempFiles == null) { return; } for (File tempFile : tempFiles) { String newName = tempFile.getName().substring(0, tempFile.getName().length() - TEMP_FILE_EXTENSION.length()); File newFile = new File(tempFile.getParent(), newName + LOG_FILE_EXTENSION); if (!tempFile.renameTo(newFile)) { log.warn("Could not rename temp file [%s] to [%s]", tempFile, newFile); } } } private  Logging(); static synchronized Logging initialize(); synchronized void disableConsole(); @SuppressWarnings("MethodMayBeStatic") @Deprecated void logToFile(String logPath, int maxHistory, DataSize maxSize, DataSize maxTotalSize); @SuppressWarnings("MethodMayBeStatic") void logToFile(String logPath, int maxHistory, int queueSize, DataSize maxSize, DataSize maxTotalSize); @VisibleForTesting static void addLogTester(Class<?> clazz, LogTester logTester); @VisibleForTesting static void addLogTester(String name, LogTester logTester); @VisibleForTesting static void resetLogTesters(); static Appender<T> createFileAppender(String logPath, int maxHistory, DataSize maxFileSize, DataSize maxTotalSize, Encoder<T> encoder, Context context); static Appender<T> createFileAppender(String logPath, int maxHistory, int queueSize, Duration flushInterval, DataSize maxFileSize, DataSize maxTotalSize, Encoder<T> encoder, Context context); Level getRootLevel(); void setRootLevel(Level newLevel); void setLevels(File file); @SuppressWarnings("MethodMayBeStatic") Level getLevel(String loggerName); @SuppressWarnings("MethodMayBeStatic") void setLevel(String loggerName, Level level); @SuppressWarnings("MethodMayBeStatic") Map<String, Level> getAllLevels(); void setLevels(Map<String, String> properties); void configure(LoggingConfiguration config); static void addShutdownLatchToWaitFor(CountDownLatch latch); @Deprecated static void addShutdownHookToWaitFor(Thread shutdownHook); @Deprecated static void removeShutdownHookToWaitFor(Thread shutdownHook);  }
@Test public void testRecoverTempFiles() throws IOException { LoggingConfiguration configuration = new LoggingConfiguration(); configuration.setLogPath(new File(tempDir, "launcher.log").getPath()); File logFile1 = new File(tempDir, "test1.log"); Files.touch(logFile1); File logFile2 = new File(tempDir, "test2.log"); Files.touch(logFile2); File tempLogFile1 = new File(tempDir, "temp1.tmp"); Files.touch(tempLogFile1); File tempLogFile2 = new File(tempDir, "temp2.tmp"); Files.touch(tempLogFile2); Logging logging = Logging.initialize(); logging.configure(configuration); assertTrue(logFile1.exists()); assertTrue(logFile2.exists()); assertFalse(tempLogFile1.exists()); assertFalse(tempLogFile2.exists()); assertTrue(new File(tempDir, "temp1.log").exists()); assertTrue(new File(tempDir, "temp2.log").exists()); }