Added Logging

This commit is contained in:
Christian Risi 2025-06-30 11:55:17 +00:00
parent 125409fda3
commit 14bfab994d
2 changed files with 49 additions and 1 deletions

View File

@ -2,4 +2,5 @@ export const PKG = __PKG__
export const DB_PATH = "src/db/db.sqlite"
export const SERVER_PRIVATE_DIR = "src/private"
export const SERVER_PRIVATE_KEY_PATH = `${SERVER_PRIVATE_DIR}/key.pem`
export const SERVER_PUBLIC_KEY_PATH = `${SERVER_PRIVATE_DIR}/pub.pem`
export const SERVER_PUBLIC_KEY_PATH = `${SERVER_PRIVATE_DIR}/pub.pem`
export const DEBUG = import.meta.env.DEV

47
src/lib/utils/logger.ts Normal file
View File

@ -0,0 +1,47 @@
import { DEBUG } from "./constants"
class Logger {
private static initialized = false
constructor(
) {
if (Logger.initialized) {
// UGLY: be specific
throw new Error("Logger has already been initialized")
}
}
public debug(message: any, title?: string) {
if (!DEBUG) {
return
}
if (!title) {
title = "INFO"
}
const currentTime: string = new Date().toLocaleString()
const debugMessage =
`
############################################
${title} DEBUG ${currentTime}
${message}
############################################
`
console.info(
debugMessage
)
}
}
export const logger = new Logger()