Skip to content

Add JPL to Log4j API bridge #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 86 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
fc41e53
Make new home for Log4j2
rgoers Feb 6, 2012
d06f0a7
LOG4J2-1360 - Add support for Platform Logger
rgoers Apr 6, 2020
918ca91
Set pom to correct parent version
rgoers Apr 12, 2020
0dfd3d5
[maven-release-plugin] prepare release log4j-2.13.2-rc1
rgoers Apr 21, 2020
0fe5015
[maven-release-plugin] prepare for next development iteration
rgoers Apr 21, 2020
bae0d92
[maven-release-plugin] prepare release log4j-2.13.3-rc1
rgoers May 10, 2020
13c91d6
[maven-release-plugin] prepare for next development iteration
rgoers May 10, 2020
ea304ce
[LOG4J2-2844] Null pointer exception when no network interfaces are
May 13, 2020
07d9475
#335 Initial import of JsonTemplateLayout from LogstashLayout.
vy Aug 19, 2020
59926f0
[LOG4J2-2653] Add initial JUnit 5 support
jvz Aug 2, 2020
31a62d6
[LOG4J2-2653] Simplify JUnit dependencies
jvz Aug 2, 2020
d0da8ca
Only generate doap file in parent project
rgoers Nov 3, 2020
dfbc43d
[maven-release-plugin] prepare release log4j-2.14.0-rc1
rgoers Nov 6, 2020
af5691d
[maven-release-plugin] prepare for next development iteration
rgoers Nov 6, 2020
7f36751
[maven-release-plugin] prepare release log4j-2.14.1-rc1
rgoers Mar 7, 2021
7079d44
[maven-release-plugin] prepare for next development iteration
rgoers Mar 7, 2021
e756493
LOG4J2-2940: Context selectors are aware of ClassLoader dependency
carterkozak Mar 16, 2021
94dbcf6
Upgrade from hamcrest-all:1.3 to hamcrest:2.2.
vy Oct 24, 2021
9755205
[maven-release-plugin] prepare release log4j-2.15.0-rc1
rgoers Dec 6, 2021
6e04e5f
[maven-release-plugin] prepare for next development iteration
rgoers Dec 6, 2021
e3e1b7a
[maven-release-plugin] prepare release log4j-2.15.0-rc2
rgoers Dec 9, 2021
f591a50
[maven-release-plugin] prepare for next development iteration
rgoers Dec 9, 2021
4cd88a3
Update maven-toolchains-plugin to 3.0.0
jvz Dec 12, 2021
6674333
[maven-release-plugin] prepare release log4j-2.15.1-rc1
jvz Dec 12, 2021
dfa31dd
[maven-release-plugin] prepare for next development iteration
jvz Dec 12, 2021
fa03889
[maven-release-plugin] prepare release log4j-2.16.0-rc1
jvz Dec 13, 2021
696cb4a
[maven-release-plugin] prepare for next development iteration
jvz Dec 13, 2021
d17029d
[maven-release-plugin] prepare release log4j-2.17.0-rc1
rgoers Dec 18, 2021
3033911
[maven-release-plugin] prepare for next development iteration
rgoers Dec 18, 2021
a2c09bd
[maven-release-plugin] prepare release log4j-2.17.1-rc1
jvz Dec 27, 2021
2f36d01
[maven-release-plugin] prepare for next development iteration
jvz Dec 27, 2021
f8c2063
LOG4J2-3345: log4j-jpl formats messages correctly using MessageFormat…
carterkozak Jan 18, 2022
74736ec
Clean up pom.xml files
jvz Jan 22, 2022
170de47
[maven-release-plugin] prepare release log4j-2.17.2-rc1
rgoers Feb 23, 2022
f7a7def
[maven-release-plugin] prepare for next development iteration
rgoers Feb 23, 2022
d9c1867
Bump surefire.plugin.version from 3.0.0-M5 to 3.0.0-M6
dependabot[bot] May 28, 2022
33896f2
Keep `log4j-jpl` at Surefire version 2.13
ppkarwasz May 28, 2022
1ac09a8
[maven-release-plugin] prepare release log4j-2.18.0-rc1
rgoers Jun 28, 2022
934b8ad
[maven-release-plugin] prepare for next development iteration
rgoers Jun 28, 2022
254662b
Use `junit-bom`
ppkarwasz Sep 6, 2022
bbf5a6a
[maven-release-plugin] prepare release log4j-2.19.0-rc1
rgoers Sep 9, 2022
8b3ac01
[maven-release-plugin] prepare for next development iteration
rgoers Sep 9, 2022
ee4a25f
[maven-release-plugin] prepare release log4j-2.19.0-rc1
rgoers Sep 9, 2022
02ddf84
[maven-release-plugin] prepare for next development iteration
rgoers Sep 9, 2022
0190401
[maven-release-plugin] prepare release log4j-2.19.0-rc2
rgoers Sep 13, 2022
bcd0899
[maven-release-plugin] prepare for next development iteration
rgoers Sep 13, 2022
da160e7
Fix new snapshot version
ppkarwasz Sep 16, 2022
1a26981
Sort dependencies in POMs
ppkarwasz Sep 18, 2022
04a995d
Move additional `log4j-core-test` classes to `main`
ppkarwasz Sep 25, 2022
eb8de48
Move exported test classes under `org.apache.logging.log4j.core.test`
ppkarwasz Sep 25, 2022
9b0d09c
Delegates plugin versions to ASF parent
ppkarwasz Sep 18, 2022
26d0d3b
Centralize plugin versions in main POM
ppkarwasz Oct 2, 2022
77733aa
Remove no-op plugin execution
ppkarwasz Oct 18, 2022
14fc114
LOG4J2-3628 Replace `maven-changes-plugin` with `log4j-changelog` (#1…
vy Jan 13, 2023
05d0553
Simplify site generation (#1166)
vy Jan 16, 2023
b08746c
Fix Javadoc generation and links for the site
vy Feb 12, 2023
5934125
Remove Maven `<reporting>` blocks, since reporting is disabled
vy Feb 14, 2023
66d76d6
[maven-release-plugin] prepare release log4j-2.20.1-rc1
rgoers Feb 18, 2023
9dad770
[maven-release-plugin] prepare for next development iteration
rgoers Feb 18, 2023
b5e6665
[maven-release-plugin] prepare release log4j-2.20.1-rc1
rgoers Feb 18, 2023
0fda3a0
Revert version update
rgoers Feb 18, 2023
9344b43
[maven-release-plugin] prepare release log4j-2.20.0-rc1
rgoers Feb 18, 2023
e547426
[maven-release-plugin] prepare for next development iteration
rgoers Feb 18, 2023
458a992
[maven-release-plugin] rollback the release of log4j-2.20.0-rc1
rgoers Feb 18, 2023
a4b5b7b
[maven-release-plugin] prepare release log4j-2.20.0-rc1
rgoers Feb 18, 2023
069a812
[maven-release-plugin] prepare for next development iteration
rgoers Feb 18, 2023
bc7bca8
Sort POMs
ppkarwasz Mar 4, 2023
579b240
Apply Spotless to all files
Apr 25, 2023
2b47351
Use `final` whenever possible
Jun 4, 2023
cdb9214
Switch build to JDK 11
ppkarwasz Feb 27, 2023
2bac18a
Bump version to 2.21.0-SNAPSHOT
ppkarwasz Sep 20, 2023
0ba29a7
Remove references to `maven-bundle-plugin`
ppkarwasz Sep 25, 2023
c9d8326
Replace explicit versions with property
ppkarwasz Sep 26, 2023
cb81750
Add BND configuration to bridges
ppkarwasz Sep 29, 2023
d6a94fd
Migrate changelog, site, and docs to the new infra
vy Oct 5, 2023
bcd3023
Automatically enable Java 8 tests on the CI
ppkarwasz Oct 4, 2023
59eee05
Swap `/pom.xml` and `/log4j-bom/pom.xml`
vy Oct 5, 2023
5bd6a0a
Remove `log4j-core` from some processor paths
ppkarwasz Oct 6, 2023
ba051b7
Add `log4j-core` to some modules processor path
ppkarwasz Oct 6, 2023
3abb1f3
Add OSGi package versioning and fix API breaking changes
ppkarwasz Oct 8, 2023
2cd7fdc
Apply Palantir formatter
vy Nov 16, 2023
a5ee7e6
Adds `useModulePath=false` to `log4j-jpl`
ppkarwasz Dec 21, 2023
77cf1a8
Fix JDK used in CI tests
ppkarwasz Dec 19, 2023
98d3cab
Migrate `log4j-jpl` tests to JUnit 5 (#3029)
ninetteadhikari Sep 27, 2024
940297f
Rename `log4j-jpl` to `jpl-to-log4j-api`
ppkarwasz Nov 6, 2024
465f828
Fix build
ppkarwasz Nov 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions jpl-to-log4j-api/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jdk-parent</artifactId>
<version>${revision}</version>
<relativePath>../parent</relativePath>
</parent>

<artifactId>jpl-to-log4j-api</artifactId>
<name>JPL to Log4j API logging bridge</name>
<description>The Apache Log4j implementation of java.lang.System.LoggerFinder</description>

<properties>
<!-- Skips BND Baseline until the first release -->
<bnd.baseline.fail.on.missing>false</bnd.baseline.fail.on.missing>

<module.name>org.apache.logging.jpl.log4j.api</module.name>
<maven.compiler.release>11</maven.compiler.release>
</properties>

<dependencies>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*
* 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.jpl;

import java.lang.System.Logger;
import java.util.MissingResourceException;
import java.util.Objects;
import java.util.ResourceBundle;
import java.util.function.Supplier;
import org.apache.logging.log4j.message.Message;
import org.apache.logging.log4j.message.MessageFormatMessage;
import org.apache.logging.log4j.message.SimpleMessage;
import org.apache.logging.log4j.spi.ExtendedLogger;

/**
* JPL {@link Logger logger} implementation that uses Log4j.
* Implement all default {@link Logger} methods to ensure proper class resolution
*
* @since 2.14
*/
public class Log4jSystemLogger implements Logger {

private final ExtendedLogger logger;

private static final String FQCN = Log4jSystemLogger.class.getName();

public Log4jSystemLogger(final ExtendedLogger logger) {
this.logger = logger;
}

@Override
public String getName() {
return logger.getName();
}

@Override
public boolean isLoggable(final Level level) {
return logger.isEnabled(getLevel(level));
}

@Override
public void log(final Level level, final String msg) {
log(level, (ResourceBundle) null, msg, (Throwable) null);
}

@Override
public void log(final Level level, final Supplier<String> msgSupplier) {
Objects.requireNonNull(msgSupplier);
if (isLoggable(Objects.requireNonNull(level))) {
log(level, (ResourceBundle) null, msgSupplier.get(), (Throwable) null);
}
}

@Override
public void log(final Level level, final Object obj) {
Objects.requireNonNull(obj);
if (isLoggable(Objects.requireNonNull(level))) {
log(level, (ResourceBundle) null, obj.toString(), (Throwable) null);
}
}

@Override
public void log(final Level level, final String msg, final Throwable thrown) {
log(level, null, msg, thrown);
}

@Override
public void log(final Level level, final Supplier<String> msgSupplier, final Throwable thrown) {
Objects.requireNonNull(msgSupplier);
if (isLoggable(Objects.requireNonNull(level))) {
log(level, null, msgSupplier.get(), thrown);
}
}

@Override
public void log(final Level level, final String format, final Object... params) {
log(level, null, format, params);
}

@Override
public void log(final Level level, final ResourceBundle bundle, final String msg, final Throwable thrown) {
logger.logIfEnabled(FQCN, getLevel(level), null, getResource(bundle, msg), thrown);
}

@Override
public void log(final Level level, final ResourceBundle bundle, final String format, final Object... params) {
final Message message = createMessage(getResource(bundle, format), params);
logger.logIfEnabled(FQCN, getLevel(level), null, message, message.getThrowable());
}

private static Message createMessage(final String format, final Object... params) {
if (params == null || params.length == 0) {
return new SimpleMessage(format);
}
return new MessageFormatMessage(format, params);
}

private static org.apache.logging.log4j.Level getLevel(final Level level) {
switch (level) {
case OFF:
return org.apache.logging.log4j.Level.OFF;
case ERROR:
return org.apache.logging.log4j.Level.ERROR;
case WARNING:
return org.apache.logging.log4j.Level.WARN;
case INFO:
return org.apache.logging.log4j.Level.INFO;
case DEBUG:
return org.apache.logging.log4j.Level.DEBUG;
case TRACE:
return org.apache.logging.log4j.Level.TRACE;
case ALL:
return org.apache.logging.log4j.Level.ALL;
}
return org.apache.logging.log4j.Level.ERROR;
}

private static String getResource(final ResourceBundle bundle, final String msg) {
if (bundle == null || msg == null) {
return msg;
}
try {
return bundle.getString(msg);
} catch (MissingResourceException e) {
// ignore
return msg;
} catch (ClassCastException ex) {
return bundle.getObject(msg).toString();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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.jpl;

import java.lang.System.Logger;
import java.lang.System.LoggerFinder;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.spi.AbstractLoggerAdapter;
import org.apache.logging.log4j.spi.LoggerContext;
import org.apache.logging.log4j.util.StackLocatorUtil;

/**
* {@link Logger} registry implementation using just log4j-api.
*
* @since 2.14
*/
public class Log4jSystemLoggerAdapter extends AbstractLoggerAdapter<Logger> {

@Override
protected Logger newLogger(final String name, final LoggerContext context) {
return new Log4jSystemLogger(context.getLogger(name));
}

@Override
protected LoggerContext getContext() {
return getContext(
LogManager.getFactory().isClassLoaderDependent()
? StackLocatorUtil.getCallerClass(LoggerFinder.class)
: null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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.jpl;

import aQute.bnd.annotation.Resolution;
import aQute.bnd.annotation.spi.ServiceProvider;
import java.lang.System.Logger;

/**
* @since 2.14
*/
@ServiceProvider(value = System.LoggerFinder.class, resolution = Resolution.OPTIONAL)
public class Log4jSystemLoggerFinder extends System.LoggerFinder {

private final Log4jSystemLoggerAdapter loggerAdapter = new Log4jSystemLoggerAdapter();

@Override
public Logger getLogger(final String name, final Module module) {
return loggerAdapter.getLogger(name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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.
*/
@Export
@Version("2.20.1")
package org.apache.logging.log4j.jpl;

import org.osgi.annotation.bundle.Export;
import org.osgi.annotation.versioning.Version;
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 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.
org.apache.logging.log4j.jpl.Log4jSystemLoggerFinder
Loading
Loading