33 #include <sys/types.h>
53 logfs.exceptions(std::ifstream::failbit | std::ifstream::badbit);
56 setlogmask(LOG_UPTO(LOG_NOTICE));
60 mask = umask(S_IWGRP | S_IWOTH);
63 filename = strdup(LOGFILE);
64 path = dirname(filename);
70 logfs.open(LOGFILE, std::fstream::out | std::fstream::app);
71 if (-1 == chmod(LOGFILE, 0644)) {
72 std::cerr <<
"Failure to set mask for logfile." << std::endl;
74 }
catch (
class std::ios_base::failure ex) {
75 std::cerr <<
"Failure to open logfile '"
76 << LOGFILE <<
"'" << std::endl;
89 std::stringstream text;
91 text << label <<
": " << strerror_r(errno, errbuf,
sizeof(errbuf));
111 syslog(LOG_ERR,
"%s", message.c_str());
112 std::cerr << message << std::endl;
116 syslog(LOG_WARNING,
"%s", message.c_str());
117 std::cerr << message << std::endl;
121 syslog(LOG_INFO,
"%s", message.c_str());
122 std::cout << message << std::endl;
126 syslog(LOG_DEBUG,
"%s", message.c_str());
127 std::cout << message << std::endl;
131 syslog(LOG_NOTICE,
"%s", message.c_str());
132 std::cout << message << std::endl;
138 }
catch (
class std::ios_base::failure ex) {
139 std::cerr <<
"Failure to write to logfile." << std::endl;
181 }
catch (
class std::ios_base::failure ex) {
182 std::cerr <<
"Failure to close logfile." << std::endl;
static void teardown()
Deletes the singleton.
static void setLevel(const enum Level)
Sets message level.
Error, e.g. malfunction of the code, malware detected.
Messaging()
Creates the singleton.
static void error(const std::string &)
Sends an error message based on errno.
~Messaging()
Deletes singleton.
Warning, e.g. file access has been blocked.
Information, e.g. access scanning has started.
Outputs messages to system and application log and to the console.
static void message(const enum Level, const std::string &)
Sends message.
static Messaging * singleton
Singleton responsible for all messages sent.
Debugging information only to be shown in the console.
Level
Message levels available.
static Messaging * getSingleton()
Retrieves the messaging singleton.