improve logging api

This commit is contained in:
Matthieu Jolimaitre 2024-02-05 01:33:10 +01:00
parent ebc9230743
commit bfb53d5c64
6 changed files with 7 additions and 7 deletions

View file

@ -10,7 +10,7 @@ import {
SlashCommandStringOption, SlashCommandStringOption,
} from "npm:discord.js@14.14.1"; } from "npm:discord.js@14.14.1";
import { channel, log_from, SimpleResult, split_promise } from "./utils.ts"; import { channel, log_from, SimpleResult, split_promise } from "./utils.ts";
const log = (...args: unknown[]) => log_from(import.meta.url, ...args); const log = log_from(import.meta.url);
/** /**
* Wraps a discord bot and implements required actions. * Wraps a discord bot and implements required actions.

View file

@ -1,6 +1,6 @@
import { z } from "https://deno.land/x/zod@v3.22.4/mod.ts"; import { z } from "https://deno.land/x/zod@v3.22.4/mod.ts";
import { log_from } from "./utils.ts"; import { log_from } from "./utils.ts";
const log = (...args: unknown[]) => log_from(import.meta.url, ...args); const log = log_from(import.meta.url);
/** /**
* Wraps the CRI API. * Wraps the CRI API.

View file

@ -1,6 +1,6 @@
import { ClientOptions, SMTPClient } from "https://deno.land/x/denomailer@1.6.0/mod.ts"; import { ClientOptions, SMTPClient } from "https://deno.land/x/denomailer@1.6.0/mod.ts";
import { log_from } from "./utils.ts"; import { log_from } from "./utils.ts";
const log = (...args: unknown[]) => log_from(import.meta.url, ...args); const log = log_from(import.meta.url);
export type EmailerConfig = { export type EmailerConfig = {
hostname: string; hostname: string;

View file

@ -7,7 +7,7 @@ import { EpitlsBot } from "./bot.ts";
import { CriApi } from "./cri.ts"; import { CriApi } from "./cri.ts";
import { Emailer } from "./email.ts"; import { Emailer } from "./email.ts";
import { WebVerifier } from "./verifier.ts"; import { WebVerifier } from "./verifier.ts";
const log = (...args: unknown[]) => log_from(import.meta.url, ...args); const log = log_from(import.meta.url);
async function main() { async function main() {
const conf = await read_conf(root_path() + "/conf.json"); const conf = await read_conf(root_path() + "/conf.json");

View file

@ -51,10 +51,10 @@ export type Resolver<T> = (item: T) => void;
/** /**
* Logging function factory. * Logging function factory.
*/ */
export function log_from(url: string, ...args: unknown[]) { export function log_from(url: string) {
const date = new Date().toLocaleString("fr-FR"); const date = new Date().toLocaleString("fr-FR");
const file = path.basename(new URL(url).pathname); const file = path.basename(new URL(url).pathname);
console.log(`[${date}][epitls][${file}]`, ...args); return (...args: unknown[]) => console.log(`[${date}][epitls][${file}]`, ...args);
} }
export type Conf = Awaited<ReturnType<typeof read_conf>>; export type Conf = Awaited<ReturnType<typeof read_conf>>;

View file

@ -1,6 +1,6 @@
import { v1 as uuid } from "https://deno.land/std@0.213.0/uuid/mod.ts"; import { v1 as uuid } from "https://deno.land/std@0.213.0/uuid/mod.ts";
import { channel, log_from, Resolver, SimpleResult, split_promise, wait } from "./utils.ts"; import { channel, log_from, Resolver, SimpleResult, split_promise, wait } from "./utils.ts";
const log = (...args: unknown[]) => log_from(import.meta.url, ...args); const log = log_from(import.meta.url);
export type WebVerifierConf = { export type WebVerifierConf = {
port: number; port: number;