Debian Codegraph @

Logger/LoggerServer.h

raw symbols SCIP
1 /*
2 RailControl - Model Railway Control Software
3
4 Copyright (c) 2017-2025 by Teddy / Dominik Mahrer - www.railcontrol.org
5
6 RailControl is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 3, or (at your option) any
9 later version.
10
11 RailControl is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 See the GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with RailControl; see the file LICENCE. If not see
18 <http://www.gnu.org/licenses/>.
19 */
20
21 #pragma once
22
23 #include <fstream>
24 #include <string>
25 #include <vector>
26
27 #include "Logger/LoggerClient.h"
28 #include "Logger/LoggerClientConsole.h"
29 #include "Logger/LoggerClientFile.h"
30 #include "Logger/LoggerClientTcp.h"
31
32 namespace Logger
33 {
34 class Logger;
35
36 class LoggerServer
37 {
38 public:
39 LoggerServer(const LoggerServer&) = delete;
40 LoggerServer& operator=(const LoggerServer&) = delete;
41
42 Logger* GetLogger(const std::string& component);
43
44 void Send(const std::string& text);
45
46 static inline LoggerServer& Instance()
47 {
48 static LoggerServer server;
49 return server;
50 }
51
52 inline void AddFileLogger(const std::string& fileName)
53 {
54 if (fileLoggerStarted == true)
55 {
56 return;
57 }
58 clients.push_back(new LoggerClientFile(fileName));
59 fileLoggerStarted = true;
60 }
61
62 inline void AddConsoleLogger()
63 {
64 if (consoleLoggerStarted == true)
65 {
66 return;
67 }
68 clients.push_back(new LoggerClientConsole());
69 consoleLoggerStarted = true;
70 }
71
72 private:
73 inline LoggerServer()
74 : fileLoggerStarted(false),
75 consoleLoggerStarted(false)
76 {
77 }
78
79 ~LoggerServer();
80
81 bool fileLoggerStarted;
82 bool consoleLoggerStarted;
83 std::vector<LoggerClient*> clients;
84 std::vector<Logger*> loggers;
85 };
86 }