Exemplo n.º 1
0
// Add a log entry
OsStatus OsSysLog::add(const OsSysLogFacility facility,
                       const OsSysLogPriority priority,
                       const char*            format,
                                              ...)
{
   OsStatus rc = OS_UNSPECIFIED;

   // If the log has not been initialized, print everything
   if (!isTaskPtrNull())
   {
      if (willLog(facility, priority))
      {
         UtlString taskName ;
         OsTaskId_t taskId = 0 ;

         va_list ap;
         va_start(ap, format);

         getTaskInfo(taskName, taskId);

         rc = vadd(taskName.data(), taskId, facility, priority, format, ap);         
         va_end(ap);
      }  
   }
   else
      rc = OS_SUCCESS ;

   return rc;
}
Exemplo n.º 2
0
// Add a log entry
OsStatus OsSysLog::add(const char*            taskName,
                       const int              taskId,
                       const OsSysLogFacility facility,
                       const OsSysLogPriority priority,
                       const char*            format,
                                              ...)
{
   OsStatus rc = OS_UNSPECIFIED;

   // If the log has not been initialized, print everything
   if (isTaskPtrNull())
   {
      // Convert the variable arguments into a single string
      UtlString data ;
      va_list ap;
      va_start(ap, format); 
      myvsprintf(data, format, ap) ;
      data = escape(data) ;
      va_end(ap);

      // Display all of the data
      osPrintf("%s %s %s 0x%08X %s\n", 
            OsSysLog::sFacilityNames[facility], 
            OsSysLog::sPriorityNames[priority],
            (taskName == NULL) ? "" : taskName, 
            taskId,
            data.data()) ;

      rc = OS_SUCCESS ;
   }
   // Otherwise make sure we want to handle the log entry before we process
   // the variable arguments.
   else
   {
      if (willLog(facility, priority))
      {
         va_list ap;
         va_start(ap, format);
         rc = vadd(taskName, taskId, facility, priority, format, ap);
         va_end(ap);
      }  
   }
   return rc;
}
Exemplo n.º 3
0
// Add a log entry
OsStatus OsSysLog::add(const OsSysLogFacility facility,
                       const OsSysLogPriority priority,
                       const char*            format,
                                              ...)
{
   OsStatus rc = OS_UNSPECIFIED;

   // If the log has not been initialized, print everything
   if (!isTaskPtrNull())
   {
      if (willLog(facility, priority))
      {
         UtlString taskName ;
         OsTaskId_t taskId = 0 ;

         va_list ap;
         va_start(ap, format);

         OsTaskBase* pBase = OsTask::getCurrentTask() ;
         if (pBase != NULL)
         {
            taskName = pBase->getName() ;
            pBase->id(taskId) ;
         } else {

             // TODO: should get abstracted into a OsTaskBase method
#ifdef __pingtel_on_posix__
            OsTaskLinux::getCurrentTaskId(taskId );
#endif
            taskName = "Anon";
            // OsTask::getIdString_d(taskName, taskId);
         }

         rc = vadd(taskName.data(), taskId, facility, priority, format, ap);         
         va_end(ap);
      }  
   }
   else
      rc = OS_SUCCESS ;

   return rc;
}
Exemplo n.º 4
0
// Add a log entry given a variable argument list
OsStatus OsSysLog::vadd(const char*            taskName,
                        const OsTaskId_t       taskId,                        
                        const OsSysLogFacility facility,
                        const OsSysLogPriority priority,
                        const char*            format,
                        va_list                ap)
{
   // If the log has not been initialized, print everything to the console
   if (!isTaskPtrNull())
   {
      if (willLog(facility, priority))
      {
         UtlString logData;
         UtlString logEntry;
         myvsprintf(logData, format, ap) ;
         logData = escape(logData) ;

#ifdef ANDROID
         __android_log_print(androidPri(priority), "sipXsyslog", "[%s] %s",
                             OsSysLog::sFacilityNames[facility], logData.data());
#endif

         OsTime timeNow;
         OsDateTime::getCurTime(timeNow); 
         OsDateTime logTime(timeNow);
         
         UtlString   strTime ;
         logTime.getIsoTimeStringZus(strTime) ;
         UtlString   taskHex;
         // TODO: Should get abstracted into a OsTaskBase method
#ifdef __pingtel_on_posix__
         OsTaskLinux::getIdString_X(taskHex, taskId);
#endif

         mysprintf(logEntry, "\"%s\":%d:%s:%s:%s:%s:%s:%s:\"%s\"",
               strTime.data(),
               ++sEventCount,
               OsSysLog::sFacilityNames[facility], 
               OsSysLog::sPriorityNames[priority],
               sHostname.data(),
               (taskName == NULL) ? "" : taskName,
               taskHex.data(),
               sProcessId.data(),
               logData.data()) ;         

         // If the logger for some reason trys to log a message
         // there is a recursive problem.  Drop the message on the
         // floor for now.  This can occur if one of the os utilities
         // logs a message.
         if(strcmp("syslog", taskName) == 0)
         {
             // Just discard the log entry
             //
             // (rschaaf):
             // NOTE: Don't try to use osPrintf() to emit the log entry since this
             // can cause consternation for applications (e.g. CGIs) that expect to
             // use stdout for further processing.
         }
         else
         {
             char* szPtr = strdup(logEntry.data()) ;
             OsSysLogMsg msg(OsSysLogMsg::LOG, szPtr) ;
             OsTime timeout(1000) ;
             OsSysLogTask *pOsSysLogTask = spOsSysLogTask;
             if ( pOsSysLogTask != NULL &&
                  pOsSysLogTask->postMessage(msg, timeout) != OS_SUCCESS)
             {
                 printf("OsSysLog jammed: %s\n", szPtr) ;
                 free(szPtr) ;
                 OsTask::yield() ;
              }
          }
       }
   }

   return OS_SUCCESS ;
}