feat: implement structured logging for server and client

Server:
- Add pino and pino-http for structured logging
- Create @Logged class decorator using Proxy pattern for automatic method logging
- Add pino redact config for sensitive data (password, token, etc.)
- Move AuthMiddleware to controllers folder (per architecture diagram)
- Add LoggingMiddleware for HTTP request logging
- Replace console.log/error with structured logger in controllers and app.ts
- Decorate all repositories and GPTAdapter with @Logged

Client:
- Add react-native-logs with namespaced loggers (apiLogger, storeLogger)
- Add request/response logging to ApiClient with duration tracking
This commit is contained in:
2026-01-10 16:59:40 +01:00
parent 675785ec93
commit 71f84d1cc7
24 changed files with 576 additions and 37 deletions

View File

@@ -3,7 +3,12 @@ import mongoose from "mongoose";
import "dotenv/config";
import { createRoutes } from "./routes";
import { AuthController, ChatController, EventController } from "./controllers";
import {
AuthController,
ChatController,
EventController,
httpLogger,
} from "./controllers";
import { AuthService, ChatService, EventService } from "./services";
import {
MongoUserRepository,
@@ -11,6 +16,7 @@ import {
MongoChatRepository,
} from "./repositories";
import { GPTAdapter } from "./ai";
import { logger } from "./logging";
const app = express();
const port = process.env.PORT || 3000;
@@ -18,6 +24,7 @@ const mongoUri = process.env.MONGODB_URI || "mongodb://localhost:27017/caldav";
// Middleware
app.use(express.json());
app.use(httpLogger);
// CORS - only needed for web browser development
// Native mobile apps don't send Origin headers and aren't affected by CORS
@@ -86,7 +93,7 @@ app.post("/api/ai/test", async (req, res) => {
});
res.json(result);
} catch (error) {
console.error("AI test error:", error);
logger.error({ error }, "AI test error");
res.status(500).json({ error: String(error) });
}
});
@@ -95,13 +102,13 @@ app.post("/api/ai/test", async (req, res) => {
async function start() {
try {
await mongoose.connect(mongoUri);
console.log("Connected to MongoDB");
logger.info("Connected to MongoDB");
app.listen(port, () => {
console.log(`Server running on port ${port}`);
logger.info({ port }, "Server started");
});
} catch (error) {
console.error("Failed to start server:", error);
logger.fatal({ error }, "Failed to start server");
process.exit(1);
}
}