File: main.cxx

package info (click to toggle)
log4cplus 2.0.8-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,592 kB
  • sloc: cpp: 53,091; sh: 10,537; ansic: 1,845; python: 1,226; perl: 263; makefile: 209; xml: 85; objc: 59
file content (57 lines) | stat: -rw-r--r-- 2,014 bytes parent folder | download | duplicates (3)
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
#include <log4cplus/logger.h>
#include <log4cplus/consoleappender.h>
#include <log4cplus/ndc.h>
#include <log4cplus/helpers/loglog.h>
#include <log4cplus/loggingmacros.h>
#include <log4cplus/initializer.h>
#include <iostream>
#include <string>

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

int
main()
{
    cout << "Entering main()..." << endl;
    log4cplus::Initializer initializer;
    LogLog::getLogLog()->setInternalDebugging(true);
    try {
        SharedObjectPtr<Appender> append_1(new ConsoleAppender());
        append_1->setName(LOG4CPLUS_TEXT("First"));
        append_1->setLayout(
            std::unique_ptr<Layout>(
                new log4cplus::PatternLayout(
                    LOG4CPLUS_TEXT ("%-5p %c <%x> - %m%n"))));
        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_void ();
        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 occurred..."));
    }

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