/ ** * */ 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 ؛ isinitialized isinitialized static static = false ؛ لوجيرتر الثابتة الثابتة = فارغة ؛ printlogwhenlog الثابتة الثابتة الخاصة = صحيح ؛ private static boolean initlogger () {string logDirectoryPath = system.getProperty ("user.dir") + java.io.file.separatorch + "log" ؛ if (! ملف جديد (logDirectoryPath) .exists ()) {ملف جديد (logDirectoryPath) .mkdir () ؛ } date logfiledate = new date () ؛ SimpledAteFormat DateFormat = جديد SimplEdateFormat ("Yyyy-MM-DD-HH-MM-SS") ؛ logFilePath = logDirectoryPath + java.io.file.separatorchar + dateformat.format (logFileDate) + ".log" ؛ Try {logwriter = new filewRiter (logFilePath ، true) ؛ isinitialized = صحيح ؛ } catch (ioException e) {// todo catch catch system.err.err.println ("غير قادر على إنشاء ملف السجل.") ؛ System.Err.Println ("Fail is Fail.") ؛ E.PrintStackTrace () ؛ العودة كاذبة } إعادة صواب ؛ } سجل الفراغ الثابت العام (رسالة سلسلة) {if (! isInitizized) {initLogger () ؛ } date logfiledate = new date () ؛ SimpledAteFormat DateFormat = جديد SimplEdateFormat ("Yyyy-MM-DD-HH-MM-SS") ؛ String CallClassName = استثناء جديد (). getStackTrace () [1] .getClassName () ؛ Synchronized (logwriter) {String log = string.format ("[٪ s] @ [٪ s]: ٪ s/n" ، callingClassName ، dateFormat.format (logFileDate) ، message) ؛ if (printlogwhenlog) {system.out.printf ("[log]: ٪ s" ، log) ؛ } جرب {logwriter.write (log) ؛ logwriter.flush () ؛ } catch (ioException e) {// todo acto catch block system.err.println ("اكتب سجل إلى file ٪ s.") ؛ E.PrintStackTrace () ؛ }}} سجل الفراغ الثابت العام (استثناء استثناء) {if (! isInitialized) {initLogger () ؛ } date logfiledate = new date () ؛ SimpledAteFormat DateFormat = جديد SimplEdateFormat ("Yyyy-MM-DD-HH-MM-SS") ؛ String CallClassName = استثناء جديد (). getStackTrace () [1] .getClassName () ؛ Synchronized (logwriter) {String log = string.format ("[٪ s] @ [٪ s]: ٪ s/n" ، callclassname ، dateFormat.format (logFileDate) ، issection.toString ()) ؛ if (printlogwhenlog) {system.out.printf ("[log]: ٪ s" ، log) ؛ } جرب {logwriter.write (log) ؛ logwriter.flush () ؛ } catch (ioException e) {// todo catch catch system.err.errintln ("اكتب سجل إلى file ٪ s.") ؛ E.PrintStackTrace () ؛ }}}}