0

I have an issue where I am logging some in app information such as requests,messages, responses and in this segment of the code is where it happening. My goal is to see the log file while the app is running which doesn't seem to happen right now, so the user has to exit the app and then go to the public folder in order to view the logs. I can provide more information if needed.

 void LogClass::log(const char* pcszComponent, const char* pcszLevel, const CF1String& title, const CF1String& message)
    {
        m_guard.lock();

        QByteArray byteArray(QTime::currentTime().toString("HH:mm:ss.zzz").toAscii());
        XXString logMessage = XXFormatString("[%s] [%7s] [%4s] [%08X] [%s] [%s]\r\n", byteArray.constData(), pcszLevel, pcszComponent, QThread::currentThreadId(), title.c_str(), message.c_str());

        if (!m_pLogFile) {
            createLogFile();
        }

        if (m_pLogFile) {
            fputs(logMessage.c_str(), m_pLogFile);
            fflush(m_pLogFile);
        }

        m_guard.unlock();
    }

Thanks in advance.

MR Mido
  • 1,618
  • 4
  • 25
  • 35

1 Answers1

1

You are using buffered output with fflush after each message so potentially you should be able to see file update (because data is written to OS). Possible reason why you don't see it is that OS doesn't flush its internal file buffers to disk. You may try _commit function on Windows or fsync on Linux

AlexT
  • 1,413
  • 11
  • 11
  • Thanks AlexT for your answer, I am not sure I fully understand the given solution given the fact that I am dealing with BB10 platform, do you think you can give me an example of _commit function on Windows or fsync on Linux in the given bb10 platform ? Thanks – MR Mido Apr 10 '14 at 05:16
  • @MRMido I didn't work neither with BB10 nor with QNX but I see that QNX has [fsync](http://www.qnx.com/developers/docs/6.3.0SP3/neutrino/lib_ref/f/fsync.html) so you can call it like `fsync(fileno(m_pLogFile))` – AlexT Apr 10 '14 at 05:47