~ubuntu-branches/ubuntu/trusty/log4shib/trusty

« back to all changes in this revision

Viewing changes to tests/testConfig.cpp

  • Committer: Package Import Robot
  • Author(s): Russ Allbery
  • Date: 2012-06-05 21:20:25 UTC
  • Revision ID: package-import@ubuntu.com-20120605212025-uyigtav7dqwvnf41
Tags: upstream-1.0.4
ImportĀ upstreamĀ versionĀ 1.0.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// testConfig.cpp : Derived from testPattern.cpp.
 
2
//
 
3
 
 
4
#include <log4shib/Portability.hh>
 
5
 
 
6
#ifdef WIN32
 
7
#include <windows.h>
 
8
#endif
 
9
#ifdef LOG4SHIB_HAVE_UNISTD_H
 
10
#include <unistd.h>
 
11
#endif
 
12
 
 
13
#include <cstdlib>
 
14
 
 
15
#include <log4shib/Category.hh>
 
16
#include <log4shib/Appender.hh>
 
17
#include <log4shib/OstreamAppender.hh>
 
18
#include <log4shib/FileAppender.hh>
 
19
#include <log4shib/Layout.hh>
 
20
#include <log4shib/BasicLayout.hh>
 
21
#include <log4shib/Priority.hh>
 
22
#include <log4shib/NDC.hh>
 
23
#include <log4shib/PatternLayout.hh>
 
24
 
 
25
#include <log4shib/SimpleConfigurator.hh>
 
26
 
 
27
double calcPi()
 
28
{
 
29
    double denominator = 3.0;
 
30
    double retVal = 4.0;
 
31
    long i;
 
32
    for (i = 0; i < 50000000l; i++)
 
33
    {
 
34
        retVal = retVal - (4.0 / denominator);
 
35
        denominator += 2.0;
 
36
        retVal = retVal + (4.0 /denominator);
 
37
        denominator += 2.0;
 
38
    }
 
39
    return retVal;
 
40
}
 
41
 
 
42
int main(int argc, char* argv[])
 
43
{
 
44
    try {
 
45
        /* looking for the init file in $srcdir is a requirement of
 
46
           automake's distcheck target.
 
47
        */
 
48
        char* srcdir = std::getenv("srcdir");
 
49
        std::string initFileName;
 
50
        if (srcdir == NULL) {
 
51
            initFileName = "./log4shib.init";
 
52
        }
 
53
        else {
 
54
            initFileName = std::string(srcdir) + "/log4shib.init";
 
55
        }
 
56
        log4shib::SimpleConfigurator::configure(initFileName);
 
57
    } catch(log4shib::ConfigureFailure& f) {
 
58
        std::cout << "Configure Problem " << f.what() << std::endl;
 
59
        return -1;
 
60
    }
 
61
 
 
62
    log4shib::Category& root = log4shib::Category::getRoot();
 
63
 
 
64
    log4shib::Category& sub1 = 
 
65
        log4shib::Category::getInstance(std::string("sub1"));
 
66
 
 
67
    log4shib::Category& sub2 = 
 
68
        log4shib::Category::getInstance(std::string("sub1.sub2"));
 
69
 
 
70
    root.error("root error");
 
71
    root.warn("root warn");
 
72
    sub1.error("sub1 error");
 
73
    sub1.warn("sub1 warn");
 
74
 
 
75
    calcPi();
 
76
 
 
77
    sub2.error("sub2 error");
 
78
    sub2.warn("sub2 warn");
 
79
 
 
80
    root.error("root error");
 
81
    root.warn("root warn");
 
82
    sub1.error("sub1 error");
 
83
    sub1.warn("sub1 warn");
 
84
 
 
85
#ifdef WIN32
 
86
    Sleep(3000);
 
87
#else
 
88
    sleep(3);
 
89
#endif
 
90
 
 
91
    sub2.error("sub2 error");
 
92
    sub2.warn("sub2 warn");
 
93
    sub2.error("%s %s %d", "test", "vform", 123);
 
94
    sub2.warnStream() << "streamed warn";
 
95
 
 
96
    sub2 << log4shib::Priority::WARN << "warn2.." << "..warn3..value=" << 0 << 
 
97
        log4shib::eol << "..warn4";
 
98
 
 
99
    log4shib::Category::shutdown();
 
100
 
 
101
    return 0;
 
102
}
 
103