Skip to content
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

Restructure configuration mechanism #89

Merged
merged 23 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d37a476
chore: Upgrade gradle
hkupty Mar 15, 2024
24b3184
chore: Replace docker image in CI
hkupty Mar 15, 2024
2c3bdce
chore: Introduce taskfile
hkupty Mar 15, 2024
b5066c0
feat: Introduce new config structure
hkupty Mar 16, 2024
ec54d76
feat: Implement new config structure for yaml
hkupty Mar 16, 2024
44c3712
test: Add tests form yaml config
hkupty Mar 16, 2024
30d5208
refactor: Pepare transition to new config structure
hkupty Mar 16, 2024
f2ce2ec
test: Add sample project (again)
hkupty Mar 16, 2024
a234b4f
feat: Add support for Snake Yaml {,Engine}
hkupty Mar 17, 2024
adf44a5
refactor: Check for alternative files
hkupty Mar 19, 2024
4888523
refactor: Only apply registered providers
hkupty Mar 20, 2024
4900594
refactor: Implement file watcher
hkupty Mar 20, 2024
43c1adc
refactor: Update sample for testing
hkupty Mar 20, 2024
19dc730
chore: Remove buildSrc plugin
hkupty Mar 20, 2024
81c2d7b
chore: Fix CI image oversight
hkupty Mar 20, 2024
89cf688
refactor: Ensure we handle root logger correctly
hkupty Mar 20, 2024
f42131c
chore: Fix missing plugin
hkupty Mar 20, 2024
8c879ac
test: Tweak values to test root logger
hkupty Mar 20, 2024
7d32d90
refactor: Rename config item to `loggers`
hkupty Mar 20, 2024
ace796a
chore: Minor build.gradle fixes
hkupty Mar 20, 2024
9cf14ef
test: Test all implementations extensively
hkupty Mar 20, 2024
c5d0c68
refactor: Cleanup old configuration + penna-dev
hkupty Mar 20, 2024
f5fa9c7
refactor: Minor fixes and renaming namespace
hkupty Mar 20, 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
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Use the latest 2.1 version of CircleCI pipeline process engine.
# See: https://circleci.com/docs/2.0/configuration-reference
---
version: 2.1

# Define a job to be invoked later in a workflow.
Expand All @@ -9,7 +10,7 @@ jobs:
# Specify the execution environment. You can specify an image from Dockerhub or use one of our Convenience Images from CircleCI's Developer Hub.
# See: https://circleci.com/docs/2.0/configuration-reference/#docker-machine-macos-windows-executor
docker:
- image: amazoncorretto:17
- image: eclipse-temurin:21-jdk-alpine
# Add steps to the job
# See: https://circleci.com/docs/2.0/configuration-reference/#steps
steps:
Expand Down
30 changes: 0 additions & 30 deletions buildSrc/src/main/groovy/penna.base-java.gradle

This file was deleted.

1 change: 0 additions & 1 deletion buildSrc/src/main/groovy/penna.publishing.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
plugins {
id 'penna.base-java'
id 'maven-publish'
id 'signing'
}
Expand Down
20 changes: 16 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,32 @@ slf4j = "2.0.12"
jackson = "2.17.0"
jqwik = "1.8.4"
junit = "5.10.2"
junit-pioneer = "2.2.0"
jmh = "1.37"
jbrAnn = "24.1.0"
snakeyaml = "2.2"
snakeyaml-engine = "2.7"

[libraries]
slf4j = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" }

# Jackson support
jackson-core = { module = "com.fasterxml.jackson.core:jackson-core", version.ref = "jackson" }
jackson-databind = { module = "com.fasterxml.jackson.core:jackson-databind", version.ref = "jackson" }
jackson-yaml = { module = "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml", version.ref = "jackson" }

# snakeyaml
snakeyaml-plain = { module = "org.yaml:snakeyaml", version.ref = "snakeyaml" }
snakeyaml-engine = { module = "org.snakeyaml:snakeyaml-engine", version.ref = "snakeyaml-engine" }

# testing
jqwik = { module = "net.jqwik:jqwik", version.ref = "jqwik" }
junit-api = { module ="org.junit.jupiter:junit-jupiter-api", version.ref = "junit" }
junit-engine = { module ="org.junit.jupiter:junit-jupiter-engine", version.ref = "junit" }
junit-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit" }
junit-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit" }
junit-pioneer = { module = "org.junit-pioneer:junit-pioneer", version.ref = "junit-pioneer" }

commons-math = { module = "org.apache.commons:commons-math3", version.prefer = "3.6.1"}
commons-lang = { module = "org.apache.commons:commons-lang3", version.prefer = "3.13.0"}
commons-math = { module = "org.apache.commons:commons-math3", version.prefer = "3.6.1" }
commons-lang = { module = "org.apache.commons:commons-lang3", version.prefer = "3.13.0" }

jmh-core = { module = "org.openjdk.jmh:jmh-core", version.ref = "jmh" }
jmh-annotations = { module = "org.openjdk.jmh:jmh-generator-annprocess", version.ref = "jmh" }
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
14 changes: 7 additions & 7 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -202,11 +202,11 @@ fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down
26 changes: 25 additions & 1 deletion penna-api/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'penna.base-java'
id 'java-library'
id 'penna.publishing'
id 'pmd'
}
Expand All @@ -10,6 +10,30 @@ repositories {
mavenCentral()
}

java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}

// Reproducible builds
tasks.withType(AbstractArchiveTask).configureEach {
preserveFileTimestamps = false
reproducibleFileOrder = true
}

// The API is an optional client-facing library and therefore it should not have gaps
// in the documentation, nor fail on linting, so it is easier for consumers to understand
// what it is doing under the hood.
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
options.compilerArgs += [
"-Xlint:all",
"-Xdoclint:all/public",
"-Werror"
]
}

dependencies {
compileOnly libs.slf4j
compileOnly libs.jetbrains.annotations
Expand Down
10 changes: 4 additions & 6 deletions penna-api/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import penna.api.configv2.Provider;

/**
* Penna API is a thin set of classes and records that are common-ground between the {@code penna.core} project
* and satellite projects or user customization.
* <br />
* For example, in order to customize log level, a user might need to pass in a {@link penna.api.config.Config} through
* the {@link penna.api.config.ConfigManager} interface.
* <br /><br />
* Advanced users might also implement a {@link penna.api.config.ConfigManager} themselves, so they have better runtime
* control over log level and fields, for example, fine-tuning the amount of logged information based on metrics or usage
* volume. For that, one can have a monitor thread collecting instrumentation data interacting directly with the
* {@link penna.api.config.Configurable} instance.
*/
module penna.api {
uses Provider;
requires transitive org.slf4j;
requires transitive org.jetbrains.annotations;

exports penna.api.models;
exports penna.api.config;
exports penna.api.configv2;
}
110 changes: 0 additions & 110 deletions penna-api/src/main/java/penna/api/config/ConfigManager.java

This file was deleted.

15 changes: 0 additions & 15 deletions penna-api/src/main/java/penna/api/config/Configurable.java

This file was deleted.

28 changes: 22 additions & 6 deletions penna-api/src/main/java/penna/api/config/ExceptionHandling.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@

/**
* This record holds configuration on how Penna should handle logging exception fields.
* @param maxDepth How far the stacktrace can go before cutting short
* @param traverseDepth The amount of levels one can traverse down the exception
*
* @param maxDepth How far the stacktrace can go before cutting short
* @param traverseDepth The amount of nested exceptions the logger can traverse before aborting
* @param deduplication When enabled, penna will not print repeated stack frames
*/
public record ExceptionHandling(
int maxDepth,
int traverseDepth,
boolean deduplication
int maxDepth,
int traverseDepth,
boolean deduplication
) {

private static final ExceptionHandling singleton = new ExceptionHandling(64, 2, false);

/**
* Gets the default instance.
*
* @return The static default instance.
*/
public static ExceptionHandling getDefault() {
Expand All @@ -24,6 +26,7 @@ public static ExceptionHandling getDefault() {

/**
* Returns a copy of the original object swapping the value for {@link ExceptionHandling#deduplication}
*
* @param deduplication Whether Penna should short-circuit out of writing stacktraces if identifies duplicates or not.
* @return A copy of the original object with the values replaced
*/
Expand All @@ -33,16 +36,28 @@ public ExceptionHandling replaceDeduplication(boolean deduplication) {

/**
* Returns a copy of the original object swapping the value for {@link ExceptionHandling#maxDepth}
*
* @param maxDepth The maximum number of stacktrace lines that should be shown before short-circuiting out
* @return A copy of the original object with the values replaced
*/
public ExceptionHandling replaceMaxDepth(int maxDepth) {
return new ExceptionHandling(maxDepth, this.traverseDepth, this.deduplication);
return new ExceptionHandling(maxDepth, this.traverseDepth, this.deduplication);
}

/**
* Returns a copy of the original object swapping the value for {@link ExceptionHandling#traverseDepth}
*
* @param traverseDepth the amount of nested exceptions the logger will traverse
* @return A copy of the original object with the values replaced
*/
public ExceptionHandling replaceTraverseDepth(int traverseDepth) {
return new ExceptionHandling(this.maxDepth, traverseDepth, this.deduplication);
}

/**
* This is a convenience method that returns a copy of the default object with the value for {@link ExceptionHandling#deduplication}
* replaced by the parameter provided.
*
* @param deduplication Whether Penna should short-circuit out of writing stacktraces if identifies duplicates or not.
* @return An instance of {@link ExceptionHandling}
*/
Expand All @@ -53,6 +68,7 @@ public static ExceptionHandling withDeduplication(boolean deduplication) {
/**
* This is a convenience method that returns a copy of the default object with the value for {@link ExceptionHandling#maxDepth}
* replaced by the parameter provided.
*
* @param maxDepth The maximum number of stacktrace lines that should be shown before short-circuiting out
* @return An instance of {@link ExceptionHandling}
*/
Expand Down
Loading