From 14d28bb21dcb0bfde9eeacc77720b9668b3f0295 Mon Sep 17 00:00:00 2001 From: zkldi <20380519+zkldi@users.noreply.github.com> Date: Wed, 10 Nov 2021 04:34:07 +0000 Subject: [PATCH] Set bootInfo: true on all bootInfo requests --- server/src/external/mongo/db.ts | 6 ++++-- server/src/external/redis/redis.ts | 8 +++++--- server/src/lib/email/client.ts | 6 ++++-- server/src/main.ts | 30 ++++++++++++++++++------------ server/src/server/server.ts | 13 +++++++++---- 5 files changed, 40 insertions(+), 23 deletions(-) diff --git a/server/src/external/mongo/db.ts b/server/src/external/mongo/db.ts index 72046d8ac..c7a2e9994 100644 --- a/server/src/external/mongo/db.ts +++ b/server/src/external/mongo/db.ts @@ -51,7 +51,7 @@ if (Environment.nodeEnv === "test") { dbName = `testingdb`; } -logger.info(`Connecting to database ${Environment.mongoUrl}/${dbName}...`); +logger.info(`Connecting to database ${Environment.mongoUrl}/${dbName}...`, { bootInfo: true }); const dbtime = process.hrtime.bigint(); // By default the connectTimeoutMS is 30 seconds. This has been upped to 2 minutes, due to poor performance @@ -63,7 +63,9 @@ export const monkDB = monk(`${Environment.mongoUrl}/${dbName}`, { /* istanbul ignore next */ monkDB .then(() => { - logger.info(`Database connection successful: took ${GetMilisecondsSince(dbtime)}ms`); + logger.info(`Database connection successful: took ${GetMilisecondsSince(dbtime)}ms`, { + bootInfo: true, + }); }) .catch((err) => { logger.crit(err); diff --git a/server/src/external/redis/redis.ts b/server/src/external/redis/redis.ts index 5eae3ef43..a74326d76 100644 --- a/server/src/external/redis/redis.ts +++ b/server/src/external/redis/redis.ts @@ -6,14 +6,14 @@ import { GetMilisecondsSince } from "utils/misc"; const logger = CreateLogCtx(__filename); -logger.verbose("Instantiated Redis Store"); +logger.verbose("Instantiated Redis Store", { bootInfo: true }); export const RedisClient = redis.createClient({ url: `redis://${Environment.redisUrl}`, }); const startConnect = process.hrtime.bigint(); -logger.verbose("Instantiated Redis Client"); +logger.verbose("Instantiated Redis Client", { bootInfo: true }); function EmitCritical() { /* istanbul ignore next */ @@ -27,7 +27,9 @@ function EmitCritical() { const ref = setTimeout(EmitCritical, ONE_MINUTE * 2); RedisClient.on("connect", () => { - logger.info(`Connected to Redis. Took ${GetMilisecondsSince(startConnect)}ms`); + logger.info(`Connected to Redis. Took ${GetMilisecondsSince(startConnect)}ms`, { + bootInfo: true, + }); clearTimeout(ref); }); diff --git a/server/src/lib/email/client.ts b/server/src/lib/email/client.ts index 5063a60ce..3ad3b8c5c 100644 --- a/server/src/lib/email/client.ts +++ b/server/src/lib/email/client.ts @@ -8,7 +8,7 @@ const logger = CreateLogCtx(__filename); let transporter: Transporter | undefined; if (ServerConfig.EMAIL_CONFIG) { - logger.info(`Connecting to email server...`); + logger.info(`Connecting to email server...`, { bootInfo: true }); const conf = ServerConfig.EMAIL_CONFIG; try { @@ -37,7 +37,9 @@ if (ServerConfig.EMAIL_CONFIG) { throw err; } } else { - logger.warn(`No EMAIL_CONFIG present in conf, emails will not be sent from the server.`); + logger.warn(`No EMAIL_CONFIG present in conf, emails will not be sent from the server.`, { + bootInfo: true, + }); } export function SendEmail( diff --git a/server/src/main.ts b/server/src/main.ts index d6a8776a1..1e75407c0 100644 --- a/server/src/main.ts +++ b/server/src/main.ts @@ -17,10 +17,12 @@ import { CloseRedisConnection } from "external/redis/redis"; const logger = CreateLogCtx(__filename); -logger.info(`Booting ${TachiConfig.NAME} - ${FormatVersion()} [ENV: ${Environment.nodeEnv}]`); -logger.info(`Log level is set to ${ServerConfig.LOGGER_CONFIG.LOG_LEVEL}.`); +logger.info(`Booting ${TachiConfig.NAME} - ${FormatVersion()} [ENV: ${Environment.nodeEnv}]`, { + bootInfo: true, +}); +logger.info(`Log level is set to ${ServerConfig.LOGGER_CONFIG.LOG_LEVEL}.`, { bootInfo: true }); -logger.info(`Loading sequence documents...`); +logger.info(`Loading sequence documents...`, { bootInfo: true }); async function RunOnInit() { await InitSequenceDocs(); @@ -52,7 +54,8 @@ let instance: http.Server | https.Server; if (ServerConfig.ENABLE_SERVER_HTTPS) { logger.warn( - "HTTPS Mode is enabled. This should not be used in production, and you should instead run behind a reverse proxy." + "HTTPS Mode is enabled. This should not be used in production, and you should instead run behind a reverse proxy.", + { bootInfo: true } ); const privateKey = fs.readFileSync("./cert/key.pem"); const certificate = fs.readFileSync("./cert/cert.pem"); @@ -60,32 +63,35 @@ if (ServerConfig.ENABLE_SERVER_HTTPS) { const httpsServer = https.createServer({ key: privateKey, cert: certificate }, server); instance = httpsServer.listen(Environment.port); - logger.info(`HTTPS Listening on port ${Environment.port}`); + logger.info(`HTTPS Listening on port ${Environment.port}`, { bootInfo: true }); } else { instance = server.listen(Environment.port); - logger.info(`HTTP Listening on port ${Environment.port}`); + logger.info(`HTTP Listening on port ${Environment.port}`, { bootInfo: true }); } process.on("SIGTERM", () => { - logger.info("SIGTERM Received, closing program."); + logger.info("SIGTERM Received, closing program.", { shutdownInfo: true }); instance.close(async () => { - logger.info("Closing Mongo Database."); + logger.info("Closing Mongo Database.", { shutdownInfo: true }); await monkDB.close(); - logger.info("Closing Redis Connection."); + logger.info("Closing Redis Connection.", { shutdownInfo: true }); CloseRedisConnection(); - logger.info("Everything closed. Waiting for process to exit naturally."); + logger.info("Everything closed. Waiting for process to exit naturally.", { + shutdownInfo: true, + }); }); }); if (process.env.INVOKE_JOB_RUNNER) { - logger.info(`Spawning a tachi-server job runner inline.`); + logger.info(`Spawning a tachi-server job runner inline.`, { bootInfo: true }); if (Environment.nodeEnv === "production") { logger.warn( - `Spawning inline tachi-server job runner in production. Is this actually what you want? You should run a tool like Ofelia to manage this.` + `Spawning inline tachi-server job runner in production. Is this actually what you want? You should run a tool like Ofelia to manage this.`, + { bootInfo: true } ); } diff --git a/server/src/server/server.ts b/server/src/server/server.ts index 77ab39ab0..09b30fd42 100644 --- a/server/src/server/server.ts +++ b/server/src/server/server.ts @@ -41,7 +41,9 @@ const userSessionMiddleware = expressSession({ const app: Express = express(); if (Environment.nodeEnv !== "production" && ServerConfig.CLIENT_DEV_SERVER) { - logger.warn(`Enabling CORS requests from ${ServerConfig.CLIENT_DEV_SERVER}.`); + logger.warn(`Enabling CORS requests from ${ServerConfig.CLIENT_DEV_SERVER}.`, { + bootInfo: true, + }); // Allow CORS requests from another server (since we have our dev server hosted separately). app.use((req, res, next) => { @@ -61,7 +63,9 @@ if (Environment.nodeEnv !== "production" && ServerConfig.CLIENT_DEV_SERVER) { } } else { if (Environment.nodeEnv !== "test") { - logger.info("Enabling Helmet, as no CLIENT_DEV_SERVER was set, or we are in production."); + logger.info("Enabling Helmet, as no CLIENT_DEV_SERVER was set, or we are in production.", { + bootInfo: true, + }); } app.use(helmet()); } @@ -110,10 +114,11 @@ app.use("/", mainRouter); if (ServerConfig.RUN_OWN_CDN) { if (Environment.nodeEnv === "production") { logger.warn( - `Running OWN_CDN in production. Consider making a separate process handle your CDN for performance.` + `Running OWN_CDN in production. Consider making a separate process handle your CDN for performance.`, + { bootInfo: true } ); } else if (Environment.nodeEnv !== "test") { - logger.info(`Running own CDN at ${Environment.cdnRoot}.`); + logger.info(`Running own CDN at ${Environment.cdnRoot}.`, { bootInfo: true }); } app.use("/cdn", express.static(Environment.cdnRoot));