package art.servers.log; import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.StringWriter; import java.util.Date; public class LogVMS { BufferedWriter out = null; private static java.text.SimpleDateFormat _sdf = new java.text.SimpleDateFormat("dd/MM/yyyy HH:mm:ss.SSS"); private static java.text.SimpleDateFormat formato1 = new java.text.SimpleDateFormat("dd-MM-yyyy"); private static java.text.SimpleDateFormat formato2 = new java.text.SimpleDateFormat("HH-mm-ss"); public LogVMS (String identifier) { crear(identifier); } public void escribir (String mens) { try { out.write(_sdf.format(new java.util.Date()) + " - " + mens); out.newLine(); out.flush(); } catch (Exception e) { } } public void escribir (String mens, Exception exception) { try { StringWriter sw = new StringWriter(); exception.printStackTrace(new PrintWriter(sw)); out.write(_sdf.format(new java.util.Date()) + " - " + mens); out.write(_sdf.format(new java.util.Date()) + " - " + exception.getMessage()); out.write(_sdf.format(new java.util.Date()) + " - " + sw.toString()); out.newLine(); out.flush(); } catch (Exception e) { } } private void crear (String identifier) { try { Date date = new Date(); try{out.close();} catch (Exception e){}; try{out = null;} catch (Exception e){}; String carpeta = "vms/Logs/" + identifier; File file = new File(carpeta); file.mkdirs(); String carpeta2 = "vms/Logs/" + identifier + "/" + formato1.format(date); File file2 = new File(carpeta2); file2.mkdirs(); String nombre = carpeta2 + "/" + formato2.format(date) + ".dat"; out = new BufferedWriter ( new OutputStreamWriter ( new FileOutputStream (nombre))); } catch (Exception e) { } } }