When debugging or maintaining systems and analysing their logs, one usually comes to the point where the plain text viewer is not enough. A couple of years ago, one of my colleagues developed a tool using C#/LINQ , that filtered out the relevant lines and allowed watching them back in the original context and some other useful features.
This is an attempt to write a similar application from scratch using C++/WTL that offers a little different set of features, supports different input encodings and can be run under Linux/Wine as well.
For more user information, please read enclosed .chm help file in LogHarvester.zip. In case of problems displaying it, this blog might help.
As I'm currently developing in C#/WPF in my job, I wanted to try something else. The WTL is great for developing lightweight native windows applications easily and it is completely for free. It is a good option for Visual C++ Express users as the Express edition does not support MFC (how to setup, please see my tip).
This is not an academic display of the best practices and design patterns. There is no rocket science in using C++ or WTL. It's rather a full featured application with i386 and x64 build and offline help.
In the time of publishing this article, this is the very first version of the application, basically tested by the author. The possible bugs and memory leaks should be fixed first. If you find any, please report it (or better still, point it out in the code including the solution).
The application architecture should be made more robust. Some things such as registry access are a bit WET. In any case, the code should be revised. Suggestions are welcome.
As for the new features, there are plans for multiple file opening, better line ending support, colouring the text instead of highlighting by selections and an optional ribbon interface as WTL supports it.
Using the code
CLogDoc is the document class that holds information about open documents or tabs, the hierarchy of source/derived documents and all the transformation logics.
CMainFrame does the main window interaction logics (mostly menu event handlers) and contains the main window initialisation.
CHarvesterView is the view class that currently does not add any extra logics to the generic
CRichEditCtrl. In the future, there could be e.g. document colouring.
Dialog classes (
C*Dlg) contain user interaction logics in dialogs (e.g., setting the select filter, find, replace etc.).
Distance.cpp is the Levenshtein distance algorithm implementation, that I found on the Internet. For copyright, see the top of that file. It is used as an advanced option in the select filter.
Harvester.cpp provides the main entry point of the application. There is also a timer that performs status bar selection counters update each 200ms as the selection change does not emit any message that could do this.
Points of Interest
You may find some peculiarities in the method
CLogDoc::LoadDocument(). For instance, the UTF-8/UNICODE16 files are obviously opened as text files, but ANSI ones are opened in the binary mode. That's because I didn't find any better way to prevent
fread() method from finishing reading ANSI files prematurely even as there wasn't anything suspicious in them. There is also a workaround for
_mbstowcs_l() as it worked correctly in x64 build but in i386 one it didn't return anything at all.
There is an unsecure
_wfopen() method used. That’s because the secure one does not support file-share access, which is needed for opening log files in use. I don't find anything really unsecure in using
_wfopen(). The warnings are
suppressed by defining
_CRT_SECURE_NO_WARNINGS, which some disapprove of.
In the method
CMainFrame::OnCreate() you may find a sort of magic in double maximising the third rebar band. This is because of the older widget used in Windows XP. Without that, the third band is aligned to the right and partially hidden after the applications starts.
- 2012-09-17: Version 1.0 published.