Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide possibility to open log file from the beginning on #51

Open
GoogleCodeExporter opened this issue Apr 14, 2015 · 15 comments
Open

Comments

@GoogleCodeExporter
Copy link

I'd like to have a possibility to influence, if the last or the first line of a 
log file is visible after opening it. In my scenario the log does not change 
any more and therefore I want to start reading the file from its top. But for 
doing this I always have to scroll up first. I searched for a possibility to 
set the first line to be shown but...
a) logViewer.getViewer().setTopIndex(0); has restricted access
b) using it anyway does not solve my problem, because the TabSelectionListener 
simply resets my position after it finishes loading.

What steps will reproduce the problem?
1.Open a log file.

What is the expected output? What do you see instead?
After setting the (not yet available) flag "show top of file" I'd like to see 
the first lines and not the last ones.

What version of the product are you using? On what operating system?
0.9.8.6 on Windows XP

Please provide any additional information below.
The inner class TabSelectionListener is responsible for setting the location. 
All information is private and therefore I see no chance to influence the 
behavior except of patching the source code.

Original issue reported on code.google.com by [email protected] on 7 Feb 2011 at 4:16

@GoogleCodeExporter
Copy link
Author

It should be easy to implement, but actually i have no time until middle of 
march to do it. If you can provide a patch, i will apply it. Thank You!

Original comment by [email protected] on 7 Feb 2011 at 8:08

  • Changed state: Accepted
  • Added labels: Milestone-Release1.0, OpSys-All, Type-Enhancement
  • Removed labels: Type-Defect

@GoogleCodeExporter
Copy link
Author

Hi, thanks. I cannot provide a patch as I would need deeper understanding of 
your code for that. The patch probably will involve accessing data that is 
currently private (if I remember right the TABs are responsible for keeping the 
top index) and also might change access restrictions. 

Best regards from sunny Black Forrest!

Original comment by [email protected] on 8 Feb 2011 at 8:19

@GoogleCodeExporter
Copy link
Author

Added new option "show top of file" to Log Viewer preferences. If enabled view 
will be reseted to top of file after switching to file view or opening new 
file. If file is already in front and new data appears, end of the file will be 
shown.

Original comment by [email protected] on 7 Mar 2011 at 11:05

  • Changed state: Started
  • Added labels: Milestone-Release-Candidate-0.9.8
  • Removed labels: Milestone-Release1.0

@GoogleCodeExporter
Copy link
Author

Is available in v0.9.8.7. Please reopen if behaviour is not exactly what you 
requested...

Original comment by [email protected] on 7 Mar 2011 at 11:06

  • Changed state: Fixed

@GoogleCodeExporter
Copy link
Author

Hi,

thanks for the support. Anyway it is still not working. 
Is it possible that there is a threading issue?

I set the preference using the extended preference page of version 0.9.8.7. 

Afterwards I opened the log viewer using the following code:
        // do this in UI thread
        PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
                @Override
                public void run()
                {
                    final IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
                    final IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();

                    activePage.addPartListener(new LogViewerPartListener());

                    try {
                        FileHistoryTracker.getInstance().clearFiles();

                        final LogViewer logViewer =
                            (LogViewer) activePage.showView(ERROR_LOG_VIEWER_ID);

                        // show only one log file
                        removeUnwantedActionsAndMenus(logViewer);
                        System.err.println(" XXX " + logViewer.getViewer().isShowTopOfFile());

                        final String tabName = moduleName + " " + dateFormatter.format(new Date());

                        // create a log file for the LogViewer
                        final LogFile logFile =
                            new LogFile(LogFileType.LOGFILE_SYSTEM_FILE, aLogFile, tabName,
                                        DEFAULT_ENCODING, false);

                        if (new File(aLogFile).exists() && !logViewer.hasLogFile(logFile)) {
                            synchronized (this) {
                                logViewer.closeAllLogFiles();
                                logViewer.openLogFile(logFile);
                                System.err.println(" XXX2 " + logViewer.getViewer().isShowTopOfFile());

                                final LogDocument logDocument = logViewer.getCurrentDocument();
                                if (!standardErrorLines.isEmpty()) {
                                    // if standard error is not empty insert output at top

                                    final DecimalFormat lineNumberFormat =
                                        new DecimalFormat(ProcessResultCollector.LINE_NUMBER_DECIMAL_FORMAT);
                                    lineNumberFormat.setMinimumIntegerDigits(7);

                                    final StringBuilder builder = new StringBuilder();

                                    for (int lineNumber = 0; lineNumber < standardErrorLines.size(); lineNumber++) {
                                        builder.append(STANDARD_ERROR_PATTERN + ":")
                                               .append(lineNumberFormat.format(lineNumber + 1)).append(':')
                                               .append(standardErrorLines.get(lineNumber));
                                    }

                                    logDocument.replace(0, 0, builder.toString() + "\n\n");
                                }
                            }
                        }

                        System.err.println(" XXX3 " + logViewer.getViewer().isShowTopOfFile());
                    } catch (final PartInitException e) {
                        LOG.error("Failed to open error log view for '" + aLogFile + "'.", e);

                        final String message =
                            MessageFormat.format(I18nMgr.getString(Keys.TX_Error_ShowErrorLogView),
                                                 moduleName);
                        DetailsMessageDialog.syncOpenError(null, message, e);
                    } catch (final BadLocationException e) {
                        LOG.error("Failed to open error log view.", e);

                        final String message =
                            MessageFormat.format(I18nMgr.getString(Keys.TX_Error_ShowErrorLogView),
                                                 moduleName);
                        DetailsMessageDialog.syncOpenError(null, message, e);
                    }
                }
            });

      // jump to top of log file (has to be done after waiting for loading in separate call,
      // see http://code.google.com/a/eclipselabs.org/p/logviewer/issues/detail?id=51)
      try {
          Thread.sleep(250);
      } catch (final InterruptedException e) {
          LOG.error("Failed to wait for loading of error log file '" + aLogFile + "'.", e);
      }

      PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
              @Override
              public void run()
              {
                  final IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
                  final IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();

                  try {
                      final LogViewer logViewer =
                          (LogViewer) activePage.showView(ERROR_LOG_VIEWER_ID);
                      logViewer.getViewer().setTopIndex(0);
                  } catch (final PartInitException e) {
                      LOG.error("Failed to jump to top position of error log file '" + aLogFile + "'.", e);
                  }
              }
          });

Only having the (unsecure, because unclear if 250ms is long enough) 
thread.sleep and afterwards the setTopIndex call helps me in reaching the top 
of the displayed text.

Am I doing something wrong?

Best regards from sunny but cold Black Forrest,
   Mattin

Original comment by [email protected] on 8 Mar 2011 at 2:09

@GoogleCodeExporter
Copy link
Author

Forgot to mention: the system.err.println result in
 XXX true
 XXX2 true
 XXX3 true

Original comment by [email protected] on 8 Mar 2011 at 2:10

@GoogleCodeExporter
Copy link
Author

Original comment by [email protected] on 8 Mar 2011 at 6:22

  • Changed state: Accepted

@GoogleCodeExporter
Copy link
Author

Hi,

it was not clear for me that you want to use it from other plugin. So it was 
implemented for "normal" users. The viewer jumps to the top of the file only 
after file was loaded first time or tab was selected. If new data appears it 
jumps to the end of the file (see comment 3). Because from my point of view 
users want to see always the last data.

It can be changed like this:
1. check "show top of file" for normal view updates, but then it will always 
jump to the top, if log file is filled every second -> user have to stop 
tailoring to scroll down
2. add new option or button to "lock scrolling"

Any ideas?

Andre

Original comment by [email protected] on 9 Mar 2011 at 6:38

@GoogleCodeExporter
Copy link
Author

About the threading question: the read wait time is set to 250ms, so it tooks 
that time to detect the change and send it to the viewer document. After viewer 
gets the data it will set top index to the end of the file...

Original comment by [email protected] on 9 Mar 2011 at 6:47

@GoogleCodeExporter
Copy link
Author

I guess I've to explain the scenario for which the log viewer is used a little 
bit more:
Actually I do not even need the reloading feature, the log file that is 
displayed won't change. the log viewer only gets opened upon request of a user 
(after analyzing, if there are errors or warnings in the file and asking the 
user, if he wants to inspect the file).
What might make things even more complicated for the log viewer is the fact 
that - if anything was printed to standard error by the process that generates 
the log file - these lines written to standard error are inserted at the 
beginning of the file:
if (!standardErrorLines.isEmpty()) {
 [...] 
}

Your plug-in was chosen to realize this because it offers an easy way to 
configure "highlighting patterns". This allows the user to detect errors and 
warnings even in long log files very easy.
Further more using the preferences a user can even define its own highlighting 
patterns (if he's interested in a certain log event).

Therefore the "scroll lock" - if it can be enabled using the API - would 
probably fit my needs. Note that in the Eclipse IDE Console view there is a 
similar feature ("Scroll Lock" button). Probably you could use the same button.

Best regards, Mattin

Original comment by [email protected] on 10 Mar 2011 at 8:02

@GoogleCodeExporter
Copy link
Author

Original comment by [email protected] on 22 Mar 2011 at 7:47

@GoogleCodeExporter
Copy link
Author

Original comment by [email protected] on 4 Aug 2011 at 9:09

  • Changed state: Started

@GoogleCodeExporter
Copy link
Author

Original comment by [email protected] on 7 Aug 2011 at 6:57

  • Added labels: Milestone-Release-Candidate-0.9.9
  • Removed labels: Milestone-Release-Candidate-0.9.8

@GoogleCodeExporter
Copy link
Author

Original comment by [email protected] on 29 Sep 2012 at 7:05

@GoogleCodeExporter
Copy link
Author

Original comment by [email protected] on 20 Sep 2013 at 5:21

  • Added labels: Milestone-Release1.0
  • Removed labels: Milestone-Release-Candidate-0.9.9

@anb0s anb0s added this to the v1.0 milestone Sep 25, 2015
@anb0s anb0s self-assigned this Sep 25, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants