Looking for a way to show descriptions for specific expressions in custom log files (solved)

Looking for a way to show descriptions for specific expressions in custom log files (solved)

2
NewbieNewbie
2

    Mar 14, 2018#1

    Hi everyone

    I am looking for a way (plug-in, macro, etc.) to show descriptions of specific expressions in custom log files opened in UltraEdit. This description may show up when clicking this expression (i.e.error number) or on mouse over.

    In the following example, such an error number (30044) is shown:

    Code: Select all

    [...]
    BTO    42.41    41.46    40.51    39.74    38.93    36.55
    Icg    22.25    22.69    23.00    23.20    23.54    24.34
    Nom   112.79   113.75   114.31   114.64   114.76   115.44
    
    prefix_300044
    
    BTO    42.41    41.46    40.51    39.74    38.93    36.55
    Icg    22.25    22.69    23.00    23.20    23.54    24.34
    Nom   112.79   113.75   114.31   114.64   114.76   115.44
    [...]
    I want to have a way to be able to have a long text available when it is needed for an error number like this. In those custom log files, >200 different errors are present. My initial plan was to have a description file that contains the expressions and corresponding descriptions.

    I did some searching for syntax highlighting, tooltips, description and such but could not find a proper solution. Since I am not very familiar with this kind of file analysis, I also do not exactly know what to look for.

    Any specific ideas or what to search for?
    Thanks a lot.

    Cheers,
    lobr

    6,675585
    Grand MasterGrand Master
    6,675585

      Mar 15, 2018#2

      It would be easy to use an UltraEdit script for this task which is added to Script List with a hotkey or chord (multi-key assignment) assigned to the script for fast execution by key which looks up the selected error number or the error number automatically selected at current position of caret in file in a list of error numbers with error descriptions both defined in script file. The script either shows a message box with the description for the error or outputs the error description to output window which is made visible by the script (and becomes not visible again if output window is docked with auto-hide enabled).

      Code: Select all

      var anErrorNumbers = [ 300044, 300045 ];
      var asErrorDescriptions = [
         "Description of error 300044",
         "Description of error 300045",
      ];
      
      if (anErrorNumbers.length != asErrorDescriptions.length)
      {
         UltraEdit.messageBox("Number of error numbers not equal number of error descriptions in file:\n\n" +
                              "C:\\Path to\\this sript file\\with name\\LogErrors.js\n\n" +
                              "Please correct this error.","Error in LogErrors.js");
      }
      
      if (UltraEdit.document.length > 0)  // Is any file opened?
      {
         // Define environment for this script.
         UltraEdit.insertMode();
         UltraEdit.columnModeOff();
      
         // Select the word at current position of caret if nothing selected.
         if (!UltraEdit.activeDocument.isSel())
         {
            UltraEdit.activeDocument.selectWord();
         }
      
         // It could be that there is still nothing selected in which case the script does nothing.
         if (UltraEdit.activeDocument.isSel())
         {
            // Get error number without string before and string after first integer in selection.
            var sErrorNumber = UltraEdit.activeDocument.selection.replace(/[^\d]*(\d+).*$/,"$1");
      
            // Verify that the remaining string is really a positive integer number.
            if (sErrorNumber.search(/^\d+$/) == 0)
            {
               // Convert decimal error number string into an integer number.
               var nErrorNumber = parseInt(sErrorNumber,10);
      
               // Search for this error number in array of error numbers.
               for (var nNumber = 0; nNumber < anErrorNumbers.length; nNumber++)
               {
                   if (anErrorNumbers[nNumber] == nErrorNumber) break;
               }
      
               // Was the error number not found in array of error numbers?
               if (nNumber ==  anErrorNumbers.length)
               {
                  nNumber = asErrorDescriptions.length;
               }
      
               var sErrorDescription = "";
               if (nNumber < asErrorDescriptions.length)
               {
                  sErrorDescription = asErrorDescriptions[nNumber];
               }
      
               // Is there no description defined in this script for this error number?
               if (!sErrorDescription.length)
               {
                  sErrorDescription = "Sorry, there is no description for this error.";
               }
      
               var sErrorHeader = "Error " + sErrorNumber + ":";
      
               UltraEdit.outputWindow.showStatus = false;
               UltraEdit.outputWindow.clear();
               UltraEdit.outputWindow.write(sErrorHeader+ " " + sErrorDescription);
               if (UltraEdit.outputWindow.visible == false)
               {
                  UltraEdit.outputWindow.showWindow(true);
               }
      
               UltraEdit.messageBox(sErrorHeader + "\n\n" + sErrorDescription);
            }
            else
            {
               UltraEdit.messageBox("The selection does not contain an error number.");
            }
         }
      }
      
      The two arrays at top must be filled by you. The error message output on number of error numbers not equal number of error descriptions should be also adapted by you for yourself. A user of this script should never see it.

      It is your choice to output the description just to output window, or show the description with a message box, or both as the script currently does.

      There are other possibilities as well like using a custom help file or perhaps auto-completion feature or smart templates. But I think the scripting solution would be fine and easy to maintain for your requirement.

      It would be also quite easy to code a script which scans the entire file for error numbers and write for each error number into output file the file name, line number containing error number, error number and error description. Then the user could look on all errors in log file with description in output window and double click on a line in output window to set caret to line in log file containing the error or use from within log file window the output window commands Next Message and Previous Message executed by hotkey (Ctrl+Shift+Down Arrow and Ctrl+Shift+Up Arrow).
      Best regards from an UC/UE/UES for Windows user from Austria

      2
      NewbieNewbie
      2

        Mar 15, 2018#3

        Thanks, exactly what I was looking for.