Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: module docs for filter stream #5

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions transforms/filter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,67 @@
/**
* # FilterLogLevelStream
*
* A transform stream that filters logs based on their log level.
*
* @example
* ```ts
* import { ConsoleReadableStream } from "@denosaurs/log";
* import { FilterLogLevelStream } from "@denosaurs/log/transforms/filter";
* import { ConsoleWritableStream } from "@denosaurs/log/writables/console";
*
* // Capture logs from the console
* const stream = new ConsoleReadableStream();
* stream
* // Filter out logs with a level of "info" or higher
* .pipeThrough(new FilterLogLevelStream("info"))
* // Write the logs to the console
* .pipeTo(new ConsoleWritableStream());
*
* // Log some messages
* console.log("Hello, world!");
* console.group("Group 1");
* console.debug("Debug message");
* console.groupEnd();
* console.info("Info message");
*
* // Output:
* // Hello, world!
* // Info message
* ```
*
* @module
*/

import { Log, LOG_LEVELS, LogLevel } from "../mod.ts";

/**
* A transform stream that filters logs based on their log level.
*
* @example
* ```ts
* import { ConsoleReadableStream } from "@denosaurs/log";
* import { FilterLogLevelStream } from "@denosaurs/log/transforms/filter";
* import { ConsoleWritableStream } from "@denosaurs/log/writables/console";
*
* // Capture logs from the console
* const stream = new ConsoleReadableStream();
* stream
* // Filter out logs with a level of "info" or higher
* .pipeThrough(new FilterLogLevelStream("info"))
* // Write the logs to the console
* .pipeTo(new ConsoleWritableStream());
*
* // Log some messages
* console.log("Hello, world!");
* console.group("Group 1");
* console.debug("Debug message");
* console.groupEnd();
* console.info("Info message");
*
* // Output:
* // Hello, world!
* // Info message
* ```
*/
export class FilterLogLevelStream<T extends LogLevel>
extends TransformStream<Log> {
Expand Down
Loading