About Store Forum Documentation Contact



Post Reply 
FileText.flush()
Author Message
MrPi Offline
Member

Post: #1
FileText.flush()
A flush() function for FileText would be very helpful to implement refreshing log files without the need to recreate a FileText object to add stuff to it.

Use case: log files for longer running applications like servers

Code:
struct LogFile
{
   LogFile()
   {
      m_bOpen = false;
   }
   ~LogFile()
   {
      Close();
   }

   void Open()
   {
      if (m_bOpen)
         return;
        
      m_bOpen = m_File.append(GetSavePath()+"log.txt");      
      Info("=============== LOG OPENED ================");
   }
   void Close()
   {
      if (!m_bOpen)
         return;
      Info("=============== LOG CLOSED ================");
      m_File.del();
   }

   void Write(const Str& category, const Str& log)
   {
      if (!m_bOpen)
         Open();
      m_File.putLine(DateTime().getLocal().asText()+" ["+category+"]: "+log);
      //m_File.flush(); <----
   }
  
   void Info(const Str& log)  { Write("INFO", log); }
   void Debug(const Str& log)  { Write("DEBUG", log); }
   void Error(const Str& log)  { Write("ERROR", log); }

private:  
  
   FileText m_File;
   Bool m_bOpen;
}

LogFile LOG;
11-16-2013 12:12 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: FileText.flush()
Will be available in next release.
11-16-2013 12:56 AM
Find all posts by this user Quote this message in a reply
MrPi Offline
Member

Post: #3
RE: FileText.flush()
Great. Thanks for the quick response, Greg!
11-16-2013 11:28 AM
Find all posts by this user Quote this message in a reply
Post Reply