Java slf4j Logger getClassLogger()

Here you can find the source of getClassLogger()

Description

Returns a logger for the calling class or context.

License

Apache License

Return

a logger for the current scope

Declaration

public static Logger getClassLogger() 

Method Source Code


//package com.java2s;
/*//from   w w w  .j a  v  a  2 s. c  o  m
 * Copyright (C) 2012 Facebook, Inc.
 *
 * 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.
 */

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Main {
    /**
     * Returns a logger for the calling class or context.
     * <p/>
     * The fully-qualified name of that class is used to get an slf4j logger, which is then wrapped.
     * Typical usage is to use this method to initialize a static member variable, e.g.,
     * {@code private static final Logger LOG = LoggingUtil.getClassLogger();}
     * <p/>
     * As getStackTrace() isn't super cheap, this is not the sort of thing you want (or need)
     * to be doing hundreds of times a second;
     *
     * @return a logger for the current scope
     */
    public static Logger getClassLogger() {
        StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
        StackTraceElement element = stacktrace[2];
        String name = element.getClassName();

        return LoggerFactory.getLogger(name);
    }
}

Related

  1. findMarker(Marker marker, String name)
  2. format(final String pattern, final @Nullable Object... arguments)
  3. format(String format, Object... args)
  4. format(String messagePattern, Object... args)
  5. get(Class clazz)
  6. getErrorMsg(String format, Object[] argArray)
  7. getIntValue(String strVal, int defVal)
  8. getLog(Class clazz)
  9. getLogger()