Skip to content

Commit

Permalink
fix(decorators): πŸ‘…πŸ‘…πŸ‘…
Browse files Browse the repository at this point in the history
  • Loading branch information
Kodarru committed Oct 26, 2024
2 parents b043e49 + 0a40a44 commit d092e72
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
13 changes: 6 additions & 7 deletions src/common/Yapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,24 @@ function getDateTime() {
export class Yapper {
constructor() {}
trace(obj) {
if (__DEV__) console.log("\x1b[90;1m Trace\x1b[90;1m \x1b[0;90m", getDateTime(), obj);
if (__DEV__) console.log("\x1b[90;1m TRC\x1b[90;1m \x1b[0;90m", getDateTime(), obj);
}
debug(obj) {
if (__DEV__)
console.log("\x1b[90;1;47m Debug", `\x1b[0m \x1b[90m${getDateTime()}`, obj, "\x1b[0m");
console.log("\x1b[90;1;47m DBG", `\x1b[0m \x1b[90m${getDateTime()}`, obj, "\x1b[0m");
}
info(obj) {
if (__DEV__)
console.log("\x1b[44;1m Info ", `\x1b[0m \x1b[90m${getDateTime()}\x1b[0m`, obj);
if (__DEV__) console.log("\x1b[44;1m INF", `\x1b[0m \x1b[90m${getDateTime()}\x1b[0m`, obj);
}
warn(obj) {
console.log("\x1b[43;1m Warn ", `\x1b[0m \x1b[90m${getDateTime()}\x1b[0m`, obj);
console.log("\x1b[43;1m WRN", `\x1b[0m \x1b[90m${getDateTime()}\x1b[0m`, obj);
}
error(obj) {
console.log("\x1b[41;1m Error", `\x1b[0m \x1b[90m${getDateTime()}\x1b[0m`, obj);
console.log("\x1b[41;1m ERR", `\x1b[0m \x1b[90m${getDateTime()}\x1b[0m`, obj);
}
fatal(obj) {
console.log(
"\x1b[40;31;1m Fatal",
"\x1b[40;31;1m FTL",
`\x1b[0m \x1b[31;1m${getDateTime()}\x1b[0;31m`,
obj,
"\x1b[0m"
Expand Down
15 changes: 9 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { bootstrap } from "fastify-decorators";
import { resolve } from "path";
import { ERROR_HANDLER } from "./common/error.js";
import { Yapper } from "./common/Yapper.js";
import { __DEV__ } from "./common/constants.js";

export const server = fastify({
loggerInstance: new Yapper("a")
Expand All @@ -17,12 +18,14 @@ server.register(bootstrap, {

server.setErrorHandler(ERROR_HANDLER);

server.log.trace("Trace message");
server.log.debug("Debug message");
server.log.info("Info message");
server.log.warn("Warn message");
server.log.error("Error message");
server.log.fatal("I killed myself");
if (__DEV__) {
server.log.trace("Trace message");
server.log.debug("Debug message");
server.log.info("Info message");
server.log.warn("Warn message");
server.log.error("Error message");
server.log.fatal("I killed myself");
}

server.listen({ port: parseInt(process.env.PORT), host: process.env.HOST }, (err, address) => {
if (err) {
Expand Down

0 comments on commit d092e72

Please sign in to comment.