feat(logger): setup logger with discord and db logging
This commit is contained in:
@@ -7,13 +7,22 @@ import path, { dirname, join } from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
import { db } from "./pkg/db/db.js";
|
||||
import { settings } from "./pkg/db/schema/settings.js";
|
||||
import { env } from "./pkg/utils/envValidator.js";
|
||||
import { createLogger } from "./pkg/logger/logger.js";
|
||||
|
||||
const PORT = Number(process.env.VITE_PORT) || 4200;
|
||||
const PORT = Number(env.VITE_PORT) || 4200;
|
||||
|
||||
const main = async () => {
|
||||
//create the logger
|
||||
const log = createLogger({ module: "system", subModule: "main start" });
|
||||
|
||||
// base path
|
||||
let basePath: string = "";
|
||||
if (process.env.NODE_ENV?.trim() !== "production") {
|
||||
|
||||
if (
|
||||
process.env.NODE_ENV?.trim() !== "production" &&
|
||||
!env.RUNNING_IN_DOCKER
|
||||
) {
|
||||
basePath = "/lst";
|
||||
}
|
||||
|
||||
@@ -24,7 +33,11 @@ const main = async () => {
|
||||
try {
|
||||
const set = await db.select().from(settings);
|
||||
|
||||
console.log(set);
|
||||
if (set.length === 0) {
|
||||
return log.fatal(
|
||||
"Seems like the DB is not setup yet the app will close now"
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error getting settings", error);
|
||||
}
|
||||
@@ -63,13 +76,16 @@ const main = async () => {
|
||||
|
||||
// start the server up
|
||||
server.listen(PORT, "0.0.0.0", () =>
|
||||
console.log(
|
||||
`Server running in ${process.env.NODE_ENV}, on http://0.0.0.0:${PORT}${basePath}`
|
||||
log.info(
|
||||
`Server running in ${
|
||||
process.env.NODE_ENV ? process.env.NODE_ENV : "dev"
|
||||
}, on http://0.0.0.0:${PORT}${basePath}`
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
main().catch((err) => {
|
||||
console.error("Startup error:", err);
|
||||
const log = createLogger({ module: "system", subModule: "main start" });
|
||||
log.fatal("Startup error:", err);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user