ssize_t NDDS_Log_Backend::log (ACE_Log_Record &log_record) { Log_Record *instance (0); instance = Log_RecordTypeSupport::create_data_ex (DDS_BOOLEAN_FALSE); if (instance == 0) { ACE_ERROR ((LM_EMERGENCY, ACE_TEXT ("Unable to create data sample for log record\n"))); return 0; } instance->node = this->node_.c_str (); instance->pid = log_record.pid (); instance->pid = log_record.pid (); instance->message = ACE_TEXT_ALWAYS_CHAR (log_record.msg_data ()); DDS_ReturnCode_t const retval = this->log_record_writer_->write (*instance, DDS_HANDLE_NIL); if (retval != DDS_RETCODE_OK) { ACE_ERROR ((LM_EMERGENCY, ACE_TEXT ("Unable to write log record to DDS\n"))); return 0; } if (instance != 0) { Log_RecordTypeSupport::delete_data_ex (instance, DDS_BOOLEAN_FALSE); } return log_record.msg_data_len (); }
int operator<< (ACE_OutputCDR &cdr, const ACE_Log_Record &log_record) { // The written message length can't be more than 32 bits (ACE_CDR::ULong) // so reduce it here if needed. ACE_CDR::ULong u_msglen = ACE_Utils::truncate_cast<ACE_CDR::ULong> (log_record.msg_data_len ()); // Insert each field from <log_record> into the output CDR stream. cdr << ACE_CDR::Long (log_record.type ()); cdr << ACE_CDR::Long (log_record.pid ()); cdr << ACE_CDR::LongLong (log_record.time_stamp ().sec ()); cdr << ACE_CDR::Long (log_record.time_stamp ().usec ()); cdr << u_msglen; #if defined (ACE_USES_WCHAR) cdr.write_wchar_array (log_record.msg_data (), u_msglen); #else cdr.write_char_array (log_record.msg_data (), u_msglen); #endif /* ACE_USES_WCHAR */ return cdr.good_bit (); }
ssize_t ACE_Log_Msg_NT_Event_Log::log (ACE_Log_Record &log_record) { // Make a copy of the log text and replace any newlines with // CR-LF. Newline characters on their own do not appear correctly in // the event viewer. We allow for a doubling in the size of the msg // data for the worst case of all newlines. const ACE_TCHAR *src_msg_data = log_record.msg_data (); ACE_TCHAR msg_data [(ACE_Log_Record::MAXLOGMSGLEN * 2) + 1]; size_t maxlen = ACE_Log_Record::MAXLOGMSGLEN; if (ACE_Log_Record::MAXLOGMSGLEN > log_record.msg_data_len ()) maxlen = log_record.msg_data_len (); size_t end = 0; for (size_t i = 0, j = 0; i < maxlen; ++i) { if (src_msg_data[i] == '\n') { msg_data[j++] = '\r'; msg_data[j++] = '\n'; } else msg_data[j++] = src_msg_data[i]; end = j; } msg_data[end] = '\0'; // Map the ACE log record type to an event log type. WORD event_type; switch (log_record.type ()) { case LM_STARTUP: case LM_SHUTDOWN: case LM_TRACE: case LM_DEBUG: case LM_INFO: event_type = EVENTLOG_INFORMATION_TYPE; break; case LM_NOTICE: case LM_WARNING: event_type = EVENTLOG_WARNING_TYPE; break; case LM_ERROR: case LM_CRITICAL: case LM_ALERT: case LM_EMERGENCY: default: event_type = EVENTLOG_ERROR_TYPE; break; } // Send the log message to the system event log. const ACE_TCHAR* msgs [1]; msgs[0] = msg_data; if (ACE_TEXT_ReportEvent (this->evlog_handle_, event_type, 0, 0, 0, 1, 0, msgs, 0) == 0) return -1; else return 0; }
ssize_t ACE_Log_Msg_IPC::log (ACE_Log_Record &log_record) { // Serialize the log record using a CDR stream, allocate enough // space for the complete <ACE_Log_Record>. size_t const max_payload_size = 4 // type + 4 // pid + 12 // timestamp + 4 // process id + 4 // data length #if defined (ACE_USES_WCHAR) + (log_record.msg_data_len () * ACE_OutputCDR::wchar_maxbytes()) // message #else + log_record.msg_data_len () // message #endif + ACE_CDR::MAX_ALIGNMENT; // padding; // Insert contents of <log_record> into payload stream. ACE_OutputCDR payload (max_payload_size); payload << log_record; // Get the number of bytes used by the CDR stream. If it becomes desireable // to support payloads more than 4GB, this field will need to be changed // to a 64-bit value. ACE_CDR::ULong length = ACE_Utils::truncate_cast<ACE_CDR::ULong> (payload.total_length ()); // Send a header so the receiver can determine the byte order and // size of the incoming CDR stream. ACE_OutputCDR header (ACE_CDR::MAX_ALIGNMENT + 8); header << ACE_OutputCDR::from_boolean (ACE_CDR_BYTE_ORDER); // Store the size of the payload that follows header << ACE_CDR::ULong (length); // Use an iovec to send both buffer and payload simultaneously. iovec iov[2]; iov[0].iov_base = header.begin ()->rd_ptr (); iov[0].iov_len = 8; iov[1].iov_base = payload.begin ()->rd_ptr (); iov[1].iov_len = length; #if defined (ACE_HAS_STREAM_PIPES) // Use the <putpmsg> API if supported to ensure correct message // queueing according to priority. ACE_Str_Buf header_msg (static_cast<void *> (header.begin ()->rd_ptr ()), static_cast<int> (8)); ACE_Str_Buf payload_msg (static_cast<void *> (payload.begin ()->rd_ptr ()), static_cast<int> (length)); return this->message_queue_.send (&header_msg, &payload_msg, static_cast<int> (log_record.priority ()), MSG_BAND); #else // We're running over sockets, so send header and payload // efficiently using "gather-write". return this->message_queue_.sendv_n (iov, 2); #endif /* ACE_HAS_STREAM_PIPES */ }