package org.postgresql;

import java.io.*;

public final class Log {

    private static PrintWriter getWriter() throws IOException {
        String logFile = System.getProperty("java.io.tmpdir") +
            File.separator + "pgsql-jdbc.log";

        return new PrintWriter(new FileWriter(logFile, true));
    }

    public synchronized static void log(String msg) {
        try {
            PrintWriter pw = Log.getWriter();
            pw.println(msg);
            pw.close();
        } catch (IOException ex) {
            ex.printStackTrace();
            throw new RuntimeException(ex.getMessage());
        }

    }

    public synchronized static void log(String msg, Throwable throwable) {
        try {
            PrintWriter pw = Log.getWriter();
            pw.println(msg);
            throwable.printStackTrace(pw);
            pw.close();
        } catch (IOException ex) {
            ex.printStackTrace();
            throw new RuntimeException(ex.getMessage());
        }

    }
}
