diff --git a/src/lib/utils/constants.ts b/src/lib/utils/constants.ts index 4f407e3..c34e3eb 100644 --- a/src/lib/utils/constants.ts +++ b/src/lib/utils/constants.ts @@ -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` \ No newline at end of file +export const SERVER_PUBLIC_KEY_PATH = `${SERVER_PRIVATE_DIR}/pub.pem` +export const DEBUG = import.meta.env.DEV \ No newline at end of file diff --git a/src/lib/utils/logger.ts b/src/lib/utils/logger.ts new file mode 100644 index 0000000..0eb4931 --- /dev/null +++ b/src/lib/utils/logger.ts @@ -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() \ No newline at end of file