CobaltFusion / DebugViewPP

DebugView++, collects, views, filters your application logs, and highlights information that is important to you!
Boost Software License 1.0
1.02k stars 149 forks source link

tailing on non (unusual) flushing loggers #334

Closed vlovo closed 6 years ago

vlovo commented 6 years ago

this is taken over from #331 I use log4cxx as a logging framework. It turns out that flushing do not operate as expected. When tailing the file in DebugView++ the FILE_NOTIFY_CHANGE_SIZE event will never be invoked. It will be invoked if you hit F5 in file explorer or if you start Baretail.exe (https://www.baremetalsoft.com/baretail/) alongside to tail the same file. I also made a test app with log4cxx and I try to forced to do an immediate flush by using the approbiate API function (appender->setImmediateFlush(true); for the record), but the behaviour do not change. So it is supposed to be a bug in log4cxx or they forget to remove API function, because the never want to flush...

So I came along with a workaround, because I noticed by quering the filesize periodically invokes the FILE_NOTIFY_CHANGE_SIZE in DebugView++. So if you add in FileReader ctor the following ( just to sketch the idea roughly..) :

std::thread t([this]()
    {
        namespace fs = std::experimental::filesystem;
        fs::path p(m_filename);
        size_t s = 0;
        while (1)
        {
            s = fs::file_size(p);
            Sleep(40);
        }
        return (s);
        });

    t.detach();

it turns out tailing/autoscroll operation works again.

janwilmans commented 6 years ago

Thanks! That sounds very interesting, I will test this and make it part of debugview++

vlovo commented 6 years ago

NFlog4cxx64.zip Attached you find the sample app as executeable , with log4cxx DLL for your convenience .....

janwilmans commented 6 years ago

I tried your test and see exactly what you mean, very interesting.

janwilmans commented 6 years ago

tail for win32 and notepad++ seems to have solved this the same way you suggest. https://github.com/notepad-plus-plus/notepad-plus-plus/issues/3142

janwilmans commented 6 years ago

I tested your proposal, however it does not work, fs::file_size(p); is not triggering the FILE_NOTIFY_CHANGE_SIZE... I do see that right-clicking the log-file or clicking 'properties' in explorer does trigger FILE_NOTIFY_CHANGE_SIZE... looking for better ways...

janwilmans commented 6 years ago

please try this pre-release version https://github.com/CobaltFusion/DebugViewPP/releases/tag/v1.8.0.27

vlovo commented 6 years ago

Sorry ,your are right ; I also did auto res = Win32::WaitForAnyObject(waitHandles, 10000); instead waiting INFINITE. This might solve kind of starting problem....

vlovo commented 6 years ago

I testeted v1.8.0.27 👍
works with test and real apps !

janwilmans commented 6 years ago

good to hear. however, I'm not really keen on the current solution, its polling the filesize every 500ms, which means it is doing more work then should be needed and the timestamps (in debugview) are at best 500ms-accurate, which is quite bad compared to the normal ~microsecond accuracy.