Skip to content

Commit 139429b

Browse files
committed
Setup pino logger
1 parent 1dcbf97 commit 139429b

14 files changed

Lines changed: 142 additions & 20 deletions

File tree

apps/server/env.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import { z } from "zod";
2+
import { createLogger } from "@livedot/logger";
3+
4+
const log = createLogger("env");
25

36
const envSchema = z.object({
47
NODE_ENV: z.enum(["development", "production", "test"]).default("development"),
@@ -30,8 +33,7 @@ const envSchema = z.object({
3033
const parsed = envSchema.safeParse(process.env);
3134

3235
if (!parsed.success) {
33-
console.error("Invalid environment variables:");
34-
console.error(parsed.error.flatten().fieldErrors);
36+
log.error(parsed.error.flatten().fieldErrors, "Invalid environment variables");
3537
process.exit(1);
3638
}
3739

apps/server/geo.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { resolve, dirname } from "path";
22
import { fileURLToPath } from "url";
33
import { existsSync, readFileSync } from "fs";
4+
import { createLogger } from "@livedot/logger";
45

6+
const log = createLogger("geo");
57
const __dirname = dirname(fileURLToPath(import.meta.url));
68

79
const DB_PATH =
@@ -14,10 +16,10 @@ let mmdbReader: import("mmdb-lib").Reader<Record<string, any>> | null = null;
1416
if (existsSync(DB_PATH)) {
1517
const { Reader } = await import("mmdb-lib");
1618
mmdbReader = new Reader(readFileSync(DB_PATH));
17-
console.log("[geo] Using GeoLite2-City (high accuracy)");
19+
log.info("Using GeoLite2-City (high accuracy)");
1820
} else {
19-
console.log("[geo] GeoLite2-City.mmdb not found — using fast-geoip (lower accuracy)");
20-
console.log("[geo] For better accuracy run: MAXMIND_LICENSE_KEY=<key> bun geo:download");
21+
log.warn("GeoLite2-City.mmdb not found — using fast-geoip (lower accuracy)");
22+
log.info("For better accuracy run: MAXMIND_LICENSE_KEY=<key> bun geo:download");
2123
}
2224

2325
let publicIp: string | null = null;

apps/server/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { Hono } from "hono";
22
import type { Server } from "bun";
3+
import { createLogger } from "@livedot/logger";
34
import { env } from "./env";
5+
6+
const log = createLogger("server");
47
import { db } from "@livedot/db";
58
import { websites } from "@livedot/db/schema";
69
import { auth } from "./auth";
@@ -50,7 +53,7 @@ export async function reloadWebsiteCache() {
5053
await loadWebsiteCache();
5154
}
5255

53-
loadWebsiteCache().catch(console.error);
56+
loadWebsiteCache().catch((err) => log.error(err, "Failed to load website cache"));
5457

5558
// Hono app
5659
const app = new Hono();
@@ -115,4 +118,4 @@ const server = Bun.serve({
115118
_server = server;
116119
startTick(getServer);
117120

118-
console.log(`Server running at ${server.url}`);
121+
log.info(`Server running at ${server.url}`);

apps/server/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
},
99
"dependencies": {
1010
"@livedot/db": "workspace:*",
11+
"@livedot/logger": "workspace:*",
1112
"@livedot/shared": "workspace:*",
1213
"@livedot/store": "workspace:*",
1314
"drizzle-orm": "^0.45.1",

apps/server/routes/auth.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ import { Hono } from "hono";
22
import { count, eq } from "drizzle-orm";
33
import { db } from "@livedot/db";
44
import { user, account } from "@livedot/db/schema";
5+
import { createLogger } from "@livedot/logger";
56
import { auth } from "../auth";
67
import { env } from "../env";
78
import { getSessionFromRequest } from "../middleware/auth";
89
import { defaultPlan } from "../limits";
910

11+
const log = createLogger("auth");
12+
1013
const otpStore = new Map<string, { otp: string; expires: number }>();
1114

1215
async function getUserCount() {
@@ -146,7 +149,7 @@ export const authRoutes = new Hono()
146149

147150
const otp = Math.floor(100000 + Math.random() * 900000).toString();
148151
otpStore.set(username, { otp, expires: Date.now() + 10 * 60 * 1000 });
149-
console.log(`\n[Livedot] Password reset OTP for "${username}": ${otp}\n`);
152+
log.info({ username, otp }, "Password reset OTP generated");
150153
return c.json({ ok: true });
151154
})
152155

apps/server/sessions.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ import type { Server } from "bun";
22
import type { VisitorSession, WSMessage, HistoryPoint, ActivityEvent } from "@livedot/shared";
33
import type { StoreAdapter } from "@livedot/store";
44
import { MemoryStore } from "@livedot/store";
5+
import { createLogger } from "@livedot/logger";
56
import { websiteCache } from "./website-cache";
67
import { env } from "./env";
78

9+
const log = createLogger("store");
10+
811
export { type VisitorSession, type WSMessage, type HistoryPoint, type ActivityEvent };
912

1013
const SESSION_TIMEOUT = 10_000;
@@ -17,10 +20,10 @@ let store: StoreAdapter;
1720
if (env.REDIS_URL) {
1821
const { RedisStore } = await import("@livedot/store/redis");
1922
store = new RedisStore(env.REDIS_URL);
20-
console.log("[store] Using Redis");
23+
log.info("Using Redis");
2124
} else {
2225
store = new MemoryStore();
23-
console.log("[store] Using in-memory");
26+
log.info("Using in-memory");
2427
}
2528

2629
export { store };

apps/www/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
"@tailwindcss/vite": "^4.2.2",
1919
"tailwindcss": "^4.2.2"
2020
}
21-
}
21+
}

apps/www/src/components/Header.astro

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
---
2+
interface Props {
3+
pathname?: string;
4+
}
5+
6+
const { pathname = "/" } = Astro.props;
7+
const isHomePage = pathname === "/";
8+
const sectionPrefix = isHomePage ? "" : "/";
9+
210
const navLinks = [
3-
{ label: "Features", href: "#features" },
4-
{ label: "Installation", href: "#installation" },
5-
{ label: "FAQ", href: "#faq" },
11+
{ label: "Features", href: `${sectionPrefix}#features`, sectionId: "features" },
12+
{ label: "Installation", href: `${sectionPrefix}#installation`, sectionId: "installation" },
13+
{ label: "Pricing", href: "/pricing" },
14+
{ label: "FAQ", href: `${sectionPrefix}#faq`, sectionId: "faq" },
615
{ label: "GitHub", href: "https://github.com/mxvsh/livedot", external: true },
716
];
817
---
918

1019
<header class="fixed inset-x-0 top-0 z-50 border-b border-white/5 bg-surface/80 backdrop-blur-md">
1120
<nav class="mx-auto flex h-20 max-w-7xl items-center justify-between px-6">
12-
<a href="#" class="flex items-center gap-3 text-lg font-bold text-primary md:text-xl">
21+
<a href="/" class="flex items-center gap-3 text-lg font-bold text-primary md:text-xl">
1322
<img src="/logo.svg" alt="Livedot logo" class="h-8 w-8 rounded-md" />
1423
<span class="brand-wordmark">livedot</span>
1524
</a>
@@ -18,12 +27,14 @@ const navLinks = [
1827
{navLinks.map((link) => (
1928
<a
2029
href={link.href}
21-
data-section-link={link.external ? undefined : link.href.slice(1)}
30+
data-section-link={isHomePage && link.sectionId ? link.sectionId : undefined}
31+
aria-current={pathname === link.href ? "page" : undefined}
2232
class:list={[
2333
"border-b-2 pb-1 transition-colors",
2434
link.external
2535
? "border-transparent text-on-surface-variant hover:text-white"
2636
: "border-transparent text-on-surface-variant hover:text-white",
37+
pathname === link.href ? "border-primary text-primary" : "",
2738
]}
2839
>
2940
{link.label}

apps/www/src/pages/index.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import MainLayout from "../layouts/MainLayout.astro";
99
---
1010

1111
<MainLayout title="Livedot - Real-time User Visualization" pathname={Astro.url.pathname}>
12-
<Header />
12+
<Header pathname={Astro.url.pathname} />
1313
<main>
1414
<HeroSection />
1515
<FeaturesSection />

0 commit comments

Comments
 (0)