Add local logging to all microservices; auto-create error_log table on startup
Build and Push Docker Images / detect-changes (push) Successful in 9s
Build and Push Docker Images / build-auth-api (push) Successful in 1m3s
Build and Push Docker Images / build-employee-api (push) Successful in 59s
Build and Push Docker Images / build-transit-api (push) Successful in 56s
Build and Push Docker Images / build-error-log-api (push) Successful in 1m4s
Build and Push Docker Images / build-admin-ui (push) Successful in 1m20s
Build and Push Docker Images / build-monitoring-ui (push) Successful in 1m12s
Build and Push Docker Images / deploy-test-node (push) Successful in 3s
Build and Push Docker Images / detect-changes (push) Successful in 9s
Build and Push Docker Images / build-auth-api (push) Successful in 1m3s
Build and Push Docker Images / build-employee-api (push) Successful in 59s
Build and Push Docker Images / build-transit-api (push) Successful in 56s
Build and Push Docker Images / build-error-log-api (push) Successful in 1m4s
Build and Push Docker Images / build-admin-ui (push) Successful in 1m20s
Build and Push Docker Images / build-monitoring-ui (push) Successful in 1m12s
Build and Push Docker Images / deploy-test-node (push) Successful in 3s
This commit is contained in:
+27
-1
@@ -5,6 +5,29 @@ require("dotenv").config();
|
||||
|
||||
const db = require("./db");
|
||||
|
||||
function log(level, message, meta = {}) {
|
||||
const timestamp = new Date().toISOString();
|
||||
console.log(JSON.stringify({ timestamp, level, service: "error_log_api", message, ...meta }));
|
||||
}
|
||||
|
||||
async function ensureErrorLogTable() {
|
||||
try {
|
||||
await db.query(`CREATE SCHEMA IF NOT EXISTS data`);
|
||||
await db.query(`
|
||||
CREATE TABLE IF NOT EXISTS data.errors (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
"date" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
"service" TEXT NOT NULL,
|
||||
partofservice TEXT,
|
||||
error TEXT NOT NULL
|
||||
)
|
||||
`);
|
||||
console.log("Error log table ready");
|
||||
} catch (err) {
|
||||
console.error("Failed to create error log table:", err);
|
||||
}
|
||||
}
|
||||
|
||||
const app = express();
|
||||
app.use(express.json({ limit: "64kb" }));
|
||||
app.use(cors());
|
||||
@@ -186,6 +209,9 @@ app.use(async (err, req, res, _next) => {
|
||||
return res.status(500).json({ error: toFriendlyError(500) });
|
||||
});
|
||||
|
||||
app.listen(PORT, () => console.log(`Error Log API listening on ${PORT}`));
|
||||
app.listen(PORT, async () => {
|
||||
await ensureErrorLogTable();
|
||||
console.log(`Error Log API listening on ${PORT}`);
|
||||
});
|
||||
|
||||
module.exports = app;
|
||||
|
||||
Reference in New Issue
Block a user