File: testPropConfig.cpp

package info (click to toggle)
log4cpp 1.1.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,444 kB
  • sloc: cpp: 6,715; sh: 3,670; ansic: 1,049; makefile: 295
file content (92 lines) | stat: -rw-r--r-- 2,314 bytes parent folder | download | duplicates (4)
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
// 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 <iostream>

#include <log4cpp/Category.hh>
#include <log4cpp/PropertyConfigurator.hh>
#include <log4cpp/HierarchyMaintainer.hh>

#include <stdlib.h>
#include <crtdbg.h>

void testPropConfigRead() {
    std::string initFileName;
#if defined(WIN32)
        initFileName = "./log4cpp.nt.property";
#else
        initFileName = "./log4cpp.property";
#endif
    log4cpp::PropertyConfigurator::configure(initFileName);

    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"));

    root.error("root error");
    root.warn("root warn");
    sub1.error("sub1 error");
    sub1.warn("sub1 warn");
    // the following 2 should only be in A1, not A2
    sub1.info("sub1 info");
    sub1.debug("sub1 debug");

    // do a few so that the log rolls over
    sub2.warn("sub2 warn 1");
    sub2.warn("sub2 warn 2");
    sub2.warn("sub2 warn 3");
    sub2.warn("sub2 warn 4");
    sub2.warn("sub2 warn 5");
    sub2.warn("sub2 warn 6");
    sub2.warn("sub2 warn 7");

#if defined(WIN32)
    log4cpp::Category& nt = 
        log4cpp::Category::getInstance(std::string("subNT"));
    nt.error("subNT error");
    nt.warn("subNT warn");
    nt.debug("subNT debug");
#endif

    log4cpp::Category::shutdownForced(); 
//    log4cpp::Category::shutdown(); 
}

int main(int argc, char* argv[])
{
// _CRTDBG_MAP_ALLOC is for detecting memory leaks on Windows
#ifdef _CRTDBG_MAP_ALLOC
	_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif

    try {
		// test single properties read
		testPropConfigRead();

		// test few more instantiations and shutdowns by shutdownForced()
		for (int i=0; i < 2; ++i) {
			testPropConfigRead();
		}
    } catch(log4cpp::ConfigureFailure& f) {
        std::cout << "Configure Problem " << f.what() << std::endl;
        return -1; 
    }

#ifdef _CRTDBG_MAP_ALLOC
	//_CrtDumpMemoryLeaks(); // would give detected leaks, since statically allocated objects were not freed yet
#endif
	return 0;
}