/ ** * * / import java.io.file; import java.io.filewriter; import java.io.ioexception; import java.text.simpledateFormat; import java.util.date; / ** * @author magic282 * * / public class Logger {private static String logfilepath; Boolean statique privé est-ce que la false; LogWriter de fichier statique privé = null; Private Static Boolean PrintlogWogwhenLog = true; private static boolean initLogger () {String logDirectoryPath = System.getProperty ("user.dir") + java.io.file.separatorchar + "log"; if (! nouveau fichier (logDirectoryPath) .exists ()) {nouveau fichier (logDirectoryPath) .mkdir (); } Date logfiledate = new Date (); SimpledateFormat DateFormat = new SimpledateFormat ("yyyy-mm-dd-hh-mm-ss"); logFilePath = logDirectoryPath + java.io.file.separatorchar + dateFormat.format (logfiledate) + ".log"; try {logWriter = new FileWriter (logFilePath, true); isInitialized = true; } catch (ioException e) {// TODO GÉNÉRATEUR AUTO GÉNÉRÉ BLOC SYSTEM.ERR.PRINTLN ("Impossible de créer un fichier journal."); System.err.println ("Initization Fail."); e.printStackTrace (); retourne false; } return true; } public static void log (String Message) {if (! isInitialized) {initLogger (); } Date logfiledate = new Date (); SimpledateFormat DateFormat = new SimpledateFormat ("yyyy-mm-dd-hh-mm-ss"); String CallingClassName = new Exception (). GetStackTrace () [1] .getClassName (); synchronisé (logWriter) {String log = string.format ("[% s] @ [% s]:% s / n", callclassname, dateformat.format (logfiledate), message); if (printLogwhenLog) {System.out.printf ("[log]:% s", log); } essayez {logwriter.write (log); logwriter.flush (); } catch (ioException e) {// TODO GÉNÉRATEUR AUTO GÉNÉRÉ BLOC SYSTÈME.ERR.PRINTLN ("Écrire le journal dans le fichier% s Erreur."); e.printStackTrace (); }}} Public static void log (exception exception) {if (! isInitialized) {initLogger (); } Date logfiledate = new Date (); SimpledateFormat DateFormat = new SimpledateFormat ("Yyyy-mm-dd-hh-mm-ss"); String CallingClassName = new Exception (). GetStackTrace () [1] .getClassName (); synchronisé (logWriter) {String log = string.format ("[% s] @ [% s]:% s / n", callclassname, dateformat.format (logfiledate), exception.tostring ()); if (printLogwhenLog) {System.out.printf ("[log]:% s", log); } essayez {logwriter.write (log); LogWriter.Flush (); } catch (ioException e) {// TODO GÉNÉRATEUR AUTO GÉNÉRÉ BLOC SYSTÈME.ERR.PRINTLN ("Écrire le journal dans le fichier% s Erreur."); e.printStackTrace (); }}}}