Chat-Room 1
A chatroom with multithreaded server & client based on TCP/IP sockets, using boost::asio library in C++.
Logger.h
1#ifndef LOGGER_H
2#define LOGGER_H
3
4#include <iostream>
5#include <fstream> // for including ofstream
6#include <string> // for dealing with names
7#include <ctime> // for writing time
8
15class Logger {
16public:
20 enum Location {
24 };
25
26private:
27 const std::string m_FileName;
28 std::ofstream m_OutStream;
29 const Location m_Location;
30
35 bool init();
36
37protected:
38 std::string m_ClassName;
39
40public:
44 Logger();
45
50 Logger(const Location &loc);
51
57 Logger(const std::string &fileName, const Location &loc);
58
62 Logger(const Logger &) = delete;
63
67 ~Logger();
68
73 bool log();
74
80 bool log(const std::string &message);
81
87 bool log(const std::initializer_list<std::string> &messages);
88};
89
90#endif // LOGGER_H
A class for logging messages to different locations such as text files or databases.
Definition: Logger.h:15
Location
Enum representing the possible logging locations.
Definition: Logger.h:20
@ TEXT_FILE
Log messages to a text file.
Definition: Logger.h:22
@ DISABLED
Logging is disabled.
Definition: Logger.h:21
@ DATABASE
Log messages to a database.
Definition: Logger.h:23
bool log()
Logs an empty string.
Definition: Logger.cpp:43
std::string m_ClassName
The name of the class, intended for use by derived classes.
Definition: Logger.h:38
Logger()
Default constructor that initializes the logger with logging disabled.
Definition: Logger.cpp:3
~Logger()
Destructor that cleans up resources used by the logger.
Definition: Logger.cpp:22
Logger(const Logger &)=delete
Copy constructor is deleted to prevent copying of the logger.