Merge branch 'master' into 6533_myLogger_salix
gitea/mylogger/pipeline/pr-master This commit looks good Details

This commit is contained in:
Javier Segarra 2025-01-17 23:38:40 +01:00
commit 970744c3b1
4 changed files with 16 additions and 12 deletions

View File

@ -4,6 +4,7 @@ logMainShowField: false
upperCaseTable: true upperCaseTable: true
userField: editorFk userField: editorFk
rowExcludeField: logExclude rowExcludeField: logExclude
ignoreSystem: false
excludeRegex: '__$' excludeRegex: '__$'
showFields: showFields:
- name - name
@ -23,6 +24,7 @@ logs:
- itemTag - itemTag
- name: item - name: item
showField: name showField: name
showId: id
logFields: logFields:
- size - size
exclude: exclude:

View File

@ -99,7 +99,8 @@ module.exports = class ModelLoader {
]; ];
const globalProps = [ const globalProps = [
'userField', 'userField',
'rowExcludeField' 'rowExcludeField',
'ignoreSystem'
]; ];
for (const [schema, table, tableInfo] of schemaMap) { for (const [schema, table, tableInfo] of schemaMap) {

View File

@ -94,7 +94,8 @@ module.exports = class MyLogger {
oldInstance = ?, oldInstance = ?,
newInstance = ?, newInstance = ?,
changedModelId = ?, changedModelId = ?,
changedModelValue = ?` changedModelValue = ?,
summaryId = ?`
); );
logInfo.fetchStmt = await db.prepare( logInfo.fetchStmt = await db.prepare(
`SELECT id FROM ${sqlTable} `SELECT id FROM ${sqlTable}
@ -109,7 +110,8 @@ module.exports = class MyLogger {
SET originFk = ?, SET originFk = ?,
creationDate = ?, creationDate = ?,
oldInstance = ?, oldInstance = ?,
changedModelValue = ? changedModelValue = ?,
summaryId = ?
WHERE id = ?` WHERE id = ?`
); );
} }
@ -271,7 +273,7 @@ module.exports = class MyLogger {
} }
} }
async onError(err) { async handleError(err) {
if (!this.isOk) return; if (!this.isOk) return;
this.isOk = false; this.isOk = false;
console.log(`Error: ${err.code}: ${err.message}`); console.log(`Error: ${err.code}: ${err.message}`);
@ -291,10 +293,6 @@ module.exports = class MyLogger {
} }
} }
handleError(err) {
console.error(err);
}
async onBinlog(evt) { async onBinlog(evt) {
//evt.dump(); //evt.dump();
try { try {
@ -332,14 +330,16 @@ module.exports = class MyLogger {
const table = evt.tableMap[evt.tableId]; const table = evt.tableMap[evt.tableId];
const tableName = table.tableName; const tableName = table.tableName;
const tableInfo = this.schemaMap.get(table.parentSchema, tableName); const tableInfo = this.schemaMap.get(table.parentSchema, tableName);
if (!tableInfo) return; if (!tableInfo) return;
const action = actions[eventName]; const action = actions[eventName];
const { rowExcludeField } = tableInfo; const { rowExcludeField, ignoreSystem } = tableInfo;
const changes = []; const changes = [];
function isExcluded(row) { function isExcluded(row) {
return rowExcludeField && row[rowExcludeField]; return (rowExcludeField && row[rowExcludeField])
|| (ignoreSystem && row.editorFk == null);
} }
function cast(value, type) { function cast(value, type) {
@ -500,6 +500,7 @@ module.exports = class MyLogger {
const isDelete = action == 'delete'; const isDelete = action == 'delete';
const isUpdate = action == 'update'; const isUpdate = action == 'update';
const created = new Date(evt.timestamp); const created = new Date(evt.timestamp);
const showId = tableInfo.conf.showId;
for (const change of changes) { for (const change of changes) {
let newI, oldI; let newI, oldI;
@ -521,7 +522,7 @@ module.exports = class MyLogger {
oldI = change.instance; oldI = change.instance;
break; break;
} }
const summaryId = showId ? row[showId] : null;
const modelId = row[tableInfo.idName]; const modelId = row[tableInfo.idName];
const modelValue = change.modelValue ?? null; const modelValue = change.modelValue ?? null;
const oldInstance = oldI ? JSON.stringify(oldI) : null; const oldInstance = oldI ? JSON.stringify(oldI) : null;

View File

@ -1,6 +1,6 @@
{ {
"name": "mylogger", "name": "mylogger",
"version": "1.1.4", "version": "1.1.5",
"author": "Verdnatura Levante SL", "author": "Verdnatura Levante SL",
"description": "MySQL and MariaDB logger using binary log", "description": "MySQL and MariaDB logger using binary log",
"license": "GPL-3.0", "license": "GPL-3.0",