Here you can find the source of log(String msg)
Parameter | Description |
---|---|
msg | The message to log. |
public static void log(String msg)
//package com.java2s; //License from project: Open Source License import java.io.*; import static javax.swing.JOptionPane.ERROR_MESSAGE; import static javax.swing.JOptionPane.showMessageDialog; public class Main { /** Writes to the log file. */ private static BufferedWriter logWriter; /** If logging has already failed, don't try again */ private static boolean loggingFailed = false; /**/*from w w w.j ava2s .c o m*/ * Writes a message to the log file. * * @param msg * The message to log. */ public static void log(String msg) { // write to the system output System.out.println(msg); // write to the log if it's available if (logWriter != null && !loggingFailed) { try { // write the line to the log and flush, so if something crashes, we gucci logWriter.write(msg); logWriter.write('\n'); logWriter.flush(); } catch (IOException e) { e.printStackTrace(); showMessageDialog(null, "Failed to write to log file!", "Logging Error", ERROR_MESSAGE); loggingFailed = true; // don't try to write next time, prevents this from happening all the time } } } }