Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Logging #3558

Merged
merged 16 commits into from
Jan 17, 2023
1 change: 1 addition & 0 deletions .env.docker
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
LINKFREE_MONGO_CONNECTION_STRING="mongodb://mongodb:27017/linkfree"
NEXT_PUBLIC_GA_MEASUREMENT_ID=""
NEXT_PUBLIC_BASE_URL="http://localhost:3000"
NODE_ENV="development"
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
LINKFREE_MONGO_CONNECTION_STRING="mongodb://localhost:27017/linkfree"
NEXT_PUBLIC_GA_MEASUREMENT_ID=""
NEXT_PUBLIC_BASE_URL="http://localhost:3000"
NODE_ENV="development"
16 changes: 16 additions & 0 deletions config/logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as PinoLogger from "pino";

const config = {
transport: {
target: "pino-pretty",
options: {
colorize: true,
},
},
};

const logger = PinoLogger.pino(
process.env.NODE_ENV === "development" ? config : {}
);

export default logger;
8 changes: 5 additions & 3 deletions config/mongo.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import mongoose from "mongoose";
import * as fs from "fs";

import logger from "../config/logger";

let hasConnection = false;
const connectMongo = async () => {
if (!process.env.LINKFREE_MONGO_CONNECTION_STRING) {
Expand All @@ -21,10 +23,10 @@ const connectMongo = async () => {

await mongoose.connect(process.env.LINKFREE_MONGO_CONNECTION_STRING);
hasConnection = true;
console.log("DB connected");
} catch (err) {
logger.info("MongoDB connected");
} catch (e) {
hasConnection = false;
console.error("DB Not connected", err);
logger.error(e, "DB connection failed");
}
};

Expand Down
Loading