Пример #1
0
void KSGLogCallback::log(ACE_Log_Record& log_record)
{
	ACE_TCHAR msg_data[ACE_Log_Record::MAXVERBOSELOGMSGLEN];
	ACE_OS::sprintf(msg_data,"F[%s]L[%d]-%s\n",ACE_LOG_MSG->file()
		,ACE_LOG_MSG->linenum(),log_record.msg_data());
	log_record.msg_data(msg_data);
}
Пример #2
0
  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 ();
  }
Пример #3
0
ssize_t
ACE_Log_Msg_Android_Logcat::log (ACE_Log_Record &log_record)
{
  __android_log_write (
    convert_log_priority (static_cast<ACE_Log_Priority> (log_record.type ())),
    "ACE",
    log_record.msg_data ());
  return 0;
}
int
Logging_Handler::handle_input (ACE_HANDLE)
{
  ssize_t n;
  size_t len;

  // Perform two recv's to emulate record-oriented semantics.  Note
  // that this code is not entirely portable since it relies on the
  // fact that sizeof (ssize_t) is the same on both the sender and
  // receiver side.  To correctly handle this is painful, and we leave
  // it as an exercise for the reader ;-).

  switch (n = this->cli_stream_.recv ((void *) &len, sizeof len))
    {
    case -1:
      ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) %p at host %s\n",
                         "client logger", this->host_name_), -1);
      /* NOTREACHED */
    case 0:
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%P|%t) closing log daemon at host %s (fd = %d)\n",
                         this->host_name_, this->get_handle ()), -1);
      /* NOTREACHED */
    case sizeof (size_t):
      {
        ACE_Log_Record lp;

        len = ntohl (len);
        n = this->cli_stream_.recv_n ((void *) &lp, len);
        if (n != (ssize_t) len)
          ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) %p at host %s\n",
                             "client logger", this->host_name_), -1);
        /* NOTREACHED */

        lp.decode ();

        if (lp.length () == n)
          {
            ACE_DEBUG ((LM_DEBUG, "(%P|%t) "));
            lp.print (this->host_name_, 1);
          }
        else
          ACE_ERROR ((LM_ERROR, "(%P|%t) error, lp.length = %d, n = %d\n",
                      lp.length (), n));
        break;
      }
    default:
      ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) %p at host %s\n",
                         "client logger", this->host_name_), -1);
      /* NOTREACHED */
    }

  return 0;
}
Пример #5
0
//
// log
//
ssize_t CUTS_ACE_Msg_Backend::log (ACE_Log_Record &log_record)
{
  this->logger_.log (log_record.priority (),
                     log_record.msg_data (),
                     log_record.length ());

  // Manually invoke the old message callback
  if (this->old_msg_backend_ != 0)
    this->old_msg_backend_->log (log_record);

  return log_record.length ();
}
Пример #6
0
void
MFC_Log::log(ACE_Log_Record& log_record)
{
  unsigned long priority = log_record.type();
  char Message[512];

  ACE_OS::sprintf(Message,"%d.%03ld %s", log_record.time_stamp().sec(),
  log_record.time_stamp().usec()/ 1000, log_record.msg_data());

#if defined (ACE_WIN32)
  ::OutputDebugString(Message);
#endif /* ACE_WIN32 */
}
void
Logger::log (ACE_Log_Record &log_record)
{
  int use_log_msg = 0;
  if (this->recursive_)
    {
      this->recursive_ = 0;
      use_log_msg = 1;
    }

  if (!this->verbose_logging_)
    {
      if (use_log_msg)
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("Logger::log->%s\n"),
                    log_record.msg_data ()));
#if !defined (ACE_LACKS_IOSTREAM_TOTALLY)
      else
        *ace_file_stream::instance ()->output_file ()
          << "Recursive Logger callback = "
          << log_record.msg_data ()
          << endl;
#endif /* ACE_LACKS_IOSTREAM_TOTALLY */
    }
  else
    {
      ACE_TCHAR verbose_msg[ACE_Log_Record::MAXVERBOSELOGMSGLEN];
      int result = log_record.format_msg (ACE_LOG_MSG->local_host (),
                                          ACE_LOG_MSG->flags (),
                                          verbose_msg);
      if (result == 0)
        {
          if (use_log_msg)
            ACE_DEBUG ((LM_DEBUG,
                        ACE_TEXT ("Logger::log->%s\n"),
                        verbose_msg));
#if !defined (ACE_LACKS_IOSTREAM_TOTALLY)
          else
            *ace_file_stream::instance ()->output_file ()
              << "Recursive Logger callback = "
              << log_record.msg_data ()
              << endl;
#endif /* ACE_LACKS_IOSTREAM_TOTALLY */
        }
    }

  // Cleanup on the way out.
  if (use_log_msg)
    this->recursive_ = 1;
}
Пример #8
0
ssize_t
ACE_Log_Msg_UNIX_Syslog::log (ACE_Log_Record &log_record)
{
  int syslog_priority = this->convert_log_priority (log_record.type ());
  u_long flags = ACE_LOG_MSG->flags ();

  // The UNIX syslog() facility does not support multi-line messages.
  // Break up the message data into separate lines and send each line
  // to the syslog daemon.

  ACE_TCHAR message[ACE_Log_Record::MAXVERBOSELOGMSGLEN];
  ACE_OS::strcpy (message, log_record.msg_data ());
  ACE_TCHAR *strtokp = 0;

  for (ACE_TCHAR *line = ACE_OS::strtok_r (message,
                                           ACE_TEXT ("\n"),
                                           &strtokp);
       line != 0;
       line = ACE_OS::strtok_r (0,
                                ACE_TEXT ("\n"),
                                &strtokp))
    {
      // Format the message line.  Note that the processing for
      // VERBOSE is the same as for VERBOSE_LITE, since syslog()
      // already provides us with the hostname and PID.  However, the
      // timestamp is duplicated (albeit a shortened version) to
      // provide a timestamp with greater precision than that provided
      // by syslog().
      if (ACE_BIT_ENABLED (flags, ACE_Log_Msg::VERBOSE)
          || ACE_BIT_ENABLED (flags, ACE_Log_Msg::VERBOSE_LITE))
        {
          ACE_TCHAR date_and_time[35];
          if (0 == ACE::timestamp (date_and_time, sizeof (date_and_time), 1))
            ACE_OS::strcpy (date_and_time, ACE_TEXT ("<time error>"));
          const ACE_TCHAR *prio_name =
            ACE_Log_Record::priority_name(ACE_Log_Priority(log_record.type()));
          syslog (syslog_priority,
                  "%s: %s: %s",
                  ACE_TEXT_ALWAYS_CHAR (date_and_time),
                  ACE_TEXT_ALWAYS_CHAR (prio_name),
                  ACE_TEXT_ALWAYS_CHAR (line));
        }
      else // No formatting required.
        syslog (syslog_priority, "%s", ACE_TEXT_ALWAYS_CHAR (line));
    }

  return 0;
}
Пример #9
0
// Type based log message receiver
template<ACE_SYNCH_DECL> void
Log_Message_Receiver_Impl<ACE_SYNCH_USE>::log_record (const ACE_TCHAR *hostname,
                                                      ACE_Log_Record &record)
{
  ACE_GUARD (ACE_SYNCH_MUTEX_T, guard, print_lock_);
  record.print (hostname,
                ACE_Log_Msg::instance ()->flags (),
                stderr);
}
void
Logger::log (ACE_Log_Record &log_record)
{
  int use_log_msg = 0;
  if (this->recursive_)
    {
      this->recursive_ = 0;
      use_log_msg = 1;
    }

  if (!this->verbose_logging_)
    {
      if (use_log_msg)
        ACE_DEBUG ((LM_DEBUG,
                    "Logger::log->%s\n",
                    log_record.msg_data ()));
      else
        ACE_OS::printf ("Recursive Logger callback = %s\n",
                        log_record.msg_data ());
    }
  else
    {
      ACE_TCHAR verbose_msg[ACE_Log_Record::MAXVERBOSELOGMSGLEN];
      int result = log_record.format_msg (ACE_LOG_MSG->local_host (),
                                          ACE_LOG_MSG->flags (),
                                          verbose_msg);
      if (result == 0)
        {
          if (use_log_msg)
            ACE_DEBUG ((LM_DEBUG,
                        "Logger::log->%s\n",
                        verbose_msg));
          else
            ACE_OS::printf ("Recursive Logger callback = %s\n",
                            verbose_msg);
        }
    }

  // Cleanup on the way out.
  if (use_log_msg)
    this->recursive_ = 1;
}
Пример #11
0
void ACE_CE_Screen_Output::log(ACE_Log_Record &log_record)
{
    ACE_TCHAR verbose_msg[ACE_Log_Record::MAXVERBOSELOGMSGLEN];
    int result = log_record.format_msg (ACE_TEXT("WindozeCE"),  // host name
                                        0,                          // verbose flag
                                        verbose_msg);

    if (result == 0)
    {
        verbose_msg[ ACE_OS::strlen(verbose_msg) - 1 ] = 0;  // CE does not like '\n' by itself.
        *this << verbose_msg << endl;
    }
}
Пример #12
0
template<ACE_SYNCH_DECL> void
Log_Message_Receiver_Impl<ACE_SYNCH_USE>::log_output (const ACE_TCHAR *hostname,
                                                      ACE_Log_Record &record,
                                                      ostream *outputfile)
{
  if (outputfile != 0)
    {
      ACE_GUARD (ACE_SYNCH_MUTEX_T, guard, print_lock_);
      record.print (hostname,
                    ACE_Log_Msg::instance ()->flags (),
                    *outputfile);
    }
}
Пример #13
0
// Type based log message receiver
template<ACE_SYNCH_DECL> void
Static_Log_Message_Receiver<ACE_SYNCH_USE>::log_record (const ACE_TCHAR *hostname,
                                                        ACE_Log_Record &record)
{
#if defined (ACE_HAS_THREADS)
  static ACE_SYNCH_MUTEX_T lock_;
  ACE_GUARD (ACE_SYNCH_MUTEX_T, guard, lock_);
#endif /* ACE_HAS_THREADS */

  record.print (hostname,
                ACE_Log_Msg::instance ()->flags (),
                stderr);
}
void
Log_Spec_Verify::log (ACE_Log_Record &log_record)
{
  const ACE_TCHAR *b = log_record.msg_data ();
  const ACE_TCHAR *expect = 0;

  if (ACE_OS::strncmp (b, ACE_TEXT ("l1:"), 3) == 0)
    {
      expect = ACE_TEXT ("42");
      b += 4;  //3
    }
  else if (ACE_OS::strncmp (b, ACE_TEXT ("l2:"), 3) == 0)
    {
      expect = ACE_TEXT ("   42");
      b += 3;
    }
  else if (ACE_OS::strncmp (b, ACE_TEXT ("l3N1:"), 4) == 0)
    {
      expect = ACE_TEXT ("0042,Log_Msg");
      b += 4;
    }
  else
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("Log_Spec_Verify, unrecognized test: %s\n"),
                  b));
      this->fail_++;
    }

  if (b != log_record.msg_data () && ACE_OS::strcmp (b, expect) != 0)
    {
      ACE_ERROR ((LM_ERROR, ACE_TEXT ("Test %s failed; expected %s\n"),
                  log_record.msg_data (), expect));
      this->fail_++;
    }

  return;
}
Пример #15
0
int KSGLogBackend::log(ACE_Log_Record& log_record)
{
	if(log_record.type() < _priority )
		return 0;
	ACE_TCHAR msg_data[ACE_Log_Record::MAXVERBOSELOGMSGLEN];
	ACE_OS::sprintf(msg_data,"P[%d]F[%s]L[%d]- %s\n",ACE_OS::thr_self(),ACE_LOG_MSG->file()
		,ACE_LOG_MSG->linenum(),log_record.msg_data());
	log_record.msg_data(msg_data);
	log_record.format_msg(ACE_LOG_MSG->local_host(),ACE_LOG_MSG->flags()
		,msg_data);
	int len = ACE_OS::strlen(msg_data);
	if(_log_app & laStdout)
		ACE_OS::printf(msg_data);
	if(_log_app & laFile)
		log2file(msg_data,len);

#ifndef WIN32
	if(_log_app & laSyslog)
		log2syslog(log_record);
#endif

	return 0;
}
template<ACE_SYNCH_DECL> void
Static_Log_Message_Receiver<ACE_SYNCH_USE>::log_output (char const *hostname,
                                                        ACE_Log_Record &record,
                                                        ostream *outputfile)
{
  if (outputfile != 0)
    {
#if defined (ACE_HAS_THREADS)
      static ACE_SYNCH_MUTEX_T lock_;
      ACE_GUARD (ACE_SYNCH_MUTEX_T, guard, lock_);
#endif /* ACE_HAS_THREADS */
      record.print (hostname,
                    ACE_Log_Msg::instance ()->flags (),
                    *outputfile);
    }
}
Пример #17
0
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 ();
}
Пример #18
0
template <ACE_PEER_STREAM_1, class COUNTER, ACE_SYNCH_DECL, class LMR> int
ACE_Server_Logging_Handler_T<ACE_PEER_STREAM_2, COUNTER, ACE_SYNCH_USE, LMR>::handle_logging_record (void)
{
  ACE_INT32 length;

  // We need to use the ol' two-read trick here since TCP sockets
  // don't support framing natively.  Note that the first call is just
  // a "peek" -- we don't actually remove the data until the second
  // call.  Note that this code is portable as long as ACE_UNIT32 is
  // always 32 bits on both the sender and receiver side.

  switch (this->peer ().recv ((void *) &length,
                              sizeof length,
                              MSG_PEEK))
    {
    default:
    case -1:
      ACE_ERROR_RETURN ((LM_ERROR,
                         "%p at host %s\n",
                         "server logger",
                         this->host_name ()),
                        -1);
      /* NOTREACHED */
    case 0:
      ACE_ERROR_RETURN ((LM_ERROR,
                         "closing log daemon at host %s\n",
                         this->host_name ()),
                        -1);
      /* NOTREACHED */
    case sizeof length:
      {
        ACE_Log_Record lp;

        // Use ACE_NTOHL to get around bug in egcs 2.91.6x.
        length = ACE_NTOHL (length);

#if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
        u_long count = ++this->request_count_;
#  if 0
        ACE_DEBUG ((LM_DEBUG,
                    "request count = %d, length = %d\n",
                    count,
                    length));
#  endif /* 0 */
#endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */

        // Perform the actual <recv> this time.
        ssize_t n = this->peer ().recv_n ((void *) &lp,
                                          length);
        if (n != length)
          ACE_ERROR_RETURN ((LM_ERROR,
                             "%d != %d, %p at host %s\n",
                             n,
                             length,
                             "server logger",
                             this->host_name ()),
                            -1);

        lp.decode ();

        if (lp.length () == n)
          {
            // Send the log record to the log message receiver for
            // processing.
            if (ACE_BIT_ENABLED (ACE_Log_Msg::instance ()->flags (),
                                 ACE_Log_Msg::STDERR))
                receiver ().log_record (this->host_name (),
                                        lp);
            ostream *orig_ostream = ACE_Log_Msg::instance ()->msg_ostream ();
            receiver ().log_output (this->host_name (),
                                    lp,
                                    orig_ostream);
          }
        else
          ACE_ERROR ((LM_ERROR,
                      "error, lp.length = %d, n = %d\n",
                      lp.length (),
                      n));
        return n;
      }
    }

  ACE_NOTREACHED (return -1;)
}
 void log (ACE_Log_Record &log_record)
 {
     log_record.print ( "", 0, cerr );
     log_record.print ( "", ACE_Log_Msg::VERBOSE , cerr );
 }
Пример #20
0
void
Log_Spec_Verify::log (ACE_Log_Record &log_record)
{
  bool use_log_msg = false;
  if (this->recursive_)
    {
      this->recursive_ = false;
      use_log_msg = true;
    }

  if (!use_log_msg)
    {
#if !defined (ACE_LACKS_IOSTREAM_TOTALLY)
      *ace_file_stream::instance ()->output_file ()
        << "Logger callback = "
        << log_record.msg_data ()
        << endl;
#endif /* ACE_LACKS_IOSTREAM_TOTALLY */
    }
  else
    {
      const ACE_TCHAR *b = log_record.msg_data ();
      const ACE_TCHAR *expect = 0;

      ++this->tests_;

      if (ACE_OS::strncmp (b, ACE_TEXT ("l1:"), 3) == 0)
        {
          expect = ACE_TEXT ("42");
          b += 3;
        }
      else if (ACE_OS::strncmp (b, ACE_TEXT ("l2:"), 3) == 0)
        {
          expect = ACE_TEXT ("   42");
          b += 3;
        }
      else if (ACE_OS::strncmp (b, ACE_TEXT ("l3N1:"), 4) == 0)
        {
          expect = ACE_TEXT ("0042,Log_Msg");
          b += 5;
        }
      else if (ACE_OS::strncmp (b, ACE_TEXT ("l4:"), 3) == 0)
        {
          b += 3;
          // Check if we have a string, exact length could vary
          if (b != log_record.msg_data () && ACE_OS::strlen (b) < 15)
            {
              ACE_ERROR ((LM_ERROR, ACE_TEXT ("Test %s failed; expected %d\n"),
                          log_record.msg_data (), ACE_OS::strlen (b)));
              ++this->fail_;
            }
        }
      else
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("Log_Spec_Verify, unrecognized test: %s\n"),
                      b));
          ++this->fail_;
        }

      if (b != log_record.msg_data () && expect && ACE_OS::strcmp (b, expect) != 0)
        {
          ACE_ERROR ((LM_ERROR, ACE_TEXT ("Test %s failed; expected %s\n"),
                      log_record.msg_data (), expect));
          ++this->fail_;
        }
    }

  // Cleanup on the way out.
  if (use_log_msg)
    this->recursive_ = true;
}
Пример #21
0
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;
}
Пример #22
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 */
}
Пример #23
0
void
Log_Spec_Verify::log (ACE_Log_Record &log_record)
{
  bool use_log_msg = false;
  if (this->recursive_)
    {
      this->recursive_ = false;
      use_log_msg = true;
    }

  if (!use_log_msg)
    {
#if !defined (ACE_LACKS_IOSTREAM_TOTALLY)
      *ace_file_stream::instance ()->output_file ()
        << "Logger callback = "
        << log_record.msg_data ()
        << endl;
#endif /* ACE_LACKS_IOSTREAM_TOTALLY */
    }
  else
    {
      const ACE_TCHAR *b = log_record.msg_data ();
      const ACE_TCHAR *expect = 0;

      ++this->tests_;

      if (ACE_OS::strncmp (b, ACE_TEXT ("l1:"), 3) == 0)
        {
          expect = ACE_TEXT ("42");
          b += 3;
        }
      else if (ACE_OS::strncmp (b, ACE_TEXT ("l2:"), 3) == 0)
        {
          expect = ACE_TEXT ("   42");
          b += 3;
        }
      else if (ACE_OS::strncmp (b, ACE_TEXT ("l3N1:"), 4) == 0)
        {
          expect = ACE_TEXT ("0042,Log_Msg");
          b += 5;
        }
      else if (ACE_OS::strncmp (b, ACE_TEXT ("l4:"), 3) == 0)
        {
          b += 3;
          // Check if we have a string, exact length could vary
          if (b != log_record.msg_data () && ACE_OS::strlen (b) < 15)
            {
              ACE_ERROR ((LM_ERROR, ACE_TEXT ("Test %s failed; expected %d\n"),
                          log_record.msg_data (), ACE_OS::strlen (b)));
              ++this->fail_;
            }
        }
        else if (ACE_OS::strncmp (b, ACE_TEXT ("l5:"), 3) == 0)
        {
          b += 3;
          switch (log_record.type())
          {
            case (LM_SHUTDOWN): expect = ACE_TEXT("S"); break;
            case (LM_TRACE): expect = ACE_TEXT("T"); break;
            case (LM_DEBUG): expect = ACE_TEXT("D"); break;
            case (LM_INFO): expect = ACE_TEXT("I"); break;
            case (LM_NOTICE): expect = ACE_TEXT("N"); break;
            case (LM_WARNING): expect = ACE_TEXT("W"); break;
            case (LM_STARTUP): expect = ACE_TEXT("U"); break;
            case (LM_ERROR): expect = ACE_TEXT("E"); break;
            case (LM_CRITICAL): expect = ACE_TEXT("C"); break;
            case (LM_ALERT): expect = ACE_TEXT("A"); break;
            case (LM_EMERGENCY): expect = ACE_TEXT("!"); break;
            default: expect = ACE_TEXT("?"); break;
          }

        }
      else
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("Log_Spec_Verify, unrecognized test: %s\n"),
                      b));
          ++this->fail_;
        }

      if (b != log_record.msg_data () && expect && ACE_OS::strcmp (b, expect) != 0)
        {
          ACE_ERROR ((LM_ERROR, ACE_TEXT ("Test %s failed; expected %s\n"),
                      log_record.msg_data (), expect));
          ++this->fail_;
        }
    }

  // Cleanup on the way out.
  if (use_log_msg)
    this->recursive_ = true;
}