diff options
author | spiff_ <spiff_@svn> | 2009-12-21 01:37:42 +0000 |
---|---|---|
committer | spiff_ <spiff_@svn> | 2009-12-21 01:37:42 +0000 |
commit | df53f9e68809e20c3be7ca4d401af68134545a08 (patch) | |
tree | bbb349e86e5e41084b0b9d548400b5f73c7001f9 | |
parent | b9c30b2c55c6bb202639da2cbd98678533418d1a (diff) |
changed: CLog now uses a FILE*. avoids crashes if we cannot write the log for some reason (usually permissions)
git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk@25916 568bbfeb-2a22-0410-94d2-cc84cf5bfa90
-rw-r--r-- | xbmc/Application.cpp | 7 | ||||
-rw-r--r-- | xbmc/utils/log.cpp | 57 | ||||
-rw-r--r-- | xbmc/utils/log.h | 7 |
3 files changed, 40 insertions, 31 deletions
diff --git a/xbmc/Application.cpp b/xbmc/Application.cpp index 63fbfe8667..ec0e85ecc7 100644 --- a/xbmc/Application.cpp +++ b/xbmc/Application.cpp @@ -498,6 +498,13 @@ HRESULT CApplication::Create(HWND hWnd) delete profile; } + if (!CLog::Init(_P(g_stSettings.m_logFolder).c_str())) + { + fprintf(stderr,"Could not init logging classes. Permission errors on ~/.xbmc?\n"); + return E_FAIL; + } + + CLog::Log(LOGNOTICE, "-----------------------------------------------------------------------"); #if defined(__APPLE__) CLog::Log(LOGNOTICE, "Starting XBMC, Platform: Mac OS X. Built on %s (SVN:%s)", __DATE__, SVN_REV); diff --git a/xbmc/utils/log.cpp b/xbmc/utils/log.cpp index 19e5d048bb..36c1eb8e92 100644 --- a/xbmc/utils/log.cpp +++ b/xbmc/utils/log.cpp @@ -32,7 +32,7 @@ #include "AdvancedSettings.h" #include "Thread.h" -XFILE::CFile* CLog::m_file = NULL; +FILE* CLog::m_file = NULL; static CCriticalSection critSec; @@ -57,8 +57,7 @@ void CLog::Close() CSingleLock waitLock(critSec); if (m_file) { - m_file->Close(); - delete m_file; + fclose(m_file); m_file = NULL; } } @@ -71,26 +70,7 @@ void CLog::Log(int loglevel, const char *format, ... ) { CSingleLock waitLock(critSec); if (!m_file) - { - m_file = new XFILE::CFile; - if (!m_file) - return; - - // g_stSettings.m_logFolder is initialized in the CSettings constructor - // and changed in CApplication::Create() - CStdString strLogFile, strLogFileOld; - - strLogFile.Format("%sxbmc.log", g_stSettings.m_logFolder.c_str()); - strLogFileOld.Format("%sxbmc.old.log", g_stSettings.m_logFolder.c_str()); - - if(m_file->Exists(strLogFileOld)) - m_file->Delete(strLogFileOld); - if(m_file->Exists(strLogFile)) - m_file->Rename(strLogFile, strLogFileOld); - - if(!m_file->OpenForWrite(strLogFile)) - return; - } + return; SYSTEMTIME time; GetLocalTime(&time); @@ -130,9 +110,8 @@ void CLog::Log(int loglevel, const char *format, ... ) strData.Replace("\n", LINE_ENDING" "); strData += LINE_ENDING; - m_file->Write(strPrefix.c_str(), strPrefix.size()); - m_file->Write(strData.c_str(), strData.size()); - + fwrite(strPrefix.c_str(),strPrefix.size(),1,m_file); + fwrite(strData.c_str(),strData.size(),1,m_file); } #ifndef _LINUX #if defined(_DEBUG) || defined(PROFILE) @@ -157,6 +136,32 @@ void CLog::Log(int loglevel, const char *format, ... ) #endif } +bool CLog::Init(const char* path) +{ + CSingleLock waitLock(critSec); + if (!m_file) + { + // g_stSettings.m_logFolder is initialized in the CSettings constructor + // and changed in CApplication::Create() + CStdString strLogFile, strLogFileOld; + + strLogFile.Format("%sxbmc.log", path); + strLogFileOld.Format("%sxbmc.old.log", path); + + struct stat64 info; + if (stat64(strLogFileOld.c_str(),&info) == 0 && + remove(strLogFileOld.c_str()) != 0) + return false; + if (stat64(strLogFile.c_str(),&info) == 0 && + rename(strLogFile.c_str(),strLogFileOld.c_str()) != 0) + return false; + + m_file = fopen(strLogFile.c_str(),"wb"); + } + + return m_file != NULL; +} + void CLog::DebugLog(const char *format, ... ) { #ifdef _DEBUG diff --git a/xbmc/utils/log.h b/xbmc/utils/log.h index 3fdeb89f1b..bba86f9e63 100644 --- a/xbmc/utils/log.h +++ b/xbmc/utils/log.h @@ -46,13 +46,9 @@ #define ATTRIB_LOG_FORMAT #endif -namespace XFILE { - class CFile; -} - class CLog { - static XFILE::CFile *m_file; + static FILE* m_file; public: CLog(); virtual ~CLog(void); @@ -61,6 +57,7 @@ public: static void DebugLog(const char *format, ...); static void MemDump(char *pData, int length); static void DebugLogMemory(); + static bool Init(const char* path); }; // GL Error checking macro |