File: CategoryStream.cpp

package info (click to toggle)
log4shib 2.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 2,968 kB
  • sloc: cpp: 4,786; sh: 4,242; ansic: 818; makefile: 193
file content (49 lines) | stat: -rw-r--r-- 1,073 bytes parent folder | download | duplicates (7)
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
/*
 * CategoryStream.cpp
 *
 * Copyright 2001, LifeLine Networks BV (www.lifeline.nl). All rights reserved.
 * Copyright 2001, Bastiaan Bakker. All rights reserved.
 *
 * See the COPYING file for the terms of usage and distribution.
 */

#include "PortabilityImpl.hh"

#ifdef LOG4SHIB_HAVE_UNISTD_H
#    include <unistd.h>
#endif

#include <log4shib/CategoryStream.hh>
#include <log4shib/Category.hh>

namespace log4shib {

    CategoryStream::CategoryStream(Category& category, Priority::Value priority) :
        _category(category),
        _priority(priority),
        _buffer(NULL) {
    }

    CategoryStream::~CategoryStream() { 
        flush();
    }

    void CategoryStream::flush() {
        if (_buffer) {
            getCategory().log(getPriority(), _buffer->str());
            delete _buffer;
            _buffer = NULL;
        }
    }

    CategoryStream& CategoryStream::operator<< (cspf pf) {
 		return (*pf)(*this);
    }

    CategoryStream& eol (CategoryStream& os) {
        if  (os._buffer) {
    		os.flush();
        }
        return os;
    }
}