diff --git a/binaries/data/config/system.cfg b/binaries/data/config/system.cfg index 5f21a9bccb..1467697685 100644 --- a/binaries/data/config/system.cfg +++ b/binaries/data/config/system.cfg @@ -37,27 +37,6 @@ windowed=true xres = 1024 yres = 768 -; Logging settings: -; -; All messages are logged into mainlog.html. These numbers control which go into -; interestinglog.html and are displayed in the console. -; Each component can have one of three 'interest' levels: -; 0 makes no messages interesting (i.e. none are sent to interestinglog / console) -; 1 (the default) makes errors/warnings interesting -; 2 makes all messages interesting - -loginterest.main = 1 -loginterest.config = 1 -loginterest.file = 1 -loginterest.world = 1 -loginterest.xml = 1 -loginterest.simulation = 1 -loginterest.graphics = 1 -loginterest.gui = 1 -loginterest.audio = 1 -loginterest.script = 1 -loginterest.i18n = 0 - ; Font mappings: font.console = console diff --git a/source/i18n/CLocale.cpp b/source/i18n/CLocale.cpp index d8674dd5b2..d05380537b 100644 --- a/source/i18n/CLocale.cpp +++ b/source/i18n/CLocale.cpp @@ -290,7 +290,7 @@ StringBuffer CLocale::Translate(const wchar_t* id) StringsType::iterator TransStr = Strings.find(Str(id)); if (TransStr == Strings.end()) { - LOG(CLogger::Warning, LOG_CATEGORY, "I18n: No translation found for string '%ls'", id); + LOG(CLogger::Normal, LOG_CATEGORY, "I18n: No translation found for string '%ls'", id); // Just use the ID string directly, and remember it for the future return StringBuffer(&AddDefaultString(id), this); diff --git a/source/ps/CLogger.cpp b/source/ps/CLogger.cpp index 300ed14fe5..3509e30278 100644 --- a/source/ps/CLogger.cpp +++ b/source/ps/CLogger.cpp @@ -66,8 +66,7 @@ void CLogger::Init() *m_MainLog << html_header0 << "Main log" << html_header1; //Write Headers for the HTML documents - *m_InterestingLog << html_header0 << "Main log (interesting items only, as specified in system.cfg)" << html_header1; - + *m_InterestingLog << html_header0 << "Main log (warnings and errors only)" << html_header1; } CLogger::~CLogger () @@ -102,62 +101,56 @@ CLogger::~CLogger () } } -void CLogger::WriteMessage(const char *message, int interestedness) +void CLogger::WriteMessage(const char *message) { - m_NumberOfMessages++; + ++m_NumberOfMessages; - if (interestedness >= 2) - { - if (g_Console) g_Console->InsertMessage(L"LOG: %hs", message); - *m_InterestingLog << "

" << message << "

\n"; - m_InterestingLog->flush(); - } *m_MainLog << "

" << message << "

\n"; m_MainLog->flush(); } -void CLogger::WriteError(const char *message, int interestedness) +void CLogger::WriteError(const char *message) { - m_NumberOfErrors++; + ++m_NumberOfErrors; if (m_UseDebugPrintf) debug_printf("ERROR: %s\n", message); - if (interestedness >= 1) - { - if (g_Console) g_Console->InsertMessage(L"ERROR: %hs", message); - *m_InterestingLog << "

ERROR: "<< message << "

\n"; - m_InterestingLog->flush(); - } + + if (g_Console) g_Console->InsertMessage(L"ERROR: %hs", message); + *m_InterestingLog << "

ERROR: "<< message << "

\n"; + m_InterestingLog->flush(); + *m_MainLog << "

ERROR: "<< message << "

\n"; m_MainLog->flush(); } -void CLogger::WriteWarning(const char *message, int interestedness) +void CLogger::WriteWarning(const char *message) { - m_NumberOfWarnings++; - if (interestedness >= 1) - { - if (g_Console) g_Console->InsertMessage(L"WARNING: %hs", message); - *m_InterestingLog << "

WARNING: "<< message << "

\n"; - m_InterestingLog->flush(); - } + ++m_NumberOfWarnings; + + if (g_Console) g_Console->InsertMessage(L"WARNING: %hs", message); + *m_InterestingLog << "

WARNING: "<< message << "

\n"; + m_InterestingLog->flush(); + *m_MainLog << "

WARNING: "<< message << "

\n"; m_MainLog->flush(); } // Sends the message to the appropriate piece of code -void CLogger::LogUsingMethod(ELogMethod method, const char* category, const char* message) +// -- This function has not been removed because the build would break. +void CLogger::LogUsingMethod(ELogMethod method, const char* message) { if(method == Normal) - WriteMessage(message, Interestedness(category)); + WriteMessage(message); else if(method == Error) - WriteError(message, Interestedness(category)); + WriteError(message); else if(method == Warning) - WriteWarning(message, Interestedness(category)); + WriteWarning(message); else - WriteMessage(message, Interestedness(category)); + WriteMessage(message); } +// -- This function has not been removed because the build would break. void CLogger::Log(ELogMethod method, const char* category, const char *fmt, ...) { va_list argp; @@ -171,10 +164,10 @@ void CLogger::Log(ELogMethod method, const char* category, const char *fmt, ...) } va_end(argp); - LogUsingMethod(method, category, buffer); + LogUsingMethod(method, buffer); } - +// -- This function has not been removed because the build would break. void CLogger::LogOnce(ELogMethod method, const char* category, const char *fmt, ...) { va_list argp; @@ -196,38 +189,56 @@ void CLogger::LogOnce(ELogMethod method, const char* category, const char *fmt, // If not, mark it as having been logged and then log it m_LoggedOnce.insert(message); - LogUsingMethod(method, category, buffer); + LogUsingMethod(method, buffer); } - -int CLogger::Interestedness(const char* category) +void CLogger::LogMessage(const char *fmt, ...) { - // This could be cached, but reading from the config DB every time allows - // easy run-time alteration of interest levels (and shouldn't be particularly - // slow) + va_list argp; + char buffer[512]; + + va_start(argp, fmt); + if (sys_vsnprintf(buffer, sizeof(buffer), fmt, argp) == -1) + { + // Buffer too small - ensure the string is nicely terminated + strcpy(buffer+sizeof(buffer)-4, "..."); // safe + } + va_end(argp); - // Category unspecified: use a high interest level to encourage - // people to categorise their errors - if (category == NULL) - return 2; - - // If the config DB hasn't been loaded, assume the default - if (! CConfigDB::IsInitialised()) - return 1; - - CConfigValue* v = g_ConfigDB.GetValue(CFG_SYSTEM, CStr("loginterest.")+category); - // If the value is unspecified, also use the default - if (!v) - return 1; - - int level; - // Try to retrieve the value as an integer - if (! v->GetInt(level)) - return 1; // something failed, so the default value might be a good alternative - - return level; + WriteMessage(buffer); } +void CLogger::LogWarning(const char *fmt, ...) +{ + va_list argp; + char buffer[512]; + + va_start(argp, fmt); + if (sys_vsnprintf(buffer, sizeof(buffer), fmt, argp) == -1) + { + // Buffer too small - ensure the string is nicely terminated + strcpy(buffer+sizeof(buffer)-4, "..."); // safe + } + va_end(argp); + + WriteWarning(buffer); +} + +void CLogger::LogError(const char *fmt, ...) +{ + va_list argp; + char buffer[512]; + + va_start(argp, fmt); + if (sys_vsnprintf(buffer, sizeof(buffer), fmt, argp) == -1) + { + // Buffer too small - ensure the string is nicely terminated + strcpy(buffer+sizeof(buffer)-4, "..."); // safe + } + va_end(argp); + + WriteError(buffer); +} TestLogger::TestLogger() { diff --git a/source/ps/CLogger.h b/source/ps/CLogger.h index fa3dbe2340..0fd5ebb77b 100644 --- a/source/ps/CLogger.h +++ b/source/ps/CLogger.h @@ -12,6 +12,13 @@ extern CLogger* g_Logger; #define LOG (g_Logger->Log) #define LOG_ONCE (g_Logger->LogOnce) +// Should become LOG_MESSAGE but this can only be changed once the LOG function is removed +// from all of the files. LOG_INFO, LOG_WARNING and LOG_ERROR are currently existing macros. + +#define LOGMESSAGE (g_Logger->LogMessage) +#define LOGWARNING (g_Logger->LogWarning) +#define LOGERROR (g_Logger->LogError) + class CLogger { NONCOPYABLE(CLogger); @@ -32,20 +39,29 @@ public: ~CLogger(); - // Functions to write different message types - void WriteMessage(const char *message, int interestedness); - void WriteError (const char *message, int interestedness); - void WriteWarning(const char *message, int interestedness); + // Functions to write different message types (Errors and warnings are placed + // both in mainLog and intrestingLog.) + void WriteMessage(const char *message); + void WriteError (const char *message); + void WriteWarning(const char *message); // Function to log stuff to file + // -- This function has not been removed because the build would break. void Log(ELogMethod method, const char* category, const char *fmt, ...); // Similar to Log, but only outputs each message once no matter how many times it's called + // -- This function has not been removed because the build would break. void LogOnce(ELogMethod method, const char* category, const char *fmt, ...); + // Functions to write a message, warning or error to file. + void LogMessage(const char *fmt, ...); + void LogWarning(const char *fmt, ...); + void LogError(const char *fmt, ...); + private: void Init(); - void LogUsingMethod(ELogMethod method, const char* category, const char* message); + // -- This function has not been removed because the build would break. + void LogUsingMethod(ELogMethod method, const char* message); // the output streams std::ostream* m_MainLog; @@ -61,12 +77,9 @@ private: int m_NumberOfErrors; int m_NumberOfWarnings; - // Returns how interesting this category is to the user - // (0 = no messages, 1(default) = warnings/errors, 2 = all) - int Interestedness(const char* category); - // Used to remember LogOnce messages std::set m_LoggedOnce; + }; /**