virtual void log(string logText, int debugLevel, string threadName = "") = 0;
로
class Logger
{
public:
virtual void log(int debugLevel, char* fmt, ...) = 0;
virtual void log(string logText, int debugLevel, string threadName = "") = 0;
static Logger* defaultLogger() {return m_defaultLogger;}
static void setDefaultLogger(Logger& logger) {m_defaultLogger = &logger;}
protected:
static Logger* m_defaultLogger;
};
class DLog : public Logger
{
public:
DLog();
~DLog();
static DLog *Instance();
static void Destroy();
void SetLogFilename(std::string filename);
void SetOutputDebug(bool enable);
std::string getKeyTypeName(long lKeyType);
std::string getScopeTypeName(long lScopeType);
std::string getMethodName(long lMethod);
virtual void log(string logText, int debugLevel)
{
Log(const_cast<char*>(logText.c_str()));
}
void Log(char* fmt, ...);
private:
static DLog *m_instance;
std::string m_filename;
bool m_bOutputDebug;
};
// DLOG의 instantion 클래스 DLOG에서 구현되지 않았습니다. 그것은 기본 클래스에서 순수 가상이기 때문에 구현해야합니다.
당신은 아마 DLog
에 log
의 첫 번째 과부하이 의미 :
virtual void log(string logText, int debugLevel, string /*threadname*/)
{
Log(const_cast<char*>(logText.c_str()));
}
편집 : 그 사용 const_cast
는 비록 당신은 여기
virtual void log(int debugLevel, char* fmt, ...) = 0;
주의 과부하를 구현하지 않은 아주 나쁜 생각이고 정의되지 않은 행동입니다. 다음과 같이하면됩니다 :
virtual void log(string logText, int debugLevel, string /*threadname*/)
{
logText.push_back('\0'); // Add null terminator
Log(&logText[0]); // Send non-const string to function
logText.pop_back(); // Remove null terminator
}
"Log"를 처음에는 const-correct로 만듭니다. 당신은 당신이 기본 클래스에 선언 된 순수 가상 메소드를 (당신이 추상 클래스로 DLog
을 원하지 않는 가정) 모든 구현을 제공 할 것으로 확신하고 있습니다 Logger
에서 DLog
클래스를 파생하여
분명히 파생 클래스에서 PVF를 구현해야합니다. –
제발 제발, 줄임표와 함께 기능을 오버로드하지 마십시오. 밤에 머리카락을 잡아 당기거나 늦은 밤에 디버깅하는 시간을 절약 해줍니다. –
@Alex : 과부하가 아닌 ... 대문자 L 로그 기능. 다른 것들은 소문자입니다 ... –