Skip to content

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.


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

  • sharedLogLevel Object

    • current LogLevel: the level entries are recorded at.
    • initial LogLevel: the level resetLogLevel() goes back to.
  • sharedLogEntry LogEntry[]

    The array the entries are recorded in, in call order.

  • contextName string

    The logger’s name in attachment names.


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

  • testInfo TestInfo

  • format Object (optional)

    • locale string (optional)
    • timeZone string (optional)

    The locale and time zone of the time and date in the names, as toLocaleTimeString takes them; the log fixture passes Playwright’s locale and timezoneId. Each one left out is the project’s use.locale or use.timezoneId from the config, or the machine’s where the config sets none; a value set with test.use() reaches only the fixtures.

Returns

  • void

Records a debug entry when the current level is debug. See warn() for what is recorded.

Arguments

  • message string
  • ...args any[]

Records an error entry; error is the highest level, so it is always recorded. See warn().

Arguments

  • message string
  • ...args any[]

Returns

  • LogLevel: the level entries are recorded at.

Returns

  • number: the current level’s position in ["debug", "info", "warn", "error"], 0 for debug.

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

  • prefix string

Returns

  • PlaywrightReportLogger

Records an info entry when the current level is info or lower. See warn().

Arguments

  • message string
  • ...args any[]

Arguments

Returns

  • boolean: whether level is the current level.

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

Returns

  • boolean: whether level is the current level or above.

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

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 test

Arguments

Returns

  • void

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

  • message string

  • ...args any[]

    Further values, attached after the message.

Returns

  • void

One recorded entry, attached to the test as one attachment.

LogLevel: the level it was logged at.

string: the message and the further arguments, as attached, separated by a blank line.

string: the name of the logger that logged it, TestCase or TestCase -> CheckoutPage.

Date: when it was logged, in the test process.

"debug" | "info" | "warn" | "error", lowest first. A logger records an entry at its current level or above.