Skip to content

Commit

Permalink
Merge pull request #43 from swoocn/revert-40-backend-logging-framework
Browse files Browse the repository at this point in the history
Self-approved; revert changes.
  • Loading branch information
swoocn committed Apr 6, 2024
2 parents 7dc19c9 + 3d9eafa commit 05c2e59
Show file tree
Hide file tree
Showing 16 changed files with 198 additions and 1,162 deletions.
14 changes: 3 additions & 11 deletions backend/logger.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
const winston = require('winston');
const configureLogging = require('./logging-config');

const initializeLogger = async () => {
try {
const loggingConfig = await configureLogging();
const logger = winston.createLogger(loggingConfig);
return logger;
} catch (error) {
console.error('Error initializing logger:', error);
return null;
}
};
const loggingConfig = configureLogging();
const logger = winston.createLogger(loggingConfig);

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

require('winston-mongodb');

dotenv.config();

const configureLogging = async () => {
// console.log(`VERCEL_ENV: ${process.env.VERCEL_ENV}`);
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 server environment
// determine the logging configuration based on the environment
if (isDevelopment()) {
return {
level: 'debug',
format: winston.format.combine(
winston.format.errors({ stack: true }),
winston.format.cli()
),
format: winston.format.cli(),
transports: [
new winston.transports.Console()
]
};
} else {
await connectDB();

return {
level: 'info',
format: winston.format.combine(
winston.format.errors({ stack: true }),
winston.format.timestamp(), // GMT
winston.format.json()
),
level: 'error',
format: winston.format.cli(),
transports: [
new winston.transports.MongoDB({
db: process.env.MONGODB_URL,
options: {
useNewUrlParser: true,
useUnifiedTopology: true
},
collection: 'serverLogs'
})
new winston.transports.Console()
]
};
}
};
}

module.exports = configureLogging;
16 changes: 0 additions & 16 deletions backend/mongodb.js

This file was deleted.

Loading

0 comments on commit 05c2e59

Please sign in to comment.