feat: use logger

This commit is contained in:
2023-08-05 22:16:14 +02:00
parent 46cd823b6c
commit 32a7f89309
15 changed files with 99 additions and 37 deletions

9
lib/cache/cache.ts vendored
View File

@ -5,11 +5,14 @@ import {
RedisConnectOptions,
RedisValue,
} from "https://deno.land/x/redis@v0.31.0/mod.ts";
import { createLogger } from "@lib/log.ts";
const REDIS_HOST = Deno.env.get("REDIS_HOST");
const REDIS_PASS = Deno.env.get("REDIS_PASS") || "";
const REDIS_PORT = Deno.env.get("REDIS_PORT");
const log = createLogger("cache");
async function createCache<T>(): Promise<Redis> {
if (REDIS_HOST) {
const conf: RedisConnectOptions = {
@ -22,10 +25,10 @@ async function createCache<T>(): Promise<Redis> {
}
try {
const client = await connect(conf);
console.log("[redis] connected");
log.info("redis connected");
return client;
} catch (_err) {
console.log("[cache] cant connect to redis, falling back to mock");
log.info("cant connect to redis, falling back to mock");
}
}
@ -94,7 +97,7 @@ export async function set<T extends RedisValue>(
content: T,
options?: RedisOptions,
) {
console.log("[cache] storing ", { id });
log.debug("storing ", { id });
const res = await cache.set(id, content);
if (options?.expires) {
await expire(id, options.expires);

4
lib/cache/image.ts vendored
View File

@ -1,6 +1,7 @@
import { hash } from "@lib/string.ts";
import * as cache from "@lib/cache/cache.ts";
import { ImageMagick } from "https://deno.land/x/imagemagick_deno@0.0.25/mod.ts";
import { createLogger } from "@lib/log.ts";
type ImageCacheOptions = {
url: string;
@ -10,6 +11,7 @@ type ImageCacheOptions = {
};
const CACHE_KEY = "images";
const log = createLogger("cache/image");
function getCacheKey({ url: _url, width, height }: ImageCacheOptions) {
const url = new URL(_url);
@ -63,7 +65,7 @@ export async function setImage(
const imageCorrect = await verifyImage(clone);
if (!imageCorrect) {
console.log("[cache/image] failed to store image", { url });
log.info("failed to store image", { url });
return;
}