All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.logging.log4j.util.Constants Maven / Gradle / Ivy

The newest version!
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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 org.apache.logging.log4j.util;

/**
 * Log4j API Constants.
 *
 * @since 2.6.2
 */
public final class Constants {
    /**
     * {@code true} if we think we are running in a web container, based on the boolean value of system property
     * "log4j2.is.webapp", or (if this system property is not set) whether the  {@code javax.servlet.Servlet} class
     * is present in the classpath.
     */
    public static final boolean IS_WEB_APP = PropertiesUtil.getProperties().getBooleanProperty(
            "log4j2.is.webapp", isClassAvailable("javax.servlet.Servlet"));

    /**
     * Kill switch for object pooling in ThreadLocals that enables much of the LOG4J2-1270 no-GC behaviour.
     * 

* {@code True} for non-{@link #IS_WEB_APP web apps}, disable by setting system property * "log4j2.enable.threadlocals" to "false". */ public static final boolean ENABLE_THREADLOCALS = !IS_WEB_APP && PropertiesUtil.getProperties().getBooleanProperty( "log4j2.enable.threadlocals", true); /** * Determines if a named Class can be loaded or not. * * @param className The class name. * @return {@code true} if the class could be found or {@code false} otherwise. */ private static boolean isClassAvailable(final String className) { try { return LoaderUtil.loadClass(className) != null; } catch (final Throwable e) { return false; } } /** * Prevent class instantiation. */ private Constants() { } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy