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/CloseableThreadContext.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; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; /** * Adds entries to the {@link ThreadContext stack or map} and them removes them when the object is closed, e.g. as part * of a try-with-resources. User code can now look like this: * <pre> * try (final CloseableThreadContext.Instance ignored = CloseableThreadContext.put(key1, value1).put(key2, value2)) { * callSomeMethodThatLogsALot(); * * // Entries for key1 and key2 are automatically removed from the ThreadContext map when done. * } * </pre> * * @since 2.6 */ public class CloseableThreadContext { private CloseableThreadContext() { } /** * Pushes new diagnostic context information on to the Thread Context Stack. The information will be popped off when * the instance is closed. * * @param message The new diagnostic context information. * @return a new instance that will back out the changes when closed. */ public static CloseableThreadContext.Instance push(final String message) { return new CloseableThreadContext.Instance().push(message); } /** * Pushes new diagnostic context information on to the Thread Context Stack. The information will be popped off when * the instance is closed. * * @param message The new diagnostic context information. * @param args Parameters for the message. * @return a new instance that will back out the changes when closed. */ public static CloseableThreadContext.Instance push(final String message, final Object... args) { return new CloseableThreadContext.Instance().push(message, args); } /** * Populates the Thread Context Map with the supplied key/value pair. Any existing key in the * {@link ThreadContext} will be replaced with the supplied value, and restored back to their original value when * the instance is closed. * * @param key The key to be added * @param value The value to be added * @return a new instance that will back out the changes when closed. */ public static CloseableThreadContext.Instance put(final String key, final String value) { return new CloseableThreadContext.Instance().put(key, value); } /** * Populates the Thread Context Stack with the supplied stack. The information will be popped off when * the instance is closed. * * @param messages The list of messages to be added * @return a new instance that will back out the changes when closed. * @since 2.8 */ public static CloseableThreadContext.Instance pushAll(final List<String> messages) { return new CloseableThreadContext.Instance().pushAll(messages); } /** * Populates the Thread Context Map with the supplied key/value pairs. Any existing keys in the * {@link ThreadContext} will be replaced with the supplied values, and restored back to their original value when * the instance is closed. * * @param values The map of key/value pairs to be added * @return a new instance that will back out the changes when closed. * @since 2.8 */ public static CloseableThreadContext.Instance putAll(final Map<String, String> values) { return new CloseableThreadContext.Instance().putAll(values); } public static class Instance implements AutoCloseable { private int pushCount = 0; private final Map<String, String> originalValues = new HashMap<>(); private Instance() { } /** * Pushes new diagnostic context information on to the Thread Context Stack. The information will be popped off when * the instance is closed. * * @param message The new diagnostic context information. * @return the instance that will back out the changes when closed. */ public Instance push(final String message) { ThreadContext.push(message); pushCount++; return this; } /** * Pushes new diagnostic context information on to the Thread Context Stack. The information will be popped off when * the instance is closed. * * @param message The new diagnostic context information. * @param args Parameters for the message. * @return the instance that will back out the changes when closed. */ public Instance push(final String message, final Object[] args) { ThreadContext.push(message, args); pushCount++; return this; } /** * Populates the Thread Context Map with the supplied key/value pair. Any existing key in the * {@link ThreadContext} will be replaced with the supplied value, and restored back to their original value when * the instance is closed. * * @param key The key to be added * @param value The value to be added * @return a new instance that will back out the changes when closed. */ public Instance put(final String key, final String value) { // If there are no existing values, a null will be stored as an old value if (!originalValues.containsKey(key)) { originalValues.put(key, ThreadContext.get(key)); } ThreadContext.put(key, value); return this; } /** * Populates the Thread Context Map with the supplied key/value pairs. Any existing keys in the * {@link ThreadContext} will be replaced with the supplied values, and restored back to their original value when * the instance is closed. * * @param values The map of key/value pairs to be added * @return a new instance that will back out the changes when closed. * @since 2.8 */ public Instance putAll(final Map<String, String> values) { final Map<String, String> currentValues = ThreadContext.getContext(); ThreadContext.putAll(values); for (final String key : values.keySet()) { if (!originalValues.containsKey(key)) { originalValues.put(key, currentValues.get(key)); } } return this; } /** * Populates the Thread Context Stack with the supplied stack. The information will be popped off when * the instance is closed. * * @param messages The list of messages to be added * @return a new instance that will back out the changes when closed. * @since 2.8 */ public Instance pushAll(final List<String> messages) { for (final String message : messages) { push(message); } return this; } /** * Removes the values from the {@link ThreadContext}. * <p> * Values pushed to the {@link ThreadContext} <em>stack</em> will be popped off. * </p> * <p> * Values put on the {@link ThreadContext} <em>map</em> will be removed, or restored to their original values it they already existed. * </p> */ @Override public void close() { closeStack(); closeMap(); } private void closeMap() { for (final Iterator<Map.Entry<String, String>> it = originalValues.entrySet().iterator(); it.hasNext(); ) { final Map.Entry<String, String> entry = it.next(); final String key = entry.getKey(); final String originalValue = entry.getValue(); if (null == originalValue) { ThreadContext.remove(key); } else { ThreadContext.put(key, originalValue); } it.remove(); } } private void closeStack() { for (int i = 0; i < pushCount; i++) { ThreadContext.pop(); } pushCount = 0; } } }
⏎ org/apache/logging/log4j/CloseableThreadContext.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, 23409👍, 0💬
Popular Posts:
Jakarta Regexp is a 100% Pure Java Regular Expression package that was graciously donated to the Apa...
What Is jsse.jar (JDK 6) Java Secure Socket Extension? jsse.jar, Java Secure Socket Extension, is Ja...
Swingx is the SwingLabs Swing Component Extensions. JAR File Size and Download Location: File name: ...
Xalan-Java, Version 2.7.1, is an XSLT processor for transforming XML documents into HTML, text, or o...
JDK 11 jdk.jlink.jmod is the JMOD file for JDK 11 JLink tool, which can be invoked by the "jlink" co...