diff --git a/config/logs.yml b/config/logs.yml index 204a61b..c7fa7fd 100644 --- a/config/logs.yml +++ b/config/logs.yml @@ -4,6 +4,7 @@ logMainShowField: false upperCaseTable: true userField: editorFk rowExcludeField: logExclude +ignoreSystem: false excludeRegex: '__$' showFields: - name @@ -23,6 +24,7 @@ logs: - itemTag - name: item showField: name + showId: id logFields: - size exclude: diff --git a/lib/model-loader.js b/lib/model-loader.js index c22aab7..8a894f5 100644 --- a/lib/model-loader.js +++ b/lib/model-loader.js @@ -99,7 +99,8 @@ module.exports = class ModelLoader { ]; const globalProps = [ 'userField', - 'rowExcludeField' + 'rowExcludeField', + 'ignoreSystem' ]; for (const [schema, table, tableInfo] of schemaMap) { diff --git a/mylogger.js b/mylogger.js index e78c2f6..bd4153b 100644 --- a/mylogger.js +++ b/mylogger.js @@ -94,7 +94,8 @@ module.exports = class MyLogger { oldInstance = ?, newInstance = ?, changedModelId = ?, - changedModelValue = ?` + changedModelValue = ?, + summaryId = ?` ); logInfo.fetchStmt = await db.prepare( `SELECT id FROM ${sqlTable} @@ -109,7 +110,8 @@ module.exports = class MyLogger { SET originFk = ?, creationDate = ?, oldInstance = ?, - changedModelValue = ? + changedModelValue = ?, + summaryId = ? WHERE id = ?` ); } @@ -271,7 +273,7 @@ module.exports = class MyLogger { } } - async onError(err) { + async handleError(err) { if (!this.isOk) return; this.isOk = false; console.log(`Error: ${err.code}: ${err.message}`); @@ -291,10 +293,6 @@ module.exports = class MyLogger { } } - handleError(err) { - console.error(err); - } - async onBinlog(evt) { //evt.dump(); try { @@ -332,14 +330,16 @@ module.exports = class MyLogger { const table = evt.tableMap[evt.tableId]; const tableName = table.tableName; const tableInfo = this.schemaMap.get(table.parentSchema, tableName); + if (!tableInfo) return; const action = actions[eventName]; - const { rowExcludeField } = tableInfo; + const { rowExcludeField, ignoreSystem } = tableInfo; const changes = []; function isExcluded(row) { - return rowExcludeField && row[rowExcludeField]; + return (rowExcludeField && row[rowExcludeField]) + || (ignoreSystem && row.editorFk == null); } function cast(value, type) { @@ -500,6 +500,7 @@ module.exports = class MyLogger { const isDelete = action == 'delete'; const isUpdate = action == 'update'; const created = new Date(evt.timestamp); + const showId = tableInfo.conf.showId; for (const change of changes) { let newI, oldI; @@ -521,7 +522,7 @@ module.exports = class MyLogger { oldI = change.instance; break; } - + const summaryId = showId ? row[showId] : null; const modelId = row[tableInfo.idName]; const modelValue = change.modelValue ?? null; const oldInstance = oldI ? JSON.stringify(oldI) : null; diff --git a/package.json b/package.json index 4bfba16..8e896cb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mylogger", - "version": "1.1.4", + "version": "1.1.5", "author": "Verdnatura Levante SL", "description": "MySQL and MariaDB logger using binary log", "license": "GPL-3.0",