00001 #ifndef _MERCURYLOG_H 00002 #define _MERCURYLOG_H 00003 00004 #include "MercuryString.h" 00005 #include <stdio.h> 00006 #include "MercuryTimer.h" 00007 #include "MercuryThreads.h" 00008 00013 class MercuryLog 00014 { 00015 public: 00016 MercuryLog(); 00017 00019 void Warn( const MString & message, int verbosity = 0 ); 00021 void Log( const MString & message, int verbosity = 0 ); 00023 void Info( const MString & message, int verbosity = 0 ); 00024 00026 inline void InfoVerbosity(int verbosity) { *MLockPtr<int>(m_infoVerbose, m_mutex) = verbosity; } 00027 inline void LogVerbosity(int verbosity) { *MLockPtr<int>(m_logVerbose, m_mutex) = verbosity; } 00028 inline void WarnVerbosity(int verbosity) { *MLockPtr<int>(m_warnVerbose, m_mutex) = verbosity; } 00029 00030 //I don't think we have to guard for a return 00031 inline int InfoVerbosity() const { return m_infoVerbose; } 00032 inline int LogVerbosity() const { return m_logVerbose; } 00033 inline int WarnVerbosity() const { return m_warnVerbose; } 00034 00035 private: 00036 void CheckInit(); 00037 bool m_bInitilized; 00038 00039 bool m_bLogToDisk; 00040 bool m_bInfoToDisk; 00041 bool m_bShowLogInConsole; 00042 bool m_bShowInfoInConsole; 00043 00044 FILE * m_fileLog; 00045 FILE * m_fileInfo; 00046 00047 MercuryTimer * m_tmrStart; 00048 00049 //volatile because these values _could_ change during execution 00050 volatile int m_infoVerbose; 00051 volatile int m_logVerbose; 00052 volatile int m_warnVerbose; 00053 00054 MercuryMutex m_mutex; 00055 }; 00056 00058 extern MercuryLog LOG; 00059 00060 #endif 00061 00062 00063 /* 00064 * Copyright (c) 2005-2006, Charles Lohr 00065 * All rights reserved. 00066 * 00067 * Redistribution and use in source and binary forms, with or 00068 * without modification, are permitted provided that the following 00069 * conditions are met: 00070 * - Redistributions of source code must retain the above 00071 * copyright notice, this list of conditions and the following disclaimer. 00072 * - Redistributions in binary form must reproduce the above copyright 00073 * notice, this list of conditions and the following disclaimer in 00074 * the documentation and/or other materials provided with the distribution. 00075 * - Neither the name of the Mercury Engine nor the names of its 00076 * contributors may be used to endorse or promote products derived from 00077 * this software without specific prior written permission. 00078 * 00079 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00080 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00081 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00082 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 00083 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00084 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00085 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00086 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00087 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00088 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00089 */