diff options
author | Yuqian Yang <crupest@crupest.life> | 2025-06-17 15:14:48 +0800 |
---|---|---|
committer | Yuqian Yang <crupest@crupest.life> | 2025-06-17 21:37:43 +0800 |
commit | e3acdfd274086a183402b2f0c75e54c620bf954a (patch) | |
tree | 6e2ed8a38dcf2d8593f962d3c98f954c8d2c19d3 /deno/base | |
parent | dabfabbe0779b2f530db7351afa99cc38ce40d8f (diff) | |
download | crupest-e3acdfd274086a183402b2f0c75e54c620bf954a.tar.gz crupest-e3acdfd274086a183402b2f0c75e54c620bf954a.tar.bz2 crupest-e3acdfd274086a183402b2f0c75e54c620bf954a.zip |
mail: skip saving if cc myself, mark sent as read.
Diffstat (limited to 'deno/base')
-rw-r--r-- | deno/base/deno.json | 1 | ||||
-rw-r--r-- | deno/base/log.ts | 60 |
2 files changed, 0 insertions, 61 deletions
diff --git a/deno/base/deno.json b/deno/base/deno.json index dabc02a..52baaa5 100644 --- a/deno/base/deno.json +++ b/deno/base/deno.json @@ -5,6 +5,5 @@ ".": "./lib.ts", "./config": "./config.ts", "./cron": "./cron.ts", - "./log": "./log.ts" } } diff --git a/deno/base/log.ts b/deno/base/log.ts deleted file mode 100644 index 940f569..0000000 --- a/deno/base/log.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { join } from "@std/path"; - -import { toFileNameString } from "./lib.ts"; - -export interface ExternalLogStream extends Disposable { - stream: WritableStream; -} - -export class LogFileProvider { - #directory: string; - - constructor(directory: string) { - this.#directory = directory; - Deno.mkdirSync(directory, { recursive: true }); - } - - async createExternalLogStream( - name: string, - options?: { - noTime?: boolean; - }, - ): Promise<ExternalLogStream> { - if (name.includes("/")) { - throw new Error(`External log stream's name (${name}) contains '/'.`); - } - - const logPath = join( - this.#directory, - options?.noTime === true - ? name - : `${name}-${toFileNameString(new Date())}`, - ); - - const file = await Deno.open(logPath, { - read: false, - write: true, - append: true, - create: true, - }); - return { - stream: file.writable, - [Symbol.dispose]: file[Symbol.dispose].bind(file), - }; - } - - async createExternalLogStreamsForProgram( - program: string, - ): Promise<{ stdout: WritableStream; stderr: WritableStream } & Disposable> { - const stdout = await this.createExternalLogStream(`${program}-stdout`); - const stderr = await this.createExternalLogStream(`${program}-stderr`); - return { - stdout: stdout.stream, - stderr: stderr.stream, - [Symbol.dispose]: () => { - stdout[Symbol.dispose](); - stderr[Symbol.dispose](); - }, - }; - } -} |