LogFileDb { public static boolean nowLoggingTo(String filename) { if (filename.contains("\n")) { throw new IllegalArgumentException("Cannot use filename with newline: "+filename); } long s = System.currentTimeMillis() / 1000; String meta = "" + s + " " + filename + "\n"; byte[] data = meta.getBytes(UTF_8); try (OutputStream out = metaFile()) { out.write(data); } catch (java.io.IOException e) { System.err.println("Saving meta-data about logfile "+filename+" failed: "+e); return false; } return true; }  static boolean nowLoggingTo(String filename);  }
@Test public void canSave() { System.err.println("VH: "+System.getenv("VESPA_HOME")); File dir = new File(getDefaults().underVespaHome(LogFileDb.DBDIR)); assertTrue(!dir.exists() || IOUtils.recursiveDeleteDir(dir)); System.err.println("using directory: "+dir); File extraDir = new File(getDefaults().underVespaHome("logs/extra")); assertTrue(!extraDir.exists() || IOUtils.recursiveDeleteDir(extraDir)); String fn = getDefaults().underVespaHome("logs/extra/foo-bar.log"); assertTrue(LogFileDb.nowLoggingTo(fn)); fn = getDefaults().underVespaHome("logs/extra/stamped-1.log"); assertTrue(LogFileDb.nowLoggingTo(fn)); }