Skip to content

Commit

Permalink
Replace System.out with Jboss logging
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Oct 28, 2024
1 parent 2752323 commit 93359b8
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ Just add the dependency as `<scope>test</scope>` to pom.xml:
<version>${playwright.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
```
Write your tests:
````java
Expand Down
5 changes: 5 additions & 0 deletions docs/modules/ROOT/pages/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ Just add the dependency as `<scope>test</scope>` to your `pom.xml`:
<version>{project-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
----

Write your tests:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.quarkiverse.playwright.graal;

import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

import io.quarkus.logging.Log;

import com.oracle.svm.core.annotate.Alias;
import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;

/**
* Replace System.err.println with Jboss Logging.
*/
@TargetClass(className = "com.microsoft.playwright.impl.driver.DriverLogging")
final class DriverLoggingSubstitution {

@Alias
private static boolean isEnabled;

@Alias
private static DateTimeFormatter timestampFormat;

@Substitute
static void logWithTimestamp(String message) {
if (!isEnabled) {
return;
}
String timestamp = ZonedDateTime.now().format(timestampFormat);
Log.infof("%s %s", timestamp, message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.quarkiverse.playwright.graal;

import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

import io.quarkus.logging.Log;

import com.oracle.svm.core.annotate.Alias;
import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;

/**
* Replace System.out.println with Jboss Logging.
*/
@TargetClass(className = "com.microsoft.playwright.impl.LoggingSupport")
final class LoggingSupportSubstitution {

@Alias
private static boolean isEnabled;

@Alias
private static DateTimeFormatter timestampFormat;

@Substitute
static void logWithTimestamp(String message) {
String timestamp = ZonedDateTime.now().format(timestampFormat);
Log.infof("%s %s", timestamp, message);
}

@Substitute
static void logApiIfEnabled(String message) {
if (isEnabled) {
logApi(message);
}
}

@Substitute
static void logApi(String message) {
logWithTimestamp("pw:api " + message);
}
}

0 comments on commit 93359b8

Please sign in to comment.