aboutsummaryrefslogtreecommitdiff
path: root/deno/base/log.ts
diff options
context:
space:
mode:
Diffstat (limited to 'deno/base/log.ts')
-rw-r--r--deno/base/log.ts66
1 files changed, 7 insertions, 59 deletions
diff --git a/deno/base/log.ts b/deno/base/log.ts
index cc71dfa..940f569 100644
--- a/deno/base/log.ts
+++ b/deno/base/log.ts
@@ -1,66 +1,17 @@
import { join } from "@std/path";
-import { toFileNameString } from "./date.ts";
-
-export type LogLevel = "error" | "warn" | "info";
-
-export interface LogOptions {
- level?: LogLevel;
- cause?: unknown;
-}
+import { toFileNameString } from "./lib.ts";
export interface ExternalLogStream extends Disposable {
stream: WritableStream;
}
-export class Logger {
- #defaultLevel = "info" as const;
- #externalLogDir?: string;
-
- get externalLogDir() {
- return this.#externalLogDir;
- }
-
- set externalLogDir(value: string | undefined) {
- this.#externalLogDir = value;
- if (value != null) {
- Deno.mkdirSync(value, {
- recursive: true,
- });
- }
- }
-
- write(message: string, options?: LogOptions): void {
- const logFunction = console[options?.level ?? this.#defaultLevel];
- if (options?.cause != null) {
- logFunction.call(console, message, options.cause);
- } else {
- logFunction.call(console, message);
- }
- }
-
- info(message: string) {
- this.write(message, { level: "info" });
- }
-
- tagInfo(tag: string, message: string) {
- this.info(tag + " " + message);
- }
-
- warn(message: string) {
- this.write(message, { level: "warn" });
- }
+export class LogFileProvider {
+ #directory: string;
- tagWarn(tag: string, message: string) {
- this.warn(tag + " " + message);
- }
-
- error(message: string, cause?: unknown) {
- this.write(message, { level: "info", cause });
- }
-
- tagError(tag: string, message: string, cause?: unknown) {
- this.error(tag + " " + message, cause);
+ constructor(directory: string) {
+ this.#directory = directory;
+ Deno.mkdirSync(directory, { recursive: true });
}
async createExternalLogStream(
@@ -72,12 +23,9 @@ export class Logger {
if (name.includes("/")) {
throw new Error(`External log stream's name (${name}) contains '/'.`);
}
- if (this.#externalLogDir == null) {
- throw new Error("External log directory is not set.");
- }
const logPath = join(
- this.#externalLogDir,
+ this.#directory,
options?.noTime === true
? name
: `${name}-${toFileNameString(new Date())}`,