feat(server): created a logger to catch em all

This commit is contained in:
2025-03-03 17:31:54 -06:00
parent 63cd43acca
commit 275502143c
2 changed files with 54 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ import {OpenAPIHono} from "@hono/zod-openapi";
import {serveStatic} from "@hono/node-server/serve-static";
import {logger} from "hono/logger";
import {cors} from "hono/cors";
import {log} from "./services/logger/logger.js";
// custom routes
import scalar from "./services/general/route/scalar.js";
@@ -63,7 +64,7 @@ serve(
port: Number(process.env.VITE_SERVER_PORT),
},
(info) => {
console.log(`Server is running on http://localhost:${info.port}`);
log.info({username: "LST-SYSTEM"}, `Server is running on http://localhost:${info.port}`);
}
);

View File

@@ -0,0 +1,52 @@
import {pino, type Logger} from "pino";
export let logLevel = "info";
const transport = pino.transport({
targets: [
{
target: "pino-pretty",
options: {
colorize: true,
// customPrettifiers: {
// time: (timestamp) => `🕰 ${timestamp}`,
// },
destination: process.stdout.fd,
},
},
{
target: "pino-pretty",
options: {
colorize: false,
destination: "./logs/logs.log",
mkdir: true,
},
},
],
});
export const log = pino(
{
level: process.env.LOG_LEVEL || logLevel,
// formatters: {
// level: (label) => {
// return {level: label.toUpperCase()};
// },
// },
customLevels: {death: 70},
// removes data from the logs that we dont want to be shown :D
redact: {paths: ["email", "password"], remove: true},
},
transport
);
// setTimeout(() => {
// const fun = () => {
// throw Error("Just an error");
// };
// try {
// fun();
// } catch (error) {
// log.error(error, "Somethingbad");
// }
// });