From ba5f8a4160fd3afb496eb889c226570a1b0d0c1f Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Mon, 11 Jan 2021 22:22:58 -0800 Subject: [PATCH] fix(logs): use same format for pw:api logs as on server (#205) --- .../playwright/impl/LoggingSupport.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/LoggingSupport.java b/playwright/src/main/java/com/microsoft/playwright/impl/LoggingSupport.java index 6454e001..d5ca3542 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/LoggingSupport.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/LoggingSupport.java @@ -18,15 +18,25 @@ package com.microsoft.playwright.impl; import com.microsoft.playwright.Deferred; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.TimeZone; import java.util.function.Supplier; class LoggingSupport { - private static boolean isEnabled; - { + private static final boolean isEnabled; + static { String debug = System.getenv("DEBUG"); isEnabled = (debug != null) && debug.contains("pw:api"); } + private static final SimpleDateFormat timestampFormat; + static { + timestampFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"); + timestampFormat.setTimeZone(TimeZone.getTimeZone("UTC")); + } + + void withLogging(String apiName, Runnable code) { withLogging(apiName, () -> { code.run(); @@ -70,6 +80,8 @@ class LoggingSupport { } private void logApi(String message) { - System.err.println(message); + // This matches log format produced by the server. + String timestamp = timestampFormat.format(new Date()); + System.err.println(timestamp + " pw:api " + message); } }