Hi,
I was wondering what the consensus is on correct use of the logger, if there is
such a thing.
Right now, in order to be able to use it in my entire project I have made the
code included below. The code works as intended but I'm not familiar with the
use of the "extern" keyword and I was wondering if my code is "correct" and
optimal or whether improvement is possible.
At any rate, thanks for any advice.
My .cpp file with the main():
(should probably get rid of the old unused includes)
====================================
// logging
#include <log4cxx/logger.h>
#include <log4cxx/fileappender.h>
#include <log4cxx/simplelayout.h>
#include <log4cxx/propertyconfigurator.h>
#include <log4cxx/helpers/exception.h>
using namespace log4cxx;
using namespace log4cxx::helpers;
LoggerPtr eventLogger;
int main (int argc, char* argv[])
{
// configure logger
eventLogger = LoggerPtr(Logger::getLogger("logger"));
PropertyConfigurator::configure("logconfig.txt");
...
}
====================================
A header file:
====================================
#ifndef EVENTLOGGER_H
#define EVENTLOGGER_H
#include <log4cxx/logger.h>
using namespace log4cxx;
using namespace log4cxx::helpers;
extern LoggerPtr eventLogger;
#endif
====================================
And in each file I want to use my logger:
====================================
#include "EventLogger.h"
void bork()
{
LOG4CXX_INFO(eventLogger, "msg");
}
====================================