From 9302df2453dbcab477ca52198bb1b20dbbed845f Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 11 Feb 2012 17:50:00 -0800 Subject: [PATCH] Allow plStrings to be passed to plLoggable. --- .../PubUtilLib/plStatusLog/plLoggable.cpp | 68 ++++++++++++------- .../PubUtilLib/plStatusLog/plLoggable.h | 4 +- 2 files changed, 48 insertions(+), 24 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plStatusLog/plLoggable.cpp b/Sources/Plasma/PubUtilLib/plStatusLog/plLoggable.cpp index b5551283..0a940a80 100644 --- a/Sources/Plasma/PubUtilLib/plStatusLog/plLoggable.cpp +++ b/Sources/Plasma/PubUtilLib/plStatusLog/plLoggable.cpp @@ -45,7 +45,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "hsTemplates.h" -plLoggable::~plLoggable() +plLoggable::~plLoggable() { IDeleteLog(); } @@ -53,7 +53,7 @@ plLoggable::~plLoggable() void plLoggable::IDeleteLog() { if ( fWeCreatedLog ) - delete fStatusLog; + delete fStatusLog; fWeCreatedLog = false; fStatusLog = nil; } @@ -86,13 +86,20 @@ void plLoggable::SetLog( plStatusLog * log, bool deleteOnDestruct/*=false */) bool plLoggable::Log( const char * str ) const { - if ( !str || strlen( str )==0 ) + return Log(plString::FromUtf8(str)); +} + +bool plLoggable::Log(const plString& str) const +{ + if (str.IsNull() || str.IsEmpty()) { return true; + } GetLog(); - if ( fStatusLog ) - return fStatusLog->AddLine( str ); + if (fStatusLog) { + return fStatusLog->AddLine(str.c_str()); + } return true; } @@ -101,60 +108,75 @@ bool plLoggable::LogF( const char * fmt, ... ) const { va_list args; va_start(args, fmt); - return Log( xtl::formatv( fmt, args ).c_str() ); + bool ret = Log(plString::IFormat(fmt, args)); + va_end(args); + + return ret; } bool plLoggable::LogV( const char * fmt, va_list args ) const { - return Log( xtl::formatv( fmt, args ).c_str() ); + return Log(plString::IFormat(fmt, args)); } -bool plLoggable::DebugMsgV(const char* fmt, va_list args) const +bool plLoggable::DebugMsgV(const char* fmt, va_list args) const { - return LogF("DBG: %s", xtl::formatv(fmt,args).c_str()); + return Log(_TEMP_CONVERT_FROM_LITERAL("DBG: ") + plString::IFormat(fmt, args)); } -bool plLoggable::ErrorMsgV(const char* fmt, va_list args) const +bool plLoggable::ErrorMsgV(const char* fmt, va_list args) const { - return LogF("ERR: %s", xtl::formatv(fmt,args).c_str()); + return Log(_TEMP_CONVERT_FROM_LITERAL("ERR: ") + plString::IFormat(fmt, args)); } -bool plLoggable::WarningMsgV(const char* fmt, va_list args) const +bool plLoggable::WarningMsgV(const char* fmt, va_list args) const { - return LogF("WRN: %s", xtl::formatv(fmt,args).c_str()); + return Log(_TEMP_CONVERT_FROM_LITERAL("WRN: ") + plString::IFormat(fmt, args)); } -bool plLoggable::AppMsgV(const char* fmt, va_list args) const +bool plLoggable::AppMsgV(const char* fmt, va_list args) const { - return LogF("APP: %s", xtl::formatv(fmt,args).c_str()); + return Log(_TEMP_CONVERT_FROM_LITERAL("APP: ") + plString::IFormat(fmt, args)); } /////////////////////////////////////////////////////////////// -bool plLoggable::DebugMsg(const char* fmt, ...) const +bool plLoggable::DebugMsg(const char* fmt, ...) const { va_list args; va_start(args, fmt); - return DebugMsgV(fmt, args); + bool ret = DebugMsgV(fmt, args); + va_end(args); + + return ret; } -bool plLoggable::ErrorMsg(const char* fmt, ...) const +bool plLoggable::ErrorMsg(const char* fmt, ...) const { va_list args; va_start(args, fmt); - return ErrorMsgV(fmt, args); + bool ret = ErrorMsgV(fmt, args); + va_end(args); + + return ret; } -bool plLoggable::WarningMsg(const char* fmt, ...) const +bool plLoggable::WarningMsg(const char* fmt, ...) const { va_list args; va_start(args, fmt); - return WarningMsgV(fmt, args); + bool ret = WarningMsgV(fmt, args); + va_end(args); + + return ret; } -bool plLoggable::AppMsg(const char* fmt, ...) const +bool plLoggable::AppMsg(const char* fmt, ...) const { va_list args; va_start(args, fmt); - return AppMsgV(fmt, args); + bool ret = AppMsgV(fmt, args); + va_end(args); + + return ret; } diff --git a/Sources/Plasma/PubUtilLib/plStatusLog/plLoggable.h b/Sources/Plasma/PubUtilLib/plStatusLog/plLoggable.h index 25e86efc..204b0c3a 100644 --- a/Sources/Plasma/PubUtilLib/plStatusLog/plLoggable.h +++ b/Sources/Plasma/PubUtilLib/plStatusLog/plLoggable.h @@ -44,6 +44,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include #include "HeadSpin.h" +#include "plString.h" // // An abstract base class which contains a status log and simple functions @@ -66,10 +67,11 @@ public: plStatusLog* GetLog() const; void SetLog( plStatusLog * log, bool deleteOnDestruct=false ); - + // logging virtual bool Log( const char * str ) const; + virtual bool Log(const plString& str) const; virtual bool LogF( const char * fmt, ... ) const; virtual bool LogV( const char * fmt, va_list args ) const; virtual bool ErrorMsgV(const char* fmt, va_list args) const ;