plptools
Loading...
Searching...
No Matches
log.h
Go to the documentation of this file.
1/*
2 * This file is part of plptools.
3 *
4 * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
5 * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
6 * Copyright (C) 2026 Jason Morley <hello@jbmorley.co.uk>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * along with this program; if not, see <https://www.gnu.org/licenses/>.
20 *
21 */
22#ifndef _LOG_H_
23#define _LOG_H_
24
25#include <cstdio>
26#include <iostream>
27
28#include <syslog.h>
29
51class logbuf : public std::streambuf {
52public:
53
62 logbuf(int loglevel, int fd);
63
69 void useSyslog() { _use_syslog = true; }
70
77 void useFileDescriptor() { _use_syslog = false; }
78
84 void setLevel(int newlevel) { _level = newlevel; }
85
93 int overflow(int c = EOF);
94
95private:
96
100 char *ptr;
101
105 unsigned int len;
106
111
116 int _fd;
117
122
127 char buf[1024];
128};
129
130#endif
A streambuffer, logging via syslog.
Definition: log.h:51
bool _use_syslog
Log flag.
Definition: log.h:121
char * ptr
Pointer to next char in buffer.
Definition: log.h:100
char buf[1024]
The internal buffer for holding messages.
Definition: log.h:127
void useFileDescriptor()
Write logs to the file descriptor passed in the constructor.
Definition: log.h:77
void useSyslog()
Write logs using syslog.
Definition: log.h:69
unsigned int len
Current length of buffer.
Definition: log.h:105
int _fd
File descriptor to use when switched off.
Definition: log.h:116
int overflow(int c=EOF)
Called by the associated ostream to write a character.
Definition: log.cc:37
int _level
The log level to use with syslog.
Definition: log.h:110
void setLevel(int newlevel)
Modifies the loglevel of this instance.
Definition: log.h:84