Ver código fonte

refactor: Logs sequelize as debug with category

Owen Diffey 4 meses atrás
pai
commit
e922c35fbe
2 arquivos alterados com 12 adições e 4 exclusões
  1. 6 3
      backend/src/BaseModule.ts
  2. 6 1
      backend/src/modules/DataModule.ts

+ 6 - 3
backend/src/BaseModule.ts

@@ -241,18 +241,21 @@ export default abstract class BaseModule {
 	 *
 	 * @param log - Log message or object
 	 */
-	public log(log: string | Omit<Log, "timestamp" | "category">) {
+	public log(log: string | Omit<Log, "timestamp">) {
 		const {
 			message,
 			type = "info",
-			data = {}
+			data = {},
+			category
 		} = {
 			...(typeof log === "string" ? { message: log } : log)
 		};
 		LogBook.log({
 			message,
 			type,
-			category: `modules.${this.getName()}`,
+			category: `modules.${this.getName()}${
+				category ? `.${category}` : ""
+			}`,
 			data: {
 				moduleName: this._name,
 				...data

+ 6 - 1
backend/src/modules/DataModule.ts

@@ -113,7 +113,12 @@ export class DataModule extends BaseModule {
 			host,
 			port,
 			dialect: "postgres",
-			logging: message => this.log(message)
+			logging: message =>
+				this.log({
+					type: "debug",
+					category: "sql",
+					message
+				})
 		});
 
 		await this._sequelize.authenticate();