aboutsummaryrefslogtreecommitdiff
path: root/deno/base
diff options
context:
space:
mode:
Diffstat (limited to 'deno/base')
-rw-r--r--deno/base/config.ts2
-rw-r--r--deno/base/deno.json3
-rw-r--r--deno/base/lib.ts (renamed from deno/base/date.ts)4
-rw-r--r--deno/base/log.ts66
-rw-r--r--deno/base/text.ts3
5 files changed, 13 insertions, 65 deletions
diff --git a/deno/base/config.ts b/deno/base/config.ts
index 8fce1d8..a5f5d86 100644
--- a/deno/base/config.ts
+++ b/deno/base/config.ts
@@ -1,4 +1,4 @@
-import { camelCaseToKebabCase } from "./text.ts";
+import { camelCaseToKebabCase } from "./lib.ts";
export interface ConfigDefinitionItem {
readonly description: string;
diff --git a/deno/base/deno.json b/deno/base/deno.json
index 2c2d550..dabc02a 100644
--- a/deno/base/deno.json
+++ b/deno/base/deno.json
@@ -2,10 +2,9 @@
"name": "@crupest/base",
"version": "0.1.0",
"exports": {
+ ".": "./lib.ts",
"./config": "./config.ts",
"./cron": "./cron.ts",
- "./date": "./date.ts",
- "./text": "./text.ts",
"./log": "./log.ts"
}
}
diff --git a/deno/base/date.ts b/deno/base/lib.ts
index e65691e..a5e4a6a 100644
--- a/deno/base/date.ts
+++ b/deno/base/lib.ts
@@ -1,3 +1,7 @@
+export function camelCaseToKebabCase(str: string): string {
+ return str.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase());
+}
+
export function toFileNameString(date: Date, dateOnly?: boolean): string {
const str = date.toISOString();
return dateOnly === true
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())}`,
diff --git a/deno/base/text.ts b/deno/base/text.ts
deleted file mode 100644
index f3e4020..0000000
--- a/deno/base/text.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-export function camelCaseToKebabCase(str: string): string {
- return str.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase());
-}