-
Notifications
You must be signed in to change notification settings - Fork 6
Extends API for customizing RLib Logger and provides property based configuration #73
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
36 changes: 0 additions & 36 deletions
36
rlib-logger-impl/src/main/java/javasabr/rlib/logger/impl/config/LoggerConfigResolver.java
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...ogger/impl/config/LogMessageConsumer.java → ...l/config/consumer/LogMessageConsumer.java
This file contains hidden or 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
6 changes: 3 additions & 3 deletions
6
...l/config/impl/ConsoleMessageConsumer.java → ...consumer/impl/ConsoleMessageConsumer.java
This file contains hidden or 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
4 changes: 4 additions & 0 deletions
4
...ogger-impl/src/main/java/javasabr/rlib/logger/impl/config/consumer/impl/package-info.java
This file contains hidden or 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,4 @@ | ||
| @NullMarked | ||
| package javasabr.rlib.logger.impl.config.consumer.impl; | ||
|
|
||
| import org.jspecify.annotations.NullMarked; |
4 changes: 4 additions & 0 deletions
4
rlib-logger-impl/src/main/java/javasabr/rlib/logger/impl/config/consumer/package-info.java
This file contains hidden or 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,4 @@ | ||
| @NullMarked | ||
| package javasabr.rlib.logger.impl.config.consumer; | ||
|
|
||
| import org.jspecify.annotations.NullMarked; |
This file contains hidden or 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
46 changes: 46 additions & 0 deletions
46
...-logger-impl/src/main/java/javasabr/rlib/logger/impl/config/impl/LoggerConfigBuilder.java
This file contains hidden or 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,46 @@ | ||
| package javasabr.rlib.logger.impl.config.impl; | ||
|
|
||
| import javasabr.rlib.collections.array.Array; | ||
| import javasabr.rlib.collections.array.ArrayFactory; | ||
| import javasabr.rlib.collections.array.MutableArray; | ||
| import javasabr.rlib.collections.dictionary.DictionaryFactory; | ||
| import javasabr.rlib.collections.dictionary.MutableRefToRefDictionary; | ||
| import javasabr.rlib.logger.api.LoggerLevel; | ||
| import javasabr.rlib.logger.impl.config.LoggerConfig; | ||
| import javasabr.rlib.logger.impl.config.consumer.LogMessageConsumer; | ||
| import javasabr.rlib.logger.impl.config.impl.DefaultLoggerConfig.LoggerConsumersKey; | ||
| import javasabr.rlib.logger.impl.config.render.LogMessageRender; | ||
|
|
||
| public class LoggerConfigBuilder { | ||
|
|
||
| final MutableRefToRefDictionary<String, LoggerLevel> loggerLevels; | ||
| final MutableRefToRefDictionary<String, LogMessageRender> renders; | ||
| final MutableRefToRefDictionary<String, LogMessageConsumer> consumers; | ||
| final MutableRefToRefDictionary<LoggerConsumersKey, MutableArray<LogMessageConsumer>> loggerConsumers; | ||
|
|
||
| public LoggerConfigBuilder() { | ||
| this.loggerLevels = DictionaryFactory.mutableRefToRefDictionary(); | ||
| this.renders = DictionaryFactory.mutableRefToRefDictionary(); | ||
| this.consumers = DictionaryFactory.mutableRefToRefDictionary(); | ||
| this.loggerConsumers = DictionaryFactory.mutableRefToRefDictionary(); | ||
| } | ||
|
JavaSaBr marked this conversation as resolved.
|
||
|
|
||
| public void registerLoggerLevel(String loggerName, LoggerLevel level) { | ||
| loggerLevels.put(loggerName, level); | ||
| } | ||
|
|
||
| public void registerLoggerConsumer(String loggerName, LoggerLevel level, LogMessageConsumer consumer) { | ||
| var key = new LoggerConsumersKey(loggerName, level); | ||
| loggerConsumers | ||
| .getOrCompute(key, () -> ArrayFactory.mutableArray(LogMessageConsumer.class)) | ||
| .add(consumer); | ||
| } | ||
|
|
||
| public LoggerConfig build() { | ||
| var tempDictionary = DictionaryFactory | ||
| .<LoggerConsumersKey, Array<LogMessageConsumer>>mutableRefToRefDictionary(); | ||
| loggerConsumers.forEach((key, consumers) -> | ||
| tempDictionary.put(key, Array.copyOf(consumers))); | ||
| return new DefaultLoggerConfig(loggerLevels.toReadOnly(), tempDictionary.toReadOnly()); | ||
| } | ||
| } | ||
This file contains hidden or 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
19 changes: 19 additions & 0 deletions
19
...pl/src/main/java/javasabr/rlib/logger/impl/config/loader/LoggerConfigLoadersProvider.java
This file contains hidden or 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,19 @@ | ||
| package javasabr.rlib.logger.impl.config.loader; | ||
|
|
||
| import javasabr.rlib.collections.array.Array; | ||
|
|
||
| /** | ||
| * Provider of additional logger configuration loaders. | ||
| * | ||
| * @since 10.0.0 | ||
| */ | ||
| public interface LoggerConfigLoadersProvider { | ||
|
|
||
| /** | ||
| * Returns additional logger configuration loaders. | ||
| * | ||
| * @return the logger configuration loaders | ||
| * @since 10.0.0 | ||
| */ | ||
| Array<LoggerConfigLoader> getLoggerConfigLoaders(); | ||
| } | ||
|
JavaSaBr marked this conversation as resolved.
|
||
48 changes: 48 additions & 0 deletions
48
...gger-impl/src/main/java/javasabr/rlib/logger/impl/config/loader/LoggerConfigResolver.java
This file contains hidden or 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 javasabr.rlib.logger.impl.config.loader; | ||
|
|
||
| import java.util.Comparator; | ||
| import java.util.Optional; | ||
| import java.util.ServiceLoader; | ||
| import javasabr.rlib.collections.array.Array; | ||
| import javasabr.rlib.collections.array.ArrayCollectors; | ||
| import javasabr.rlib.collections.array.ArrayFactory; | ||
| import javasabr.rlib.logger.impl.config.LoggerConfig; | ||
| import javasabr.rlib.logger.impl.config.loader.impl.DefaultLoggerConfigLoader; | ||
| import javasabr.rlib.logger.impl.config.loader.impl.PropertyLoggerConfigLoader; | ||
|
|
||
| /** | ||
| * Resolver of logger configuration from available loaders. | ||
| * | ||
| * @since 10.0.0 | ||
| */ | ||
| public class LoggerConfigResolver { | ||
|
|
||
| private static final Array<LoggerConfigLoader> LOADERS; | ||
|
|
||
| static { | ||
| var registeredProviders = ArrayFactory.mutableArray(LoggerConfigLoader.class); | ||
| registeredProviders.add(new DefaultLoggerConfigLoader()); | ||
| registeredProviders.add(new PropertyLoggerConfigLoader()); | ||
| for (var provider : ServiceLoader.load(LoggerConfigLoadersProvider.class)) { | ||
| registeredProviders.addAll(provider.getLoggerConfigLoaders()); | ||
| } | ||
| LOADERS = registeredProviders.stream() | ||
| .sorted(Comparator.comparingInt(LoggerConfigLoader::order)) | ||
| .collect(ArrayCollectors.toArray(LoggerConfigLoader.class)); | ||
| } | ||
|
|
||
| /** | ||
| * Loads logger configuration. | ||
| * | ||
| * @return the loaded logger configuration | ||
| * @since 10.0.0 | ||
| */ | ||
| public static LoggerConfig load() { | ||
| return LOADERS | ||
| .stream() | ||
| .map(LoggerConfigLoader::tryToLoad) | ||
| .flatMap(Optional::stream) | ||
| .findFirst() | ||
| .orElseThrow(); | ||
| } | ||
| } |
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.