Skip to content

Commit 012345c

Browse files
committed
feat: add logging
1 parent c54e6e4 commit 012345c

File tree

15 files changed

+85
-4
lines changed

15 files changed

+85
-4
lines changed

.env.defaults

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
# Comma separated set of string keys to use for signing cookies
2-
KEY_STACK_KEYS=kview
2+
KEY_STACK_KEYS=kview
3+
# The logging level for the application
4+
# Possible values: debug, info, warning, error, fatal
5+
LOG_LEVEL=info

build.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
import "@std/dotenv/load";
12
import { defineConfig } from "$fresh/server.ts";
23
import tailwind from "$fresh/plugins/tailwind.ts";
34
import svg_minify from "@kitsonk/svg-minify";
45
import zipBuild from "./zip_build.plugin.ts";
56

7+
const port = Deno.env.has("PORT") ? parseInt(Deno.env.get("PORT")!, 10) : undefined;
8+
69
export default defineConfig({
10+
server: { port },
711
plugins: [tailwind(), svg_minify(), zipBuild()],
812
});

fresh.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { defineConfig } from "$fresh/server.ts";
22
import tailwind from "$fresh/plugins/tailwind.ts";
33

4+
const port = Deno.env.has("PORT") ? parseInt(Deno.env.get("PORT")!, 10) : undefined;
5+
46
export default defineConfig({
7+
server: { port },
58
plugins: [tailwind()],
69
});

routes/api/blob/download/[id]/[...path].ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import { type Handlers } from "$fresh/server.ts";
22
import { pathToKey } from "$utils/kv.ts";
33
import { getKv } from "$utils/kv_state.ts";
4+
import { getLogger } from "@logtape/logtape";
5+
6+
const logger = getLogger(["kview", "api", "blob", "download"]);
47

58
export const handler: Handlers = {
69
async GET(_req, { params: { id, path } }) {
10+
logger.debug("GET: {id}:{path}", { id, path });
711
const key = path === "" ? [] : pathToKey(path);
812
const kv = await getKv(id);
913
return kv.getAsBlob(key, { response: true, contentDisposition: true });

routes/api/blob/serve/[id]/[...path].ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import { type Handlers } from "$fresh/server.ts";
22
import { pathToKey } from "$utils/kv.ts";
33
import { getKv } from "$utils/kv_state.ts";
4+
import { getLogger } from "@logtape/logtape";
5+
6+
const logger = getLogger(["kview", "api", "blob", "serve"]);
47

58
export const handler: Handlers = {
69
async GET(_req, { params: { id, path } }) {
10+
logger.debug("GET: {id}:{path}", { id, path });
711
const key = path === "" ? [] : pathToKey(path);
812
const kv = await getKv(id);
913
return kv.getAsBlob(key, { response: true });

routes/api/jobs/[id].ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
import { type Handlers } from "$fresh/server.ts";
22
import { abort, getJob } from "$utils/kv_bulk.ts";
3+
import { getLogger } from "@logtape/logtape";
4+
5+
const logger = getLogger(["kview", "api", "jobs", "id"]);
36

47
export const handler: Handlers = {
58
GET(_req, { params: { id } }) {
9+
logger.debug("GET: {id}", { id });
610
const job = getJob(parseInt(id, 10));
711
if (job) {
812
return Response.json({ status: 200, statusText: "OK", job });
913
}
14+
logger.info("Not Found: {id}", { id });
1015
return Response.json({ status: 404, statusText: "Not Found", id }, {
1116
status: 404,
1217
statusText: "Not Found",
1318
});
1419
},
1520
DELETE(_req, { params: { id } }) {
21+
logger.debug("DELETE: {id}", { id });
1622
if (abort(parseInt(id, 10))) {
1723
return Response.json({ status: 200, statusText: "OK", id });
1824
}
25+
logger.info("Not Found: {id}", { id });
1926
return Response.json({ status: 404, statusText: "Not Found", id }, {
2027
status: 404,
2128
statusText: "Not Found",

routes/api/jobs/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import { type Handlers } from "$fresh/server.ts";
22
import { getJobs } from "$utils/kv_bulk.ts";
3+
import { getLogger } from "$utils/logs.ts";
4+
5+
const logger = getLogger(["kview", "api", "jobs"]);
36

47
export const handler: Handlers = {
58
GET(_req, _ctx) {
9+
logger.debug("GET");
610
return Response.json({ status: 200, statusText: "OK", jobs: getJobs() });
711
},
812
};

routes/api/kv/[id]/[...path].ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export const handler: Handlers = {
7373
}
7474
},
7575
async PUT(req, { params: { id, path = "" } }) {
76+
logger.debug("PUT: {id}:{path}", { id, path });
7677
try {
7778
const key = pathToKey(path);
7879
const kv = await getKv(id);

routes/api/kv/[id]/_bulk/[...path].ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,21 @@ export const handler: Handlers = {
4545
const name = req.headers.get("kview-name");
4646
const href = req.headers.get("kview-href");
4747
const data = await req.bytes();
48-
logger.debug("Importing: {id}:{path}", { id, path });
48+
logger.debug("start: {id}:{path} overwrite: {overwrite}, name: {name}, href: {href}", {
49+
id,
50+
path,
51+
overwrite,
52+
name,
53+
href,
54+
});
4955
const job = await importNdJson(id, prefix, data, { overwrite, name, href });
5056
if (!job) {
57+
logger.info("Not Found: {id}:{path}, name: {name}, href: {href}", { id, path, name, href });
5158
return Response.json({ status: 404, statusText: "Not Found" }, {
5259
status: 404,
5360
statusText: "Not Found",
5461
});
5562
}
56-
logger.info("Created job: {id}", { id: job.id });
5763
return Response.json({ status: 201, statusText: "Created", id: job.id }, {
5864
status: 201,
5965
statusText: "Created",

routes/api/local/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { type Handlers } from "$fresh/server.ts";
22
import { keys, mergeHeaders, SecureCookieMap, STORE_NAMES } from "$utils/cookies.ts";
33
import { LOCAL_STORES, localStores } from "$utils/kv.ts";
44
import { state } from "$utils/state.ts";
5+
import { getLogger } from "$utils/logs.ts";
6+
7+
const logger = getLogger(["kview", "api", "local"]);
58

69
async function setName(
710
value: string,
@@ -24,6 +27,7 @@ async function setName(
2427
export const handler: Handlers = {
2528
async POST(req) {
2629
const [id, value]: [string, string] = await req.json();
30+
logger.debug("POST: {id} = {value}", { id, value });
2731
const cookies = await setName(value, id, req);
2832
return new Response(null, {
2933
status: 204,
@@ -39,6 +43,12 @@ export const handler: Handlers = {
3943
previousPath?: string;
4044
name?: string;
4145
} = await req.json();
46+
logger.debug("PUT: {id} = {name}, path: {path}, previousPath: {previousPath}", {
47+
id,
48+
name,
49+
path,
50+
previousPath,
51+
});
4252
if (path) {
4353
const { isFile } = await Deno.stat(path);
4454
if (isFile) {
@@ -75,6 +85,7 @@ export const handler: Handlers = {
7585
async DELETE(req) {
7686
try {
7787
const { path }: { path: string } = await req.json();
88+
logger.debug("DELETE: {path}", { path });
7889
const localStoresString = localStorage.getItem(LOCAL_STORES);
7990
if (localStoresString) {
8091
const stores: string[] = JSON.parse(localStoresString);

0 commit comments

Comments
 (0)