-
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix compatibility with legacy SLF4J 1
LoggerFactory failed to load org.slf4j.spi.LoggingEventAware. Fixes #397
- Loading branch information
Showing
13 changed files
with
847 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
slf4j-tinylog/src/main/java/org/tinylog/slf4j/LegacyTinylogLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2023 Martin Winandy | ||
* | ||
* Licensed 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.tinylog.slf4j; | ||
|
||
/** | ||
* Location aware logger for legacy SLF4J 1. | ||
*/ | ||
public final class LegacyTinylogLogger extends AbstractTinylogLogger { | ||
|
||
/** | ||
* @param name | ||
* Name for logger | ||
*/ | ||
public LegacyTinylogLogger(final String name) { | ||
super(name); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
slf4j-tinylog/src/main/java/org/tinylog/slf4j/ModernTinylogLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright 2023 Martin Winandy | ||
* | ||
* Licensed 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.tinylog.slf4j; | ||
|
||
import java.util.List; | ||
|
||
import org.slf4j.Marker; | ||
import org.slf4j.event.LoggingEvent; | ||
import org.slf4j.spi.LoggingEventAware; | ||
import org.tinylog.Level; | ||
|
||
/** | ||
* Location and event aware logger for modern SLF4J 2. | ||
*/ | ||
public final class ModernTinylogLogger extends AbstractTinylogLogger implements LoggingEventAware { | ||
|
||
/** | ||
* @param name | ||
* Name for logger | ||
*/ | ||
public ModernTinylogLogger(final String name) { | ||
super(name); | ||
} | ||
|
||
@Override | ||
public void log(final LoggingEvent event) { | ||
Level severityLevel = translateLevel(event.getLevel().toInt()); | ||
List<Marker> markers = event.getMarkers(); | ||
Marker marker = markers == null || markers.isEmpty() ? null : markers.get(0); | ||
String tag = marker == null ? null : marker.getName(); | ||
|
||
if (provider.getMinimumLevel(tag).ordinal() <= severityLevel.ordinal()) { | ||
provider.log( | ||
event.getCallerBoundary(), | ||
tag, | ||
severityLevel, | ||
event.getThrowable(), | ||
formatter, | ||
event.getMessage(), | ||
event.getArgumentArray() | ||
); | ||
} | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
slf4j-tinylog/src/main/java/org/tinylog/slf4j/ModernTinylogLoggerFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2023 Martin Winandy | ||
* | ||
* Licensed 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.tinylog.slf4j; | ||
|
||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ConcurrentMap; | ||
|
||
import org.slf4j.ILoggerFactory; | ||
|
||
/** | ||
* Logging factory implementation for providing {@link ModernTinylogLogger} instances. | ||
*/ | ||
public final class ModernTinylogLoggerFactory implements ILoggerFactory { | ||
|
||
private final ConcurrentMap<String, ModernTinylogLogger> loggers; | ||
|
||
/** */ | ||
public ModernTinylogLoggerFactory() { | ||
loggers = new ConcurrentHashMap<String, ModernTinylogLogger>(); | ||
} | ||
|
||
@Override | ||
public ModernTinylogLogger getLogger(final String name) { | ||
ModernTinylogLogger logger = loggers.get(name); | ||
if (logger == null) { | ||
ModernTinylogLogger newLogger = new ModernTinylogLogger(name); | ||
ModernTinylogLogger existingLogger = loggers.putIfAbsent(name, newLogger); | ||
return existingLogger == null ? newLogger : existingLogger; | ||
} else { | ||
return logger; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.