File: main.cxx

package info (click to toggle)
log4cplus 1.0.4-1.2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,532 kB
  • ctags: 1,420
  • sloc: sh: 10,603; cpp: 9,253; ansic: 706; makefile: 251
file content (53 lines) | stat: -rw-r--r-- 1,798 bytes parent folder | download | duplicates (2)
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

#include <log4cplus/logger.h>
#include <log4cplus/consoleappender.h>
#include <log4cplus/ndc.h>
#include <log4cplus/helpers/loglog.h>
#include <iostream>
#include <string>

using namespace std;
using namespace log4cplus;
using namespace log4cplus::helpers;

int
main()
{
    cout << "Entering main()..." << endl;
    LogLog::getLogLog()->setInternalDebugging(true);
    try {
        SharedObjectPtr<Appender> append_1(new ConsoleAppender());
        append_1->setName(LOG4CPLUS_TEXT("First"));
	append_1->setLayout( std::auto_ptr<Layout>(new log4cplus::TTCCLayout()) );
        Logger::getRoot().addAppender(append_1);

        Logger logger = Logger::getInstance(LOG4CPLUS_TEXT("test"));
        log4cplus::tcout << "Logger: " << logger.getName() << endl;
        getNDC().push(LOG4CPLUS_TEXT("tsmith"));
        LOG4CPLUS_DEBUG(logger, LOG4CPLUS_TEXT("This is a short test..."));

        getNDC().push(LOG4CPLUS_TEXT("password"));
        LOG4CPLUS_DEBUG(logger, LOG4CPLUS_TEXT("This should have my password now"));

        getNDC().pop();
        LOG4CPLUS_DEBUG(logger, LOG4CPLUS_TEXT("This should NOT have my password now"));

        getNDC().pop();
        cout << "Just returned from pop..." << endl;
        LOG4CPLUS_DEBUG(logger, LOG4CPLUS_TEXT("There should be no NDC..."));

        getNDC().push(LOG4CPLUS_TEXT("tsmith"));
        getNDC().push(LOG4CPLUS_TEXT("password"));
        LOG4CPLUS_DEBUG(logger, LOG4CPLUS_TEXT("This should have my password now"));
        getNDC().remove();
        LOG4CPLUS_DEBUG(logger, LOG4CPLUS_TEXT("There should be no NDC..."));
    }
    catch(...) {
        cout << "Exception..." << endl;
        Logger::getRoot().log(FATAL_LOG_LEVEL, LOG4CPLUS_TEXT("Exception occured..."));
    }

    cout << "Exiting main()..." << endl;
    return 0;
}