Java JOptionPane Message log(String msg)

Here you can find the source of log(String msg)

Description

Writes a message to the log file.

License

Open Source License

Parameter

Parameter Description
msg The message to log.

Declaration

public static void log(String msg) 

Method Source Code


//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
            }
        }
    }
}

Related

  1. getUserInputString(String message)
  2. globalMessagebox(String body, String title, int icon)
  3. input(Component comp, String title, String message, Object def)
  4. input(String message, String title)
  5. inputMessage(String str1)
  6. message(Component comp, String title, String message)
  7. message(String s)
  8. message(String s)
  9. messageBox(String s)