import { LogLevel, LogRecord, Sink } from "@logtape/logtape"; //#region src/recorder.d.ts /** * A predicate that matches log record properties. * * The first argument is the resolved properties object. The second argument * is the full log record for cases where the predicate needs category, level, * or message context. * * @since 2.2.0 */ type PropertyMatcher = (properties: Readonly>, record: LogRecord) => boolean; /** * A matcher for records collected by a {@link LogRecorder}. * * Object property matching is shallow: every own string key in the matcher * must exist on the record properties and match by value. Most values are * compared with `Object.is()`, `Date` values are compared by timestamp, and * regular expression matcher values match string property values. Use a * {@link PropertyMatcher} when a test needs absence checks or deeper matching. * * @since 2.2.0 */ interface LogRecordMatch { /** * Exact category matcher. A string is matched against the dot-joined * category, while an array is matched segment by segment. A regular * expression is tested against the dot-joined category. */ readonly category?: string | readonly string[] | RegExp; /** * Category prefix matcher. A string is split on dots, while an array is * matched segment by segment. */ readonly categoryPrefix?: string | readonly string[]; /** * Exact severity level matcher. */ readonly level?: LogLevel; /** * Rendered message matcher. String and regular expression matchers are * applied to the rendered message, using the same value rendering as * LogTape's default text formatter. A predicate receives the full record. */ readonly message?: string | RegExp | ((record: LogRecord) => boolean); /** * Raw message matcher. A string record is matched directly. A tagged * template record is matched against the concatenated template strings. */ readonly rawMessage?: string | RegExp; /** * Shallow property matcher or predicate. */ readonly properties?: Readonly> | PropertyMatcher; /** * Full-record predicate for custom checks. */ readonly predicate?: (record: LogRecord) => boolean; } /** * A test recorder for LogTape records. * * @since 2.2.0 */ interface LogRecorder { /** * A sink that appends each received record to {@link LogRecorder.records}. */ readonly sink: Sink; /** * A snapshot of records collected so far, in sink call order. */ readonly records: readonly LogRecord[]; /** * Removes all collected records. */ clear(): void; /** * Returns collected records and clears the recorder. */ take(): readonly LogRecord[]; /** * Finds the first collected record matching the given matcher. * * @param match The matcher to apply. * @returns The first matching record, or `undefined`. */ find(match: LogRecordMatch): LogRecord | undefined; /** * Finds all collected records matching the given matcher. * * @param match The matcher to apply. * @returns All matching records in collection order. */ filter(match: LogRecordMatch): readonly LogRecord[]; /** * Asserts that at least one collected record matches the given matcher. * * @param match The matcher to apply. * @throws {Error} If no matching record exists. */ assertLogged(match: LogRecordMatch): void; /** * Asserts that no collected record matches the given matcher. * * @param match The matcher to apply. * @throws {Error} If a matching record exists. */ assertNotLogged(match: LogRecordMatch): void; } /** * Creates a LogTape test recorder. * * @example * ```ts * import { configure, getLogger, reset } from "@logtape/logtape"; * import { createLogRecorder } from "@logtape/testing/recorder"; * * const recorder = createLogRecorder(); * * try { * await configure({ * sinks: { recorder: recorder.sink }, * loggers: [ * { category: ["my-lib"], lowestLevel: "debug", sinks: ["recorder"] }, * ], * }); * * getLogger(["my-lib"]).info("User {userId} logged in.", { * userId: 123, * }); * * recorder.assertLogged({ * category: ["my-lib"], * level: "info", * message: "User 123 logged in.", * properties: { userId: 123 }, * }); * } finally { * await reset(); * } * ``` * * @returns A recorder with a sink and assertion helpers. * @since 2.2.0 */ declare function createLogRecorder(): LogRecorder; //# sourceMappingURL=recorder.d.ts.map //#endregion export { LogRecordMatch, LogRecorder, PropertyMatcher, createLogRecorder }; //# sourceMappingURL=recorder.d.ts.map