package org.d2c.common;

import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.SimpleFormatter;

public class Logger {

    /**
     * Text to put on the start of each line.
     */
    private final static String LOGGER_NL_TEXT = "D2C > ";

    /**
     * Log name
     */
    private static String LOG_NAME = "D2CLogger";

    /**
     * Is to print data?
     */
    private static boolean print = false;

    /**
     * Logger instance.
     */
    private static java.util.logging.Logger log = java.util.logging.Logger.getLogger(getLogName());

    private static int DEBUG_LEVEL = 0;

    /**
     * Enable file handler
     */
    public static void enableFileHandler()
    {
        FileHandler fh;
        try {
            fh = new FileHandler(getLogName(), true);
            log.addHandler(fh);
            fh.setFormatter(new SimpleFormatter());
        } catch (SecurityException e) {
            log.log(Level.SEVERE, "SecurityException", e);
        } catch (IOException e) {
            log.log(Level.SEVERE, "IOException", e);
        }
    }

    /**
     * Get the log name.
     *
     * @return
     */
    public static String getLogName()
    {
        return LOG_NAME;
    }

    /**
     * Write a new log information entry.
     *
     * @param text Log text
     */
    public static void info(String text)
    {
        if (!print) {
            return;
        }

        log.info(LOGGER_NL_TEXT + text);
    }

    public static void error(String text)
    {
        if (!print) {
            return;
        }

        log.severe(LOGGER_NL_TEXT + text);
    }

    public static void enable()
    {
        print = true;
    }

    public static void disable()
    {
        print = false;
    }

    public static void config(int debugLevel)
    {
        DEBUG_LEVEL = debugLevel;

        // Console debug enable
        if (debugLevel > 0) {
            enable();
        }

        // File handle debug enable
        if (debugLevel > 1) {
            enableFileHandler();
        }
    }

    public static int getDebugLevel()
    {
        return DEBUG_LEVEL;
    }

}

@@ -62,32 +62,58 @@
 ava.
-util.logging.FileHandler
+text.DateFormat;%0Aimport java.text.SimpleDateFormat
 ;%0Aim
@@ -131,21 +131,12 @@
 til.
-logging.Level
+Date
 ;%0Aim
@@ -158,31 +158,17 @@
 logging.
-SimpleFormatter
+*
 ;%0A%0Apubli
@@ -1717,16 +1717,239 @@
  = true;
+%0A%0A        log.setUseParentHandlers(false);%0A%0A        MyFormatter formatter = new MyFormatter();%0A        ConsoleHandler handler = new ConsoleHandler();%0A        handler.setFormatter(formatter);%0A        log.addHandler(handler);
 %0A    %7D%0A%0A
@@ -2394,10 +2394,852 @@
 %0A    %7D%0A%0A
+    static class MyFormatter extends Formatter %7B%0A        //%0A        // Create a DateFormat to format the logger timestamp.%0A        //%0A        private static final DateFormat df = new SimpleDateFormat(%22dd/MM/yyyy hh:mm:ss.SSS%22);%0A%0A        public String format(LogRecord record)%0A        %7B%0A            StringBuilder builder = new StringBuilder(1000);%0A            builder.append(df.format(new Date(record.getMillis()))).append(%22 - %22);%0A            builder.append(%22%5B%22).append(record.getLevel()).append(%22%5D - %22);%0A            builder.append(formatMessage(record));%0A            builder.append(%22%5Cn%22);%0A            return builder.toString();%0A        %7D%0A%0A        public String getHead(Handler h)%0A        %7B%0A            return super.getHead(h);%0A        %7D%0A%0A        public String getTail(Handler h)%0A        %7B%0A            return super.getTail(h);%0A        %7D%0A    %7D%0A
 %7D%0A

Improve the Logger class