1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
#include <log4cplus/loggingmacros.h>
#include <log4cplus/configurator.h>
#include <log4cplus/helpers/loglog.h>
#include <log4cplus/helpers/stringhelper.h>
#include <log4cplus/helpers/fileinfo.h>
#include <log4cplus/loggingmacros.h>
#include <log4cplus/initializer.h>
using namespace std;
using namespace log4cplus;
using namespace log4cplus::helpers;
log4cplus::tstring
getPropertiesFileArgument (int argc, char * argv[])
{
if (argc >= 2)
{
char const * arg = argv[1];
log4cplus::tstring file = LOG4CPLUS_C_STR_TO_TSTRING (arg);
log4cplus::helpers::FileInfo fi;
if (getFileInfo (&fi, file) == 0)
return file;
}
return LOG4CPLUS_TEXT ("log4cplus.properties");
}
int
main(int argc, char * argv[])
{
tcout << LOG4CPLUS_TEXT("Entering main()...") << endl;
log4cplus::Initializer initializer;
LogLog::getLogLog()->setInternalDebugging(true);
Logger root = Logger::getRoot();
try {
PropertyConfigurator::doConfigure(
getPropertiesFileArgument (argc, argv));
Logger fileCat = Logger::getInstance(LOG4CPLUS_TEXT("filelogger"));
LOG4CPLUS_WARN(root, LOG4CPLUS_TEXT("Testing...."));
LOG4CPLUS_WARN(root, LOG4CPLUS_TEXT("Writing messages to log...."));
for (int i=0; i<10000; ++i)
LOG4CPLUS_WARN(fileCat, LOG4CPLUS_TEXT("This is a WARNING...")
<< i);
// Test that DOS EOLs in property files get removed.
#define TEST_TEXT LOG4CPLUS_TEXT ("this is a test with DOS EOL-->")
tistringstream propsStream (
LOG4CPLUS_TEXT ("text=") TEST_TEXT LOG4CPLUS_TEXT ("\r\n"));
Properties props (propsStream);
LOG4CPLUS_ASSERT (root,
props.getProperty (LOG4CPLUS_TEXT ("text")) == TEST_TEXT);
}
catch(...) {
tcout << LOG4CPLUS_TEXT("Exception...") << endl;
LOG4CPLUS_FATAL(root, LOG4CPLUS_TEXT("Exception occurred..."));
}
tcout << LOG4CPLUS_TEXT("Exiting main()...") << endl;
return 0;
}
|