예제 #1
0
    void RemoteSyslogAppender::_append(const LoggingEvent& event) {
        const std::string message(_getLayout().format(event));
        size_t messageLength = message.length();
        char *buf = new char [messageLength + 16];
        int priority = _facility + toSyslogPriority(event.priority);
        int preambleLength = sprintf (buf, "<%d>", priority);
        memcpy (buf + preambleLength, message.data(), messageLength);

        sockaddr_in sain;
        sain.sin_family = AF_INET;
        sain.sin_port   = htons (_portNumber);
        // NO, do NOT use htonl on _ipAddr. Is already in network order.
        sain.sin_addr.s_addr = _ipAddr;

        while (messageLength > 0) {
            /* if packet larger than maximum (900 bytes), split
               into two or more syslog packets. */
            if (preambleLength + messageLength > 900) {
                sendto (_socket, buf, 900, 0, (struct sockaddr *) &sain, sizeof (sain));
                messageLength -= (900 - preambleLength);
                std::memmove (buf + preambleLength, buf + 900, messageLength);
                // note: we might need to sleep a bit here
            } else {
                sendto (_socket, buf, preambleLength + messageLength, 0, (struct sockaddr *) &sain, sizeof (sain));
                break;
            }
        }

        delete[] buf;
    }
void SyslogLogger::log(const Level level, const char *format, va_list args) {
	if (level >= getLevel()) {
		std::string format_ident;

		if (requestSpecificIdent_ && threadIdent_.get()) {
			format_ident = ident_ + ":" + *threadIdent_ + ": %s";
		} else {
			format_ident = ident_ + ": %s";
		}

		std::string formatted(1024*10, '\0');

		vsnprintf(const_cast<char *>(formatted.data()), formatted.size(), format, args);
	
		std::string tmp;
		std::stringstream ss(formatted);

		while (ss.good()) {
			std::getline(ss, tmp, '\n');
			syslog(toSyslogPriority(level), format_ident.c_str(), tmp.c_str());
		}
                
		//vsyslog(toSyslogPriority(level), signedFormat.c_str(), args);
	}
}
예제 #3
0
 void SyslogAppender::_append(const LoggingEvent& event) {
     std::string message(_getLayout().format(event));
     int priority = toSyslogPriority(event.priority);
     ::syslog(priority | _facility, "%s", message.c_str());
 }
void SyslogLogger::setLevelInternal(const Level level) {
	priority_ = toSyslogPriority(level);
}
예제 #5
0
void SyslogLogger::log(const Level level, const char *format, va_list args) {
	if (level >= getLevel()) {
		std::string signedFormat = ident_ + ": " + format;
		vsyslog(toSyslogPriority(level), signedFormat.c_str(), args);
	}
}