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 21b1f8b
Show file tree
Hide file tree
Showing 4 changed files with 85 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,33 @@
package io.quarkiverse.playwright.graal;

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

import org.jboss.logging.Logger;

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 {
private static final Logger log = Logger.getLogger("Playwright Driver");

@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,42 @@
package io.quarkiverse.playwright.graal;

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

import org.jboss.logging.Logger;

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 {
private static final Logger log = Logger.getLogger("Playwright");

@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 21b1f8b

Please sign in to comment.