Menu

[2d617b]: / tests / testPropertyConfig.cpp  Maximize  Restore  History

Download this file

109 lines (86 with data), 2.6 kB

  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
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
// testConfig.cpp : Derived from testPattern.cpp.
//
#include <log4cpp/Portability.hh>
#ifdef WIN32
#include <windows.h>
#endif
#ifdef LOG4CPP_HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <stdlib.h>
#include <log4cpp/Category.hh>
#include <log4cpp/Appender.hh>
#include <log4cpp/OstreamAppender.hh>
#include <log4cpp/FileAppender.hh>
#include <log4cpp/Layout.hh>
#include <log4cpp/BasicLayout.hh>
#include <log4cpp/Priority.hh>
#include <log4cpp/NDC.hh>
#include <log4cpp/PatternLayout.hh>
#include <log4cpp/PropertyConfigurator.hh>
double calcPi()
{
double denominator = 3.0;
double retVal = 4.0;
long i;
for (i = 0; i < 50000000l; i++)
{
retVal = retVal - (4.0 / denominator);
denominator += 2.0;
retVal = retVal + (4.0 /denominator);
denominator += 2.0;
}
return retVal;
}
int main(int argc, char* argv[])
{
try {
/* looking for the init file in $srcdir is a requirement of
automake's distcheck target.
*/
char* srcdir = getenv("srcdir");
std::string initFileName;
if (srcdir == NULL) {
initFileName = "./testConfig.log4cpp.properties";
}
else {
initFileName = std::string(srcdir) + "/testConfig.log4cpp.properties";
}
log4cpp::PropertyConfigurator::configure(initFileName);
} catch(log4cpp::ConfigureFailure& f) {
std::cout << "Configure Problem " << f.what() << std::endl;
return -1;
}
log4cpp::Category& root = log4cpp::Category::getRoot();
log4cpp::Category& sub1 =
log4cpp::Category::getInstance(std::string("sub1"));
log4cpp::Category& sub2 =
log4cpp::Category::getInstance(std::string("sub1.sub2"));
log4cpp::Category& sub3 =
log4cpp::Category::getInstance(std::string("sub1.sub2.sub3"));
root.error("root error");
root.warn("root warn");
sub1.error("sub1 error");
sub1.warn("sub1 warn");
calcPi();
sub2.error("sub2 error");
sub2.warn("sub2 warn");
root.error("root error");
root.warn("root warn");
sub1.error("sub1 error");
sub1.warn("sub1 warn");
#ifdef WIN32
Sleep(3000);
#else
sleep(3);
#endif
sub2.error("sub2 error");
sub2.warn("sub2 warn");
sub2.error("%s %s %d", "test", "vform", 123);
sub2.warnStream() << "streamed warn";
sub2 << log4cpp::Priority::WARN << "warn2.." << "..warn3..value=" << 0
<< log4cpp::eol << "..warn4";
sub3 << log4cpp::Priority::INFO << "Very long config string follows";
log4cpp::Category::shutdown();
return 0;
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.