PlaywrightReportLogger
A PlaywrightReportLogger records entries at a level and attaches them to the test’s report, one
attachment per entry, in the order they were logged.
The log fixture gives every test one, named TestCase, starting at warn on the first
run and at debug on a retry. A child logger has a name of its own and shares its parent’s entries and level.
import { test } from "pomwright";
test("checkout", async ({ log }) => { log.warn("the basket was empty; added the test product"); // attachment: 11:39:57 PM 10/16/2026 - WARN : [TestCase]});Guide: logging to the report.
Constructor
Section titled “Constructor”new PlaywrightReportLogger()
Section titled “new PlaywrightReportLogger()”Creates a root logger, for a fixture of your own; the log fixture creates one per test. The level and the entries
are objects that the logger and its children share and change.
Usage
import { type LogEntry, PlaywrightReportLogger } from "pomwright";
const entries: LogEntry[] = [];const log = new PlaywrightReportLogger({ current: "warn", initial: "warn" }, entries, "TestCase");Arguments
-
sharedLogLevelObject -
sharedLogEntryLogEntry[]The array the entries are recorded in, in call order.
-
contextNamestringThe logger’s name in attachment names.
Methods
Section titled “Methods”attachLogsToTest()
Section titled “attachLogsToTest()”Attaches the recorded entries to the test, one attachment per entry in call order, named with the time, the date, the
level and the logger’s name. The log fixture calls it when the test ends; call it in a fixture of your own. See
your own fixture.
Usage
import { test as base } from "@playwright/test";import { PlaywrightReportLogger } from "pomwright";
export const test = base.extend<{ log: PlaywrightReportLogger }>({ log: async ({ locale, timezoneId }, use, testInfo) => { const log = new PlaywrightReportLogger({ current: "warn", initial: "warn" }, [], "TestCase"); await use(log); log.attachLogsToTest(testInfo, { locale, timeZone: timezoneId }); },});Arguments
-
testInfoTestInfo -
formatObject (optional)localestring (optional)timeZonestring (optional)
The locale and time zone of the time and date in the names, as
toLocaleTimeStringtakes them; thelogfixture passes Playwright’slocaleandtimezoneId. Each one left out is the project’suse.localeoruse.timezoneIdfrom the config, or the machine’s where the config sets none; a value set withtest.use()reaches only the fixtures.
Returns
- void
debug()
Section titled “debug()”Records a debug entry when the current level is debug. See warn() for what is recorded.
Arguments
messagestring...argsany[]
error()
Section titled “error()”Records an error entry; error is the highest level, so it is always recorded. See warn().
Arguments
messagestring...argsany[]
getCurrentLogLevel()
Section titled “getCurrentLogLevel()”Returns
- LogLevel: the level entries are recorded at.
getCurrentLogLevelIndex()
Section titled “getCurrentLogLevelIndex()”Returns
- number: the current level’s position in
["debug", "info", "warn", "error"],0fordebug.
getNewChildLogger()
Section titled “getNewChildLogger()”Creates a child logger named after this one and prefix. It shares this logger’s entries and level: changing the
level on any logger of the tree changes it for all of them.
Usage
const checkoutLog = log.getNewChildLogger("CheckoutPage");checkoutLog.warn("paying with the test card"); // named [TestCase -> CheckoutPage]Arguments
prefixstring
Returns
- PlaywrightReportLogger
info()
Section titled “info()”Records an info entry when the current level is info or lower. See warn().
Arguments
messagestring...argsany[]
isCurrentLogLevel()
Section titled “isCurrentLogLevel()”Arguments
levelLogLevel
Returns
- boolean: whether
levelis the current level.
isLogLevelEnabled()
Section titled “isLogLevelEnabled()”Returns whether an entry at level would be recorded, for code that should only do work when its entry is.
Usage
if (log.isLogLevelEnabled("debug")) log.debug("cart", await cartText());Arguments
levelLogLevel
Returns
- boolean: whether
levelis the current level or above.
resetLogLevel()
Section titled “resetLogLevel()”Sets the level back to the one the test started with, sharedLogLevel.initial: for the log fixture, warn on a
first run and debug on a retry.
Returns
- void
setLogLevel()
Section titled “setLogLevel()”Sets the level entries are recorded at, for this logger and every logger of its tree, until it is set or reset again.
Usage
log.setLogLevel("debug"); // from here on, everything for this testArguments
levelLogLevel
Returns
- void
warn()
Section titled “warn()”Records a warn entry when the current level is warn or lower: strings as written, any other value as console.log
prints it. See what is attached.
Usage
log.warn("order", { id: 7, total: 42 });// order//// { id: 7, total: 42 }Arguments
-
messagestring -
...argsany[]Further values, attached after the message.
Returns
- void
LogEntry
Section titled “LogEntry”One recorded entry, attached to the test as one attachment.
logLevel
Section titled “logLevel”LogLevel: the level it was logged at.
message
Section titled “message”string: the message and the further arguments, as attached, separated by a blank line.
prefix
Section titled “prefix”string: the name of the logger that logged it, TestCase or TestCase -> CheckoutPage.
timestamp
Section titled “timestamp”Date: when it was logged, in the test process.
LogLevel
Section titled “LogLevel”"debug" | "info" | "warn" | "error", lowest first. A logger records an entry at its current level or above.