/*
 * Copyright 2012 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Eclipse Public License version 1.0, available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package org.jboss.aesh.util;

import org.jboss.aesh.console.settings.Settings;

import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Handler;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;

/**
 * butt ugly logger util, but its simple and gets the job done (hopefully not too dangerous)
 *
 * @author <a href="mailto:stale.pedersen@jboss.org">Ståle W. Pedersen</a>
 */
public class LoggerUtil {

    private static Handler logHandler;

    /**
     *
     * @param name class
     * @return logger
     */
    public static synchronized Logger getLogger(String name) {
        if(logHandler == null)
            try {
                logHandler = new FileHandler(Settings.getInstance().getLogFile());
                logHandler.setFormatter(new SimpleFormatter());
            }
            catch (IOException e) {
                e.printStackTrace();
            }

        Logger log =  Logger.getLogger(name);
        log.setUseParentHandlers(false);
        log.addHandler(logHandler);

        return log;
    }
}

@@ -238,27 +238,86 @@
 ole.
-settings.Settings;%0A
+Config;%0Aimport org.jboss.aesh.console.settings.Settings;%0A%0Aimport java.io.File;
 %0Aimp
@@ -917,16 +917,602 @@
   try %7B%0A
+                File logFile = new File(Settings.getInstance().getLogFile());%0A                if(!logFile.getParentFile().isDirectory()) %7B%0A                    if(!logFile.getParentFile().mkdirs()) %7B%0A                        //if creating dirs failed, just create a logger without a file handler%0A                        return Logger.getLogger(name);%0A                    %7D%0A                %7D%0A                else if(logFile.isDirectory()) %7B%0A                    Settings.getInstance().setLogFile(Settings.getInstance().getLogFile()+ Config.getPathSeparator()+%22aesh.log%22);%0A                %7D%0A
         

make sure that parent log file dir is a directory