static Lock appendToFile_lock = lock(); sbool appendToFile_keepOpen; static new HashMap appendToFile_writers; static void appendToFile(S path, S s) ctex { lock appendToFile_lock; // Let's just generally synchronize this to be safe. mkdirsForFile(new File(path)); path = getCanonicalPath(path); Writer writer = appendToFile_writers.get(path); if (writer == null) { //print("[Logging to " + path + "]"); writer = new BufferedWriter(new OutputStreamWriter( newFileOutputStream(path, true), "UTF-8")); if (appendToFile_keepOpen) appendToFile_writers.put(path, writer); } writer.write(s); if (!appendToFile_keepOpen) writer.close(); } static void appendToFile(File path, String s) { if (path != null) appendToFile(path.getPath(), s); } svoid cleanMeUp_appendToFile { temp tempCleaningUp(); lock appendToFile_lock; closeAllWriters(values(appendToFile_writers)); appendToFile_writers.clear(); }