Webdar 1.0.0
Web user interface to libdar
central_report.hpp
1/*********************************************************************/
2// webdar - a web server and interface program to libdar
3// Copyright (C) 2013-2025 Denis Corbin
4//
5// This file is part of Webdar
6//
7// Webdar is free software: you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// Webdar is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with Webdar. If not, see <http://www.gnu.org/licenses/>
19//
20//----
21// to contact the author: dar.linux@free.fr
22/*********************************************************************/
23
24#ifndef CENTRAL_REPORT_HPP
25#define CENTRAL_REPORT_HPP
26
27 // C system header files
28#include "my_config.h"
29extern "C"
30{
31#if HAVE_SYSLOG_H
32#include <syslog.h>
33#endif
34
35#if HAVE_PTHREAD_H
36#include <pthread.h>
37#endif
38}
39
40 // C++ system header files
41#include <string>
42#include <libthreadar/libthreadar.hpp>
43
44 // webdar headers
45
47
48enum priority_t { crit, err, warning, notice, info, debug };
49
51
53{
54public:
55 central_report(priority_t min_logged): min(min_logged) {};
56 central_report(const central_report & ref) = delete;
57 central_report(central_report && ref) noexcept = delete;
58 central_report & operator = (const central_report & ref) = delete;
59 central_report & operator = (central_report && ref) noexcept = delete;
60 virtual ~central_report() noexcept(false) {};
61
62 void report(priority_t priority, const std::string & message);
63
64protected:
65 virtual void inherited_report(priority_t priority, const std::string & message) = 0;
66
67private:
68 priority_t min;
69 static libthreadar::mutex access; //< caller must acquire mutex before reporting
70};
71
73
75{
76public:
77 central_report_stdout(priority_t min_logged): central_report(min_logged) {};
78
79protected:
80 virtual void inherited_report(priority_t priority, const std::string & message) override;
81};
82
84
86{
87public:
88 central_report_syslog(priority_t min_logged, const std::string & fixed_label, int facility);
89 ~central_report_syslog() noexcept(false);
90
91protected:
92 virtual void inherited_report(priority_t priority, const std::string & message) override;
93
94private:
95 std::string label; //< need to exist during the whole life of the object for syslog(3) to work as expected
96
97 // static fields
98 static unsigned int num_obj; //< number of object created (only one is allowed as syslog routine is not re-entrant)
99 static libthreadar::mutex num_obj_mod; //< controls the write access to num_obj
100
101};
102
103#endif
implements a central_report logging centralization which output the logs on stdout
Definition: central_report.hpp:75
implements a central_report logging centralization which send logs to syslog
Definition: central_report.hpp:86
pure virtual class defining the common interface of log centralization implementations
Definition: central_report.hpp:53