47 lines
770 B
TypeScript
47 lines
770 B
TypeScript
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() |