File: log

package info (click to toggle)
bobcat 6.11.00-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,292 kB
  • sloc: cpp: 21,370; fortran: 6,507; makefile: 2,787; sh: 724; perl: 401; ansic: 26
file content (108 lines) | stat: -rw-r--r-- 3,665 bytes parent folder | download
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#ifndef INCLUDED_BOBCAT_LOG_
#define INCLUDED_BOBCAT_LOG_

#include <iostream>

#include <fstream>
#include <memory>

#include <bobcat/logbuf>
#include <bobcat/level>
#include <bobcat/exception>

namespace FBB
{

enum LogManipulator
{
    FATAL,
    nl,                 // new line without new time stamp
    fnl,                // forced new line, even at low level specs.
};

class Log: private LogBuf, public std::ostream
{
                                                                    // opins:
    friend Log &operator<<(Log &log, LogManipulator manip);         //  2.cc
    friend Log &operator<<(Log &log,                                //  3.cc
                           std::ostream &(*fun)(std::ostream &str)); 
    friend Log &operator<<(Log &log,                                //  4.cc
                           std::ios_base &(*fun)(std::ios_base &base));
    template<typename Type>
    friend Log &operator<<(Log &log, Type const &type);             //   .f

    std::ofstream d_stream;
    size_t d_level;         // defined by setLevel: the minimum level 
                            // messages must have to be inserted

    struct Active
    {
        bool levelOK;
        bool opfunOK;       // WHAT'S opfun?

                            // log characters accepted by opfun.cc (?)
        std::string accept; // accepted log characters for opfun.cc
    };
    std::unique_ptr<Active> d_active;

                                                // Log object used by 
    static std::unique_ptr<Log> s_stream;       // initialize() and instance()

    public:
                    // returns s_stream's Log object
        static Log &instance();

                    // initializes s_stream, returns its Log object
        static Log &initialize(std::string const &filename,
                std::ios::openmode = std::ios::out | std::ios::app,
                char const *delim = " ");

            // defines the base class objects, calls init()
        Log();                                                  // 1.cc

           // defines the base class objects, calls init()
        Log(std::ostream &out,  char const *delim = " ");       // 2.cc

            // forwards to open(), also called by initialize()
        Log(std::string const &filename,                        // 3.cc
                std::ios::openmode = std::ios::out | std::ios::app,
                char const *delim = " ");

            // redefines LogBuf, calls init()
        void open(std::string const &filename,
                std::ios::openmode = std::ios::out | std::ios::app,
                char const *delim = " ");

            // returns the current message level (i.e., d_level)
        size_t level() const;                                           // .f

            // updates d_active's levelOK, opfunOK to false
            // messages are logged if levelOK is true
        std::ostream &level(size_t useLevel);

            // d_level = newLevel, activates msg logging at 'newLevel'
        void  setLevel(size_t newLevel);

        void  setTimestamp(TimeStamps timeStamp, char const *delim = " ");

            // logging completely off/on, but on() can specify a level nr.
        void  off();                                                    // .f
        void  on(size_t logLevel = 0);

        Log &operator()(char accept);

        void str(std::string const &str);
        std::string const &str() const;

    private:
        void init();
};

#include "log.f"

} // FBB

    // Not in FBB, but overloading the std operator<<(ostream &) function:
std::ostream &operator<<(std::ostream &str, FBB::LogManipulator); // opins1.cc

#endif