Source Code for Apache Log4j Core Implementation

Apache Log4j Core Implementation provides the functional components of the logging system. Users are free to create their own plugins and include them in the logging configuration. Apache Log4j Core is a required module to use Apache Log4j.

Bytecode (Java 8) for Apache Log4j Core Implementation is provided in a separate JAR file like log4j-core-2.14.1.jar.

Source Code files for Apache Log4j API are provided in both binary packge like and source package like You can download them at Apache Log4j Website.

You can also browse Source Code files for Apache Log4j Core Implementation 2.14.1 below.



 * 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
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * See the license for the specific language governing permissions and
 * limitations under the license.

import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;

 * PasswordProvider that reads password from a file.
 * <p>
 * This is a relatively secure way to handle passwords:
 * <ul>
 *     <li>Managing file access privileges can be delegated to the operating system.</li>
 *     <li>The password file can be in a separate location from the logging configuration.
 *       This gives flexibility to have different passwords in different environments while
 *       using the same logging configuration. It also allows for separation of responsibilities:
 *       developers don't need to know the password that is used in the production environment.</li>
 *     <li>There is only a small window of opportunity for attackers to obtain the password from a memory
 *       dump: the password data is only resident in memory from the moment the caller calls the
 *       {@link #getPassword()} method and the password file is read until the moment that the caller
 *       completes authentication and overwrites the password char[] array.</li>
 * </ul>
 * </p><p>
 * Less secure implementations are {@link MemoryPasswordProvider} and {@link EnvironmentPasswordProvider}.
 * </p>
class FilePasswordProvider implements PasswordProvider {
    private final Path passwordPath;

     * Constructs a new FilePasswordProvider with the specified path.
     * @param passwordFile the path to the password file
     * @throws NoSuchFileException if the password file does not exist when this FilePasswordProvider is constructed
    public FilePasswordProvider(final String passwordFile) throws NoSuchFileException {
        this.passwordPath = Paths.get(passwordFile);
        if (!Files.exists(passwordPath)) {
            throw new NoSuchFileException("PasswordFile '" + passwordFile + "' does not exist");

    public char[] getPassword() {
        byte[] bytes = null;
        try {
            bytes = Files.readAllBytes(passwordPath);
            final ByteBuffer bb = ByteBuffer.wrap(bytes);
            final CharBuffer decoded = Charset.defaultCharset().decode(bb);
            final char[] result = new char[decoded.limit()];
            decoded.get(result, 0, result.length);
            decoded.put(new char[result.length]); // erase decoded CharBuffer
            return result;
        } catch (final IOException e) {
            throw new IllegalStateException("Could not read password from " + passwordPath + ": " + e, e);
        } finally {
            if (bytes != null) {
                Arrays.fill(bytes, (byte) 0x0);



Or download all of them as a single archive file:

File name: log4j-core-2.14.1-sources.jar
File size: 1281358 bytes
Release date: 2021-03-06


Source Code for Apache Log4j JDK Logging Adapter

Source Code for Apache Log4j API

Downloading and Reviewing Apache Log4j Packages

⇑⇑ FAQ for Apache Log4j

2015-11-03, 92349👍, 0💬