001/**
002 * Copyright 2010-2014 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.common.util.log;
017
018import static java.lang.String.format;
019
020import org.slf4j.Logger;
021import org.slf4j.LoggerFactory;
022
023public class Loggers {
024
025        /**
026         * <p>
027         * Convenience method for issuing richly formatted INFO log messages
028         * </p>
029         */
030        public static void info(Logger logger, String msg, Object... args) {
031                logger.info((args == null || args.length == 0) ? msg : format(msg, args));
032        }
033
034        /**
035         * <p>
036         * Convenience method for obtaining a logger (borrowed from the JBoss crew)
037         * </p>
038         * 
039         * <pre>
040         * private static final Logger logger = Loggers.newLogger();
041         * </pre>
042         */
043        public static Logger newLogger() {
044                Throwable throwable = new Throwable();
045                StackTraceElement[] elements = throwable.getStackTrace();
046                StackTraceElement directCaller = elements[1];
047                return LoggerFactory.getLogger(directCaller.getClassName());
048        }
049
050        /**
051         * <p>
052         * Convenience method for obtaining a logger (borrowed from the JBoss crew)
053         * </p>
054         * 
055         * <pre>
056         * private static final Logger logger = Loggers.make();
057         * </pre>
058         * 
059         * @deprecated Use newLogger() instead
060         */
061        @Deprecated
062        public static Logger make() {
063                Throwable throwable = new Throwable();
064                StackTraceElement[] elements = throwable.getStackTrace();
065                StackTraceElement directCaller = elements[1];
066                return LoggerFactory.getLogger(directCaller.getClassName());
067        }
068
069}