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#pragma once
23
24#include <cstdio>
25#include <iostream>
26
27#include <syslog.h>
28
50class logbuf : public std::streambuf {
51public:
52
61 logbuf(int loglevel, int fd);
62
68 void useSyslog() { _use_syslog = true; }
69
76 void useFileDescriptor() { _use_syslog = false; }
77
83 void setLevel(int newlevel) { _level = newlevel; }
84
92 int overflow(int c = EOF);
93
94private:
95
99 char *ptr;
100
104 unsigned int len;
105
110
115 int _fd;
116
121
126 char buf[1024];
127};
A streambuffer, logging via syslog.
Definition: log.h:50
bool _use_syslog
Log flag.
Definition: log.h:120
char * ptr
Pointer to next char in buffer.
Definition: log.h:99
char buf[1024]
The internal buffer for holding messages.
Definition: log.h:126
void useFileDescriptor()
Write logs to the file descriptor passed in the constructor.
Definition: log.h:76
void useSyslog()
Write logs using syslog.
Definition: log.h:68
unsigned int len
Current length of buffer.
Definition: log.h:104
int _fd
File descriptor to use when switched off.
Definition: log.h:115
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:109
void setLevel(int newlevel)
Modifies the loglevel of this instance.
Definition: log.h:83