All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pacman.game.util.Log Maven / Gradle / Ivy

There is a newer version: 2.0.1.0
Show newest version
package pacman.game.util;

import java.util.Date;

public class Log {
    private static String fileName;
    private static Log log = null;
    private StringBuilder msg;
    private boolean timeStamp, console;

    private Log() {
        msg = new StringBuilder();

        fileName = "log.txt";
        timeStamp = false;
        console = false;
    }

    public static Log getLog() {
        if (log == null)
            log = new Log();

        return log;
    }

    public void enableConsolePrinting() {
        console = true;
    }

    public void disableConsolePrinting() {
        console = false;
    }

    public void setFile(String fileName) {
        Log.fileName = fileName;
    }

    public void enableTimeStamp() {
        timeStamp = true;
    }

    public void disableTimeStamp() {
        timeStamp = false;
    }

    public void log(Object context, String message) {
        if (timeStamp) {
            String string = "[" + new Date().toString() + "; " + context.getClass().toString() + "]\t" + message;

            msg.append(string);

            if (console)
                System.out.println(string);
        } else {
            String string = "[" + context.getClass().toString() + "]\t" + message;

            msg.append(string);

            if (console)
                System.out.println(string);
        }
    }

    public void clear() {
        msg = new StringBuilder();
    }

    public void saveLog(boolean append) {
        IO.saveFile(fileName, msg.toString(), append);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy