From eff47706920f2ee0638bf60642d4aebebce1f99e Mon Sep 17 00:00:00 2001 From: David Brazda Date: Fri, 15 Mar 2024 11:06:18 +0100 Subject: [PATCH] highlight logs on gui (#176) --- v2realbot/static/index.html | 12 ++--- v2realbot/static/js/mytables.js | 46 +++++++++++++++++++ .../js/tables/archivetable/functions.js | 24 ++++++++-- .../static/js/tables/archivetable/handlers.js | 9 +++- 4 files changed, 79 insertions(+), 12 deletions(-) diff --git a/v2realbot/static/index.html b/v2realbot/static/index.html index b9c7529..08d65d1 100644 --- a/v2realbot/static/index.html +++ b/v2realbot/static/index.html @@ -667,14 +667,14 @@
-
-

+                                    
+
@@ -1166,9 +1166,9 @@ - + - + @@ -1178,7 +1178,7 @@ - + diff --git a/v2realbot/static/js/mytables.js b/v2realbot/static/js/mytables.js index cbfc031..ee9ae5f 100644 --- a/v2realbot/static/js/mytables.js +++ b/v2realbot/static/js/mytables.js @@ -90,9 +90,55 @@ $(document).ready(function () { monaco.languages.register({ id: 'python' }); monaco.languages.register({ id: 'json' }); + //Register mylogs language + monaco.languages.register({ id: 'mylogs' }); // Register the TOML language + monaco.languages.setLanguageConfiguration('mylogs', { + comments: { + lineComment: '//', // Adjust if your logs use a different comment symbol + }, + brackets: [['[', ']'], ['{', '}']], // Array and object brackets + autoClosingPairs: [ + { open: '{', close: '}', notIn: ['string'] }, + { open: '"', close: '"', notIn: ['string', 'comment'] }, + { open: "'", close: "'", notIn: ['string', 'comment'] }, + ], + }); + monaco.languages.setMonarchTokensProvider('mylogs', { + tokenizer: { + root: [ + [/#.*/, 'comment'], // Comments (if applicable) + + // Timestamps + [/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+/, 'timestamp'], + + // Log Levels + [/\b(INFO|DEBUG|WARNING|ERROR|CRITICAL)\b/, 'log-level'], + + // Strings + [/".*"/, 'string'], + [/'.*'/, 'string'], + + // Key-Value Pairs + [/[A-Za-z_]+\s*:/, 'key'], + [/-?\d+\.\d+/, 'number.float'], // Floating-point + [/-?\d+/, 'number.integer'], // Integers + [/\btrue\b/, 'boolean.true'], + [/\bfalse\b/, 'boolean.false'], + + // Other Words and Symbols + [/[A-Za-z_]+/, 'identifier'], + [/[ \t\r\n]+/, 'white'], + [/[\[\]{}(),]/, 'delimiter'], // Expand if more delimiters exist + ] + } + }); + + monaco.languages.register({ id: 'toml' }); + + // Define the TOML language configuration monaco.languages.setLanguageConfiguration('toml', { comments: { diff --git a/v2realbot/static/js/tables/archivetable/functions.js b/v2realbot/static/js/tables/archivetable/functions.js index d6c2aa2..e08cb44 100644 --- a/v2realbot/static/js/tables/archivetable/functions.js +++ b/v2realbot/static/js/tables/archivetable/functions.js @@ -6,6 +6,7 @@ let editor_diff_arch1 let editor_diff_arch2 var archData = null var batchHeaders = [] +var editorLog = null function refresh_arch_and_callback(row, callback) { //console.log("entering refresh") @@ -472,13 +473,28 @@ function refresh_logfile() { contentType: "application/json", dataType: "json", success:function(response){ + if (editorLog) { + editorLog.dispose(); + } if (response.lines.length == 0) { - $('#log-content').html("no records"); + value = "no records"; + // $('#log-content').html("no records"); } else { - var escapedLines = response.lines.map(line => escapeHtml(line)); - $('#log-content').html(escapedLines.join('\n')); - } + //console.log(response.lines) + //var escapedLines = response.lines.map(line => escapeHtml(line)); + value = response.lines.join('\n') + // $('#log-content').html(escapedLines.join('\n')); + } + require(["vs/editor/editor.main"], () => { + editorLog = monaco.editor.create(document.getElementById('log-container'), { + value: value, + language: 'mylogs', + theme: 'tomlTheme-dark', + automaticLayout: true, + readOnly: true + }); + }); }, error: function(xhr, status, error) { var err = eval("(" + xhr.responseText + ")"); diff --git a/v2realbot/static/js/tables/archivetable/handlers.js b/v2realbot/static/js/tables/archivetable/handlers.js index 40006e0..3e318f7 100644 --- a/v2realbot/static/js/tables/archivetable/handlers.js +++ b/v2realbot/static/js/tables/archivetable/handlers.js @@ -265,8 +265,8 @@ $(document).ready(function () { $('#diff_first').text(record1.name); $('#diff_second').text(record2.name); - $('#diff_first_id').text(data1.id); - $('#diff_second_id').text(data2.id); + $('#diff_first_id').text(data1.id + ' Batch: ' + data1.batch_id); + $('#diff_second_id').text(data2.id + ' Batch: ' + data2.batch_id); //monaco require(["vs/editor/editor.main"], () => { @@ -358,8 +358,13 @@ $(document).ready(function () { }) }); + $('#closeLogModal').click(function () { + editorLog.dispose() + }); + //button to query log $('#logRefreshButton').click(function () { + editorLog.dispose() refresh_logfile() });