// $Id$
/*
 * Copyright 2010 Institute for Systems Biology
 *                Seattle, Washington, USA.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package biotextEngine.util;

import java.util.logging.*;

/**
 * Set up logging to System.out using JUL.  This is barely one step removed
 * from direct System.out calls.  Sorry.
 * 
 * @author David Julian
 */
public final class Scrivener {

    private Scrivener() {
    }

    // why oh why do they spool to System.err by default
    private static final ConsoleHandler HANDLER = new ConsoleHandler() {
        {
            setOutputStream(System.out);
            setLevel(Level.ALL);
        }
    };

    /**
     * Get a {@link Logger} by class.  This just passes to {@link Scrivener#getLogger(String)}
     * passing in the value from {@link Class#getCanonicalName()}.
     * 
     * @param who The class to get a logger for
     * @return a logger for the class
     */
    public static Logger getLogger(Class<?> who) {
        return getLogger(who.getCanonicalName());
    }

    /**
     * Get a {@link Logger} by name.
     * 
     * @param name the name to use for the logger
     * @return a logger for that name
     */
    public static Logger getLogger(String name) {
        Logger logger = Logger.getLogger(name);
        logger.addHandler(HANDLER);
        logger.setUseParentHandlers(false);
        logger.setLevel(Level.ALL);
        
        return logger;
    }
}
