diff --git a/driver-bundle/src/main/java/com/microsoft/playwright/impl/DriverJar.java b/driver-bundle/src/main/java/com/microsoft/playwright/impl/DriverJar.java index 2fdfde5f..56944780 100644 --- a/driver-bundle/src/main/java/com/microsoft/playwright/impl/DriverJar.java +++ b/driver-bundle/src/main/java/com/microsoft/playwright/impl/DriverJar.java @@ -37,11 +37,13 @@ public class DriverJar extends Driver { ? Files.createTempDirectory(prefix) : Files.createTempDirectory(Paths.get(alternativeTmpdir), prefix); driverTempDir.toFile().deleteOnExit(); + logMessage("created DriverJar: " + driverTempDir); } @Override protected void initialize(Map env, Boolean installBrowsers) throws Exception { extractDriverToTempDir(); + logMessage("extracted driver from jar to " + driverPath()); if (installBrowsers) installBrowsers(env); } diff --git a/driver/src/main/java/com/microsoft/playwright/impl/Driver.java b/driver/src/main/java/com/microsoft/playwright/impl/Driver.java index c71446b3..d4512ef5 100644 --- a/driver/src/main/java/com/microsoft/playwright/impl/Driver.java +++ b/driver/src/main/java/com/microsoft/playwright/impl/Driver.java @@ -18,8 +18,11 @@ package com.microsoft.playwright.impl; import java.nio.file.Path; import java.nio.file.Paths; +import java.time.ZonedDateTime; import java.util.Map; +import static com.microsoft.playwright.impl.DriverLogging.logWithTimestamp; + /** * This class provides access to playwright-cli. It can be either preinstalled * in the host system and its path is passed as a system property or it can be @@ -31,6 +34,7 @@ public abstract class Driver { private static class PreinstalledDriver extends Driver { private final Path driverDir; PreinstalledDriver(Path driverDir) { + logMessage("created PreinstalledDriver: " + driverDir); this.driverDir = driverDir; } @@ -49,7 +53,9 @@ public abstract class Driver { if (instance == null) { try { instance = createDriver(); + logMessage("initializing driver"); instance.initialize(env, installBrowsers); + logMessage("driver inialized."); } catch (Exception exception) { throw new RuntimeException("Failed to create driver", exception); } @@ -97,4 +103,9 @@ public abstract class Driver { } abstract Path driverDir(); + + protected static void logMessage(String message) { + // This matches log format produced by the server. + logWithTimestamp("pw:install " + message); + } } diff --git a/driver/src/main/java/com/microsoft/playwright/impl/DriverLogging.java b/driver/src/main/java/com/microsoft/playwright/impl/DriverLogging.java new file mode 100644 index 00000000..4e748c3d --- /dev/null +++ b/driver/src/main/java/com/microsoft/playwright/impl/DriverLogging.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) Microsoft Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.microsoft.playwright.impl; + +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; + +class DriverLogging { + private static final boolean isEnabled; + static { + String debug = System.getenv("DEBUG"); + isEnabled = (debug != null) && debug.contains("pw:install"); + } + + private static final DateTimeFormatter timestampFormat = DateTimeFormatter.ofPattern( + "yyyy-MM-dd'T'HH:mm:ss.SSSXXX").withZone(ZoneId.of("UTC")); + + static void logWithTimestamp(String message) { + // This matches log format produced by the server. + String timestamp = ZonedDateTime.now().format(timestampFormat); + System.err.println(timestamp + " " + message); + } +}