Added Logging
This commit is contained in:
parent
125409fda3
commit
14bfab994d
@ -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
47
src/lib/utils/logger.ts
Normal 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()
|
||||
Loading…
x
Reference in New Issue
Block a user