Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (101)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (309)
Collections:
Other Resources:
Source Code for Apache Log4j API
Apache Log4j API
provides the interface that applications should code to and provides the adapter
components required for implementers to create a logging implementation.
Apache Log4j API is a required module to use Apache Log4j.
Bytecode (Java 8) for Apache Log4j API is provided in a separate JAR file like log4j-api-2.14.1.jar.
Source Code files for Apache Log4j API are provided in both binary packge like apache-log4j-2.14.1-bin.zip and source package like apache-log4j-2.14.1-src.zip. You can download them at Apache Log4j Website.
You can also browse Source Code files for Apache Log4j API 2.14.1 below.
✍: FYIcenter.com
⏎ org/apache/logging/log4j/util/ProviderUtil.java
/* * 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; import java.io.IOException; import java.net.URL; import java.util.Collection; import java.util.Enumeration; import java.util.HashSet; import java.util.Properties; import java.util.ServiceLoader; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.spi.Provider; import org.apache.logging.log4j.status.StatusLogger; /** * <em>Consider this class private.</em> Utility class for Log4j {@link Provider}s. When integrating with an application * container framework, any Log4j Providers not accessible through standard classpath scanning should * {@link #loadProvider(java.net.URL, ClassLoader)} a classpath accordingly. */ public final class ProviderUtil { /** * Resource name for a Log4j 2 provider properties file. */ protected static final String PROVIDER_RESOURCE = "META-INF/log4j-provider.properties"; /** * Loaded providers. */ protected static final Collection<Provider> PROVIDERS = new HashSet<>(); /** * Guards the ProviderUtil singleton instance from lazy initialization. This is primarily used for OSGi support. * * @since 2.1 */ protected static final Lock STARTUP_LOCK = new ReentrantLock(); private static final String API_VERSION = "Log4jAPIVersion"; private static final String[] COMPATIBLE_API_VERSIONS = {"2.6.0"}; private static final Logger LOGGER = StatusLogger.getLogger(); // STARTUP_LOCK guards INSTANCE for lazy initialization; this allows the OSGi Activator to pause the startup and // wait for a Provider to be installed. See LOG4J2-373 private static volatile ProviderUtil instance; private ProviderUtil() { for (final ClassLoader classLoader : LoaderUtil.getClassLoaders()) { try { loadProviders(classLoader); } catch (final Throwable ex) { LOGGER.debug("Unable to retrieve provider from ClassLoader {}", classLoader, ex); } } for (final LoaderUtil.UrlResource resource : LoaderUtil.findUrlResources(PROVIDER_RESOURCE)) { loadProvider(resource.getUrl(), resource.getClassLoader()); } } protected static void addProvider(final Provider provider) { PROVIDERS.add(provider); LOGGER.debug("Loaded Provider {}", provider); } /** * Loads an individual Provider implementation. This method is really only useful for the OSGi bundle activator and * this class itself. * * @param url the URL to the provider properties file * @param cl the ClassLoader to load the provider classes with */ protected static void loadProvider(final URL url, final ClassLoader cl) { try { final Properties props = PropertiesUtil.loadClose(url.openStream(), url); if (validVersion(props.getProperty(API_VERSION))) { final Provider provider = new Provider(props, url, cl); PROVIDERS.add(provider); LOGGER.debug("Loaded Provider {}", provider); } } catch (final IOException e) { LOGGER.error("Unable to open {}", url, e); } } /** * * @param classLoader null can be used to mark the bootstrap class loader. */ protected static void loadProviders(final ClassLoader classLoader) { final ServiceLoader<Provider> serviceLoader = ServiceLoader.load(Provider.class, classLoader); for (final Provider provider : serviceLoader) { if (validVersion(provider.getVersions()) && !PROVIDERS.contains(provider)) { PROVIDERS.add(provider); } } } /** * @deprecated Use {@link #loadProvider(java.net.URL, ClassLoader)} instead. Will be removed in 3.0. */ @Deprecated protected static void loadProviders(final Enumeration<URL> urls, final ClassLoader cl) { if (urls != null) { while (urls.hasMoreElements()) { loadProvider(urls.nextElement(), cl); } } } public static Iterable<Provider> getProviders() { lazyInit(); return PROVIDERS; } public static boolean hasProviders() { lazyInit(); return !PROVIDERS.isEmpty(); } /** * Lazily initializes the ProviderUtil singleton. * * @since 2.1 */ protected static void lazyInit() { // noinspection DoubleCheckedLocking if (instance == null) { try { STARTUP_LOCK.lockInterruptibly(); try { if (instance == null) { instance = new ProviderUtil(); } } finally { STARTUP_LOCK.unlock(); } } catch (final InterruptedException e) { LOGGER.fatal("Interrupted before Log4j Providers could be loaded.", e); Thread.currentThread().interrupt(); } } } public static ClassLoader findClassLoader() { return LoaderUtil.getThreadContextClassLoader(); } private static boolean validVersion(final String version) { for (final String v : COMPATIBLE_API_VERSIONS) { if (version.startsWith(v)) { return true; } } return false; } }
⏎ org/apache/logging/log4j/util/ProviderUtil.java
Or download all of them as a single archive file:
File name: log4j-api-2.14.1-sources.jar File size: 264773 bytes Release date: 2021-03-06 Download
⇒ Source Code for Apache Log4j Core Implementation
⇐ Downloading Apache Log4j Binary Package
2015-11-17, 23366👍, 0💬
Popular Posts:
What is the sax\Writer.java provided in the Apache Xerces package? I have Apache Xerces 2.11.0 insta...
What Is HttpComponents httpcore-4.4.6.jar? HttpComponents httpcore-4.4.6.jar is the JAR file for Apa...
JRE 8 rt.jar is the JAR file for JRE 8 RT (Runtime) libraries. JRE (Java Runtime) 8 is the runtime e...
Java Cryptography Extension 1.2.2 JAR File Size and Download Location: File name: jce.jar, jce-1.2.2...
JDK 11 java.compiler.jmod is the JMOD file for JDK 11 Compiler module. JDK 11 Compiler module compil...