I wrote my own simple class for logging. I understand that I better to use some kind of library (boost.log, log4cpp?) but let's anyway discuss my simple class:
#include "stdafx.h"
#include "Logger.h"
Logger::Logger(std::string fileName)
{
logFile.open(fileName);
}
Logger::~Logger(void)
{
logFile.close();
}
void Logger::Error(std::string message) {
logFile << message << std::endl;
}
void Logger::Debug(std::string message) {
logFile << message << std::endl;
}
- I want my methods to accept variable number of arguments, so I can pass parameters like that
"Error code: %x", code
. How to do that? - I want
Debug
method to be excluded ifLOG_DEBUG
compilation symbol is not set. in C# I can just add[Conditional("LOG_DEBUG")]
before the method declaration, but now to do that in c++?
upd Regarding 1 i've tried that and it works:
void Logger::Debug(std::string message, ...) {
va_list arglist;
fprintf(pFile, message.c_str(), arglist);