Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented Backend logging framework #12

Merged
merged 13 commits into from
Mar 24, 2024
3 changes: 2 additions & 1 deletion backend/.env
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
JWT_SECRET="MAP_OF_PI"
PLATFORM_API_URL=https://api.minepi.com
PI_API_KEY=iyzjmicgaza9bh2nmqy6vjceyl7rdrpn94h4vdxxdog3inkf6vt96dfoqanfim1m
VERCEL_ENV=localhost
MONGODB_URL=mongodb+srv://mapofpi:mapofpi@mapofpi.vibqtx2.mongodb.net/mapofpiDB?retryWrites=true&w=majority
PORT=8000
FRONTEND_URL=http://localhost:4200
MAP_OF_PI_URL1=https://mapofpi9975.pinet.com/
MAP_OF_PI_URL2=https://mapofpi.com/
MAP_OF_PI_URL2=https://mapofpi.com/
15 changes: 15 additions & 0 deletions backend/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
plugins: [
'jest',
],
// Utilize the extendable recommended configurations
extends: [
// 'eslint:recommended',
'plugin:node/recommended',
'plugin:jest/recommended'
],
rules: {
'node/no-unsupported-features/es-syntax': ['error', { version: '>=20.0.0' }]
}
};

7 changes: 7 additions & 0 deletions backend/logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const winston = require('winston');
const configureLogging = require('./logging-config');

const loggingConfig = configureLogging();
const logger = winston.createLogger(loggingConfig);

module.exports = logger;
34 changes: 34 additions & 0 deletions backend/logging-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const dotenv = require("dotenv");
const winston = require('winston');

dotenv.config();

const configureLogging = () => {
console.log(`VERCEL_ENV: ${process.env.VERCEL_ENV}`);

// check if the app is running in localhost mode or sandbox
const isDevelopment = () => {
return process.env.VERCEL_ENV === "localhost" || process.env.VERCEL_ENV === "sandbox";
};

// determine the logging configuration based on the environment
if (isDevelopment()) {
return {
level: 'debug',
format: winston.format.cli(),
transports: [
new winston.transports.Console()
]
};
} else {
return {
level: 'error',
format: winston.format.cli(),
transports: [
new winston.transports.Console()
]
};
}
}

module.exports = configureLogging;
Loading
Loading