9 #include <netinet/in.h> 23 int const lev = severity.getLevel();
30 <<
"\nERROR LOGGED WITHOUT DESTINATION!\n" 31 <<
"Attaching destination \"cerr\" to ELadministrator by default\n\n";
109 hostname_ = (gethostname(hostname, 1023) == 0) ? hostname :
"Unkonwn Host";
112 hostent* host =
nullptr;
113 host = gethostbyname(hostname);
115 if (host !=
nullptr) {
117 char* ip = inet_ntoa(*(
struct in_addr*)host->h_addr);
121 struct ifaddrs* ifAddrStruct =
nullptr;
122 struct ifaddrs* ifa =
nullptr;
123 void* tmpAddrPtr =
nullptr;
125 if (getifaddrs(&ifAddrStruct)) {
130 for (ifa = ifAddrStruct; ifa !=
nullptr; ifa = ifa->ifa_next) {
131 if (ifa->ifa_addr->sa_family == AF_INET) {
133 tmpAddrPtr = &((
struct sockaddr_in*)ifa->ifa_addr)->sin_addr;
134 char addressBuffer[INET_ADDRSTRLEN];
135 inet_ntop(AF_INET, tmpAddrPtr, addressBuffer, INET_ADDRSTRLEN);
137 }
else if (ifa->ifa_addr->sa_family == AF_INET6) {
139 tmpAddrPtr = &((
struct sockaddr_in6*)ifa->ifa_addr)->sin6_addr;
140 char addressBuffer[INET6_ADDRSTRLEN];
141 inet_ntop(AF_INET6, tmpAddrPtr, addressBuffer, INET6_ADDRSTRLEN);
157 pid_ =
static_cast<long>(getpid());
159 if (applicationName.empty()) {
161 std::stringstream ss;
162 ss <<
"//proc//" <<
pid_ <<
"//cmdline";
163 std::ifstream procfile{ss.str().c_str()};
167 if (procfile.is_open()) {
168 procfile >> procinfo;
172 size_t end = procinfo.find(
'\0');
173 size_t start = procinfo.find_last_of(
'/', end);
175 application_ = procinfo.substr(start + 1, end - start - 1);
184 auto const& xid = msg.
xid();
185 if (xid.hostname().empty()) {
188 if (xid.hostaddr().empty()) {
191 if (xid.application().empty()) {
194 if (xid.pid() == 0) {
ELextendedID const & xid() const
virtual void setHostName(const std::string &hostname)
void for_all_destinations(F f)
ELslProxy< ELhighestSeverityGen > constexpr ELhighestSeverity
virtual void setPID(long pid)
bool hasDestination(std::string const &) const
virtual void setHostAddr(const std::string &hostaddr)
void setApplication(std::string const &application)
std::string const & hostname() const
int severityCount(ELseverityLevel sev) const
void updateMsg_(ErrorObj &msg) const
ELslProxy< ELzeroSeverityGen > constexpr ELzeroSeverity
ELseverityLevel severity() const
destination_collection_t destinations_
virtual void setApplication(const std::string &application)
ELseverityLevel highSeverity_
ELadministrator(ELadministrator const &)=delete
std::array< int, ELseverityLevel::nLevels > severityCounts_
std::string const & hostaddr() const
void resetSeverityCount()
auto default_destinations_config()
ELseverityLevel checkSeverity()
std::string const & application() const