package io.keen.client.java;

import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
import java.util.logging.StreamHandler;

/**
 * KeenLogging is a wrapper around a logging module and provides, well, logging for the Keen Java SDK.
 * Logging is disabled by default so as not to clutter up your development experience.
 *
 * @author dkador
 * @since 1.0.0
 */
public class KeenLogging {

    private static final Logger LOGGER;
    private static final StreamHandler HANDLER;

    static {
        LOGGER = Logger.getLogger(KeenLogging.class.getName());
        HANDLER = new StreamHandler(System.out, new SimpleFormatter());
        LOGGER.addHandler(HANDLER);
        disableLogging();
    }

    static void log(String msg) {
        if (isLoggingEnabled()) {
            LOGGER.log(Level.FINER, msg);
            HANDLER.flush();
        }
    }

    /**
     * Call this to enable logging.
     */
    public static void enableLogging() {
        setLogLevel(Level.FINER);
    }

    /**
     * Call this to disable logging.
     */
    public static void disableLogging() {
        setLogLevel(Level.OFF);
    }

    /**
     * Whether or not logging is enabled.
     *
     * @return a boolean saying whether or not logging is enabled
    */
    public static boolean isLoggingEnabled() {
        return LOGGER.getLevel() == Level.FINER;
    }

    private static void setLogLevel(Level newLevel) {
        LOGGER.setLevel(newLevel);
        for (Handler handler : LOGGER.getHandlers()) {
            handler.setLevel(newLevel);
        }
    }
}

@@ -1189,32 +1189,333 @@
 evel.OFF);%0A    %7D
+%0A    %0A    /**%0A     * Disable the default log handler installed by the Keen Client to allow %0A     * log management by standard j.u.l mechanisms.%0A     */%0A    public static void disableDefaultLogHandler()%7B%0A    %09LOGGER.removeHandler(HANDLER);%09//returns silently if given handler is null or not found%0A    %7D
 %0A%0A    /**%0A     *

Add public method to disable the default log handler installed by the Keen SDK. This method can be called by applications which wish to more closely manage log output.