-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add `logging` sample by demonstrating how to configure logging via `jpro.onJVMStartup` and `jpro.onFStartup` configuration options * Update JPro to version `2023.2.0-M1` for the usage of latest introduced changes needed for this sample * Retrieve JavaFX version from `gradle.properties` * Reconfigure logging on `JVM` startup * Upgrade JPro version to version `2023.2.2` * Define dependencies version in the `gradle.properties` * Define dependencies versions in `gradle.properties` * Use version strings from `gradle.properties` in `build.gradle` files foe each sample * Apply API changes regarding the update of the dependencies * Update the routing API to the latest version * Use the new routing API in the `website` sample * Apply some cleanup * Fix `link` on the header label * Remove the exception from the `start` method in the `PWAApp` class * Fix missing dependencies for the `logging-sample` * Add `logging` sample description in the `README.md` file * Leave only the Linux CI build with Java 17 * Update the `logging` sample application and include the `jpro.onJVMShutdown` configuration * Fix resource paths in `jpro.conf` configuration file * Fix logback configuration resource filename
- Loading branch information
Showing
13 changed files
with
325 additions
and
33 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 was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
.gradle | ||
build/ | ||
!gradle/wrapper/gradle-wrapper.jar | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### IntelliJ IDEA ### | ||
.idea/modules.xml | ||
.idea/jarRepositories.xml | ||
.idea/compiler.xml | ||
.idea/libraries/ | ||
*.iws | ||
*.iml | ||
*.ipr | ||
out/ | ||
!**/src/main/**/out/ | ||
!**/src/test/**/out/ | ||
|
||
### Eclipse ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
bin/ | ||
!**/src/main/**/bin/ | ||
!**/src/test/**/bin/ | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
### Mac OS ### | ||
.DS_Store |
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 @@ | ||
plugins { | ||
application | ||
id("org.openjfx.javafxplugin") | ||
id("jpro-gradle-plugin") | ||
} | ||
|
||
group = "one.jpro.samples" | ||
version = "0.0.1" | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
val JAVAFX_VERSION = properties["JAVAFX_VERSION"] as String | ||
val SLF4J_VERSION = properties["SLF4J_VERSION"] as String | ||
val LOGBACK_VERSION = properties["LOGBACK_VERSION"] as String | ||
val JUNIT_VERSION = properties["JUNIT_VERSION"] as String | ||
|
||
javafx { | ||
version = JAVAFX_VERSION | ||
modules = listOf("javafx.graphics", "javafx.controls", "javafx.fxml", "javafx.media", "javafx.web") | ||
} | ||
|
||
dependencies { | ||
implementation("org.slf4j:slf4j-api:$SLF4J_VERSION") | ||
implementation("org.slf4j:jul-to-slf4j:$SLF4J_VERSION") | ||
implementation("ch.qos.logback:logback-classic:$LOGBACK_VERSION") | ||
|
||
testImplementation(platform("org.junit:junit-bom:$JUNIT_VERSION")) | ||
testImplementation("org.junit.jupiter:junit-jupiter") | ||
} | ||
|
||
application { | ||
mainModule.set("one.jpro.samples.logging") | ||
// Define the main class for the application. | ||
mainClass.set("one.jpro.samples.logging.SampleApp") | ||
} | ||
|
||
jpro { | ||
port = 8080 | ||
} | ||
|
||
tasks.test { | ||
useJUnitPlatform() | ||
} |
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,15 @@ | ||
/** | ||
* Module descriptor. | ||
* | ||
* @author Besmir Beqiri | ||
*/ | ||
module one.jpro.samples.logging { | ||
requires javafx.controls; | ||
requires java.logging; | ||
requires org.slf4j; | ||
requires jul.to.slf4j; | ||
requires ch.qos.logback.core; | ||
requires ch.qos.logback.classic; | ||
|
||
exports one.jpro.samples.logging; | ||
} |
18 changes: 18 additions & 0 deletions
18
logging/src/main/java/one/jpro/samples/logging/LogOnFXStartup.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,18 @@ | ||
package one.jpro.samples.logging; | ||
|
||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
/** | ||
* Log config on FX startup. | ||
* | ||
* @author Besmir Beqiri | ||
*/ | ||
public class LogOnFXStartup { | ||
|
||
private static final Logger logger = Logger.getLogger(LogOnFXStartup.class.getName()); | ||
|
||
public static void main(String[] args) { | ||
logger.log(Level.INFO, "Some logging on JavaFX Application Startup!"); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
logging/src/main/java/one/jpro/samples/logging/LogOnJVMShutdown.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,26 @@ | ||
package one.jpro.samples.logging; | ||
|
||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
/** | ||
* This is a simple class that will be executed on JVM startup. | ||
* | ||
* @author Besmir Beqiri | ||
*/ | ||
public class LogOnJVMShutdown { | ||
|
||
private static final Logger jullogger = Logger.getLogger(LogOnJVMShutdown.class.getName()); | ||
|
||
public static void main(String[] args) { | ||
|
||
jullogger.log(Level.INFO, "JUL Logging on JVM Shutdown!"); | ||
|
||
for (java.util.logging.Handler handler : Logger.getLogger("").getHandlers()) { | ||
handler.flush(); | ||
} | ||
LogOnJVMStartup.julShutdownTrigger.complete(null); | ||
LogOnJVMStartup.loggerContext.stop(); | ||
|
||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
logging/src/main/java/one/jpro/samples/logging/LogOnJVMStartup.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,99 @@ | ||
package one.jpro.samples.logging; | ||
|
||
import ch.qos.logback.classic.LoggerContext; | ||
import ch.qos.logback.classic.joran.JoranConfigurator; | ||
import ch.qos.logback.core.joran.spi.JoranException; | ||
import org.slf4j.LoggerFactory; | ||
import org.slf4j.bridge.SLF4JBridgeHandler; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.logging.*; | ||
|
||
/** | ||
* This is a simple class that will be executed on JVM startup. | ||
* | ||
* @author Besmir Beqiri | ||
*/ | ||
public class LogOnJVMStartup { | ||
public static LoggerContext loggerContext = null; | ||
private static final Logger logger = Logger.getLogger(LogOnJVMStartup.class.getName()); | ||
|
||
public static void main(String[] args) { | ||
// redirect j.u.l. logging to SLF4J | ||
SLF4JBridgeHandler.removeHandlersForRootLogger(); | ||
|
||
String logbackFile = LogOnJVMStartup.class.getResource("/logback-sample.xml").getFile(); | ||
loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); | ||
loggerContext.reset(); | ||
JoranConfigurator configurator = new JoranConfigurator(); | ||
configurator.setContext(loggerContext); | ||
|
||
SLF4JBridgeHandler.install(); | ||
try { | ||
configurator.doConfigure(logbackFile); | ||
} catch (JoranException je) { | ||
je.printStackTrace(); | ||
throw new RuntimeException(je.getMessage()); | ||
} | ||
|
||
synchronizeJULShutdown(); | ||
|
||
logger.log(Level.INFO, "Logging on JVM Startup!"); | ||
} | ||
|
||
public static void synchronizeJULShutdown() { | ||
// For reference: https://stackoverflow.com/questions/60687511/why-is-the-new-java-logger-failing-to-work-consistently-here | ||
Logger root = Logger.getLogger(""); | ||
Handler[] handlers = root.getHandlers(); | ||
|
||
for(Handler h : handlers) { | ||
root.removeHandler(h); | ||
} | ||
|
||
root.addHandler(new CleanerJoin()); | ||
|
||
for(Handler h : handlers) { | ||
root.addHandler(h); | ||
} | ||
} | ||
|
||
|
||
public static CompletableFuture<Void> julShutdownTrigger = new CompletableFuture<>(); | ||
static class CleanerJoin extends Handler { | ||
|
||
CleanerJoin() { | ||
} | ||
|
||
@Override | ||
public void close() { | ||
boolean interrupted = false; | ||
try { | ||
for(;;) { | ||
try { //Could use LogManager to lookup timeout values and use a timed join. | ||
julShutdownTrigger.get(); | ||
break; | ||
} catch (ExecutionException e) { | ||
reportError("Shutdown hook failed.", e, ErrorManager.CLOSE_FAILURE); | ||
break; | ||
} catch (InterruptedException retry) { | ||
interrupted = true; | ||
} | ||
} | ||
} finally { | ||
if (interrupted) { | ||
Thread.currentThread().interrupt(); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void flush() { | ||
} | ||
|
||
@Override | ||
public void publish(LogRecord r) { | ||
isLoggable(r); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
logging/src/main/java/one/jpro/samples/logging/SampleApp.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,34 @@ | ||
package one.jpro.samples.logging; | ||
|
||
import javafx.application.Application; | ||
import javafx.geometry.Pos; | ||
import javafx.scene.Scene; | ||
import javafx.scene.control.Label; | ||
import javafx.scene.text.Font; | ||
import javafx.stage.Stage; | ||
|
||
/** | ||
* Example application for custom logging configuration. | ||
* | ||
* @author Besmir Beqiri | ||
*/ | ||
public class SampleApp extends Application { | ||
|
||
@Override | ||
public void start(Stage stage) { | ||
Label label = new Label("Hello JPro!"); | ||
label.setFont(new Font(50)); | ||
label.setAlignment(Pos.CENTER); | ||
stage.setScene(new Scene(label)); | ||
stage.show(); | ||
} | ||
|
||
/** | ||
* Application entry point. | ||
* | ||
* @param args the command line arguments | ||
*/ | ||
public static void main(String[] args) { | ||
launch(args); | ||
} | ||
} |
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,6 @@ | ||
jpro.logConsole=false | ||
jpro.logToJUL=true | ||
jpro.forceShutdown = false | ||
jpro.onJVMStartup=one.jpro.samples.logging.LogOnJVMStartup | ||
jpro.onJVMShutdown=one.jpro.samples.logging.LogOnJVMShutdown | ||
jpro.onFXStartup=one.jpro.samples.logging.LogOnFXStartup |
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,24 @@ | ||
<configuration> | ||
|
||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>[onJVMStartup] %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<appender name="FILE" class="ch.qos.logback.core.FileAppender"> | ||
<file>logs/testFile.log</file> | ||
<append>true</append> | ||
<immediateFlush>true</immediateFlush> | ||
<encoder> | ||
<pattern>[onJVMStartup] %-4relative [%thread] %-5level %logger{35} -%kvp- %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<logger name="Console" additivity="false"/> | ||
|
||
<root level="debug"> | ||
<appender-ref ref="FILE" /> | ||
<appender-ref ref="STDOUT" /> | ||
</root> | ||
</configuration> |
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 |
---|---|---|
|
@@ -27,3 +27,4 @@ include "ensemble:site" | |
include "auth0" | ||
include "suneditor" | ||
include "gps" | ||
include 'logging' |