forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable the registration of @LoggingFilter classes via CDI
This allows for users to configure their filters via the usual Quarkus configuration approach. Follows up on: quarkusio#27864
- Loading branch information
Showing
8 changed files
with
104 additions
and
18 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
48 changes: 48 additions & 0 deletions
48
core/runtime/src/main/java/io/quarkus/runtime/logging/LogFilterFactory.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,48 @@ | ||
package io.quarkus.runtime.logging; | ||
|
||
import java.util.ServiceLoader; | ||
import java.util.logging.Filter; | ||
|
||
public interface LogFilterFactory { | ||
|
||
int MIN_PRIORITY = Integer.MAX_VALUE; | ||
int DEFAULT_PRIORITY = 0; | ||
|
||
Filter create(String className) throws Exception; | ||
|
||
default int priority() { | ||
return DEFAULT_PRIORITY; | ||
} | ||
|
||
static LogFilterFactory factory() { | ||
LogFilterFactory result = null; | ||
ServiceLoader<LogFilterFactory> load = ServiceLoader.load(LogFilterFactory.class); | ||
for (LogFilterFactory next : load) { | ||
if (result == null) { | ||
result = next; | ||
} else { | ||
if (next.priority() < result.priority()) { | ||
result = next; | ||
} | ||
} | ||
} | ||
if (result == null) { | ||
result = new ReflectionLogFilterFactory(); | ||
} | ||
return result; | ||
} | ||
|
||
class ReflectionLogFilterFactory implements LogFilterFactory { | ||
|
||
@Override | ||
public Filter create(String className) throws Exception { | ||
return (Filter) Class.forName(className, true, Thread.currentThread().getContextClassLoader()) | ||
.getConstructor().newInstance(); | ||
} | ||
|
||
@Override | ||
public int priority() { | ||
return LogFilterFactory.MIN_PRIORITY; | ||
} | ||
} | ||
} |
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
16 changes: 16 additions & 0 deletions
16
...s/arc/deployment/src/main/java/io/quarkus/arc/deployment/LoggingBeanSupportProcessor.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,16 @@ | ||
package io.quarkus.arc.deployment; | ||
|
||
import io.quarkus.arc.processor.BuiltinScope; | ||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.logging.LoggingResourceProcessor; | ||
|
||
public class LoggingBeanSupportProcessor { | ||
|
||
@BuildStep | ||
public void discoveredComponents(BuildProducer<BeanDefiningAnnotationBuildItem> beanDefiningAnnotationProducer) { | ||
beanDefiningAnnotationProducer.produce(new BeanDefiningAnnotationBuildItem( | ||
LoggingResourceProcessor.LOGGING_FILTER, BuiltinScope.SINGLETON.getName(), false)); | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
extensions/arc/runtime/src/main/java/io/quarkus/arc/runtime/logging/ArcLogFilterFactory.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,20 @@ | ||
package io.quarkus.arc.runtime.logging; | ||
|
||
import java.util.logging.Filter; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.runtime.logging.LogFilterFactory; | ||
|
||
public class ArcLogFilterFactory implements LogFilterFactory { | ||
|
||
@Override | ||
public Filter create(String className) throws Exception { | ||
return (Filter) Arc.container().instance(Class.forName(className, true, Thread.currentThread() | ||
.getContextClassLoader())).get(); | ||
} | ||
|
||
@Override | ||
public int priority() { | ||
return LogFilterFactory.DEFAULT_PRIORITY - 100; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
.../runtime/src/main/resources/META-INF/services/io.quarkus.runtime.logging.LogFilterFactory
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 @@ | ||
io.quarkus.arc.runtime.logging.ArcLogFilterFactory |
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