File: setlogparams.cc

package info (click to toggle)
natlog 3.01.00-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,912 kB
  • sloc: cpp: 3,691; fortran: 201; sh: 133; ansic: 123; makefile: 110
file content (79 lines) | stat: -rw-r--r-- 1,938 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "options.ih"

void Options::setLogParams()
{
    // at construction time: d_rotateFreq = 0;

    d_arg.option(&d_logData, "log-data");                   // maybe log
                                                            // table data

    if (not d_arg.option(&d_log, "log"))     // no log spec: use syslog
    {
        d_log = "syslog";

        if (not d_arg.option(&d_syslogTag, "syslog-tag"))   // specific or 
            d_syslogTag = s_defaultSyslogIdent;             // default log-tag
    
        setSyslogFacility();
        setSyslogPriority();

        return;
    }
                                                // log specification indicates
    if (d_log == "off")                         // no logging
    {
        d_log.clear();
        return;
    }

    // path to the log-file was specified

    string value;
    if (d_arg.option(&value, "log-rotate"))     // log file rotation in days
    {
        istringstream in{ value };

        in >> d_rotateFreq;
        switch (in.get())
        {
            case 'd':
                d_rotateFactor = 24 * 60;
                d_rotateTimeSpec = " days";
            break;

            case 'h':
                d_rotateFactor = 60;
                d_rotateTimeSpec = " hours";
            break;

            case 'm':
                d_rotateTimeSpec = " minutes";
            break;

            default:
            throw Exception{} << "`log-rotate " << value << "' not supported";
        }

        if (d_rotateFreq == 1)
            d_rotateTimeSpec.pop_back();

        if (isdigit(in.peek()))
        {
            in >> d_nRotations;
            if (d_nRotations == 0)
                d_nRotations = 1;
        }
        else if (in.peek() == EOF)
            d_nRotations = 1;
        else
            throw Exception{} << "`--log-rotate " << value << 
                                                    "' not supported";
    }
}