Exemplo n.º 1
0
tr_log_message *
tr_logGetQueue (void)
{
  tr_log_message * ret;
  tr_lockLock (getMessageLock ());

  ret = myQueue;
  myQueue = NULL;
  myQueueTail = &myQueue;
  myQueueLength = 0;

  tr_lockUnlock (getMessageLock ());
  return ret;
}
Exemplo n.º 2
0
tr_msg_list *
tr_getQueuedMessages( void )
{
    tr_msg_list * ret;
    tr_lockLock( getMessageLock( ) );

    ret = messageQueue;
    messageQueue = NULL;
    messageQueueTail = &messageQueue;

    messageQueueCount = 0;

    tr_lockUnlock( getMessageLock( ) );
    return ret;
}
Exemplo n.º 3
0
void
tr_msg( const char * file, int line,
        tr_msg_level level,
        const char * name,
        const char * fmt, ... )
{
    const int err = errno; /* message logging shouldn't affect errno */
    char buf[1024];
    va_list ap;
    tr_lockLock( getMessageLock( ) );

    /* build the text message */
    *buf = '\0';
    va_start( ap, fmt );
    evutil_vsnprintf( buf, sizeof( buf ), fmt, ap );
    va_end( ap );

    OutputDebugString( buf );

    if( *buf )
    {
        if( messageQueuing )
        {
            tr_msg_list * newmsg;
            newmsg = tr_new0( tr_msg_list, 1 );
            newmsg->level = level;
            newmsg->when = tr_time( );
            newmsg->message = tr_strdup( buf );
            newmsg->file = file;
            newmsg->line = line;
            newmsg->name = tr_strdup( name );

            *messageQueueTail = newmsg;
            messageQueueTail = &newmsg->next;
            ++messageQueueCount;

            if( messageQueueCount > TR_MAX_MSG_LOG )
            {
                tr_msg_list * old = messageQueue;
                messageQueue = old->next;
                old->next = NULL;
                tr_freeMessageList(old);

                --messageQueueCount;

                assert( messageQueueCount == TR_MAX_MSG_LOG );
            }
        }
        else
        {
            char timestr[64];
            FILE * fp;

            fp = tr_getLog( );
            if( fp == NULL )
                fp = stderr;

            tr_getLogTimeStr( timestr, sizeof( timestr ) );

            if( name )
                fprintf( fp, "[%s] %s: %s\n", timestr, name, buf );
            else
                fprintf( fp, "[%s] %s\n", timestr, buf );
            fflush( fp );
        }
    }

    tr_lockUnlock( getMessageLock( ) );
    errno = err;
}
Exemplo n.º 4
0
void tr_msg_init()
{
	getMessageLock();
}
Exemplo n.º 5
0
void
tr_logAddMessage (const char * file,
                  int line,
                  tr_log_level level,
                  const char * name,
                  const char * fmt,
                  ...)
{
  const int err = errno; /* message logging shouldn't affect errno */
  char buf[1024];
  int buf_len;
  va_list ap;
  tr_lockLock (getMessageLock ());

  /* build the text message */
  *buf = '\0';
  va_start (ap, fmt);
  buf_len = evutil_vsnprintf (buf, sizeof (buf), fmt, ap);
  va_end (ap);

  if (buf_len < 0)
    return;

#ifdef _WIN32
  if ((size_t) buf_len < sizeof (buf) - 3)
    {
      buf[buf_len + 0] = '\r';
      buf[buf_len + 1] = '\n';
      buf[buf_len + 2] = '\0';
      OutputDebugStringA (buf);
      buf[buf_len + 0] = '\0';
    }
  else
    {
      OutputDebugStringA (buf);
    }
#endif

  if (*buf)
    {
      if (tr_logGetQueueEnabled ())
        {
          tr_log_message * newmsg;
          newmsg = tr_new0 (tr_log_message, 1);
          newmsg->level = level;
          newmsg->when = tr_time ();
          newmsg->message = tr_strdup (buf);
          newmsg->file = file;
          newmsg->line = line;
          newmsg->name = tr_strdup (name);

          *myQueueTail = newmsg;
          myQueueTail = &newmsg->next;
          ++myQueueLength;

          if (myQueueLength > TR_LOG_MAX_QUEUE_LENGTH)
            {
              tr_log_message * old = myQueue;
              myQueue = old->next;
              old->next = NULL;
              tr_logFreeQueue (old);
              --myQueueLength;
              assert (myQueueLength == TR_LOG_MAX_QUEUE_LENGTH);
            }
        }
      else
        {
          tr_sys_file_t fp;
          char timestr[64];

          fp = tr_logGetFile ();
          if (fp == TR_BAD_SYS_FILE)
            fp = tr_sys_file_get_std (TR_STD_SYS_FILE_ERR, NULL);

          tr_logGetTimeStr (timestr, sizeof (timestr));

          if (name)
            tr_sys_file_write_fmt (fp, "[%s] %s: %s" TR_NATIVE_EOL_STR, NULL, timestr, name, buf);
          else
            tr_sys_file_write_fmt (fp, "[%s] %s" TR_NATIVE_EOL_STR, NULL, timestr, buf);
          tr_sys_file_flush (fp, NULL);
        }
    }

  tr_lockUnlock (getMessageLock ());
  errno = err;
}
Exemplo n.º 6
0
void
tr_logAddMessage (const char * file,
                  int line,
                  tr_log_level level,
                  const char * name,
                  const char * fmt,
                  ...)
{
  const int err = errno; /* message logging shouldn't affect errno */
  char buf[1024];
  va_list ap;
  tr_lockLock (getMessageLock ());

  /* build the text message */
  *buf = '\0';
  va_start (ap, fmt);
  evutil_vsnprintf (buf, sizeof (buf), fmt, ap);
  va_end (ap);

  OutputDebugStringA (buf);

  if (*buf)
    {
      if (tr_logGetQueueEnabled ())
        {
          tr_log_message * newmsg;
          newmsg = tr_new0 (tr_log_message, 1);
          newmsg->level = level;
          newmsg->when = tr_time ();
          newmsg->message = tr_strdup (buf);
          newmsg->file = file;
          newmsg->line = line;
          newmsg->name = tr_strdup (name);

          *myQueueTail = newmsg;
          myQueueTail = &newmsg->next;
          ++myQueueLength;

          if (myQueueLength > TR_LOG_MAX_QUEUE_LENGTH)
            {
              tr_log_message * old = myQueue;
              myQueue = old->next;
              old->next = NULL;
              tr_logFreeQueue (old);
              --myQueueLength;
              assert (myQueueLength == TR_LOG_MAX_QUEUE_LENGTH);
            }
        }
      else
        {
          FILE * fp;
          char timestr[64];

          fp = tr_logGetFile ();
          if (fp == NULL)
            fp = stderr;

          tr_logGetTimeStr (timestr, sizeof (timestr));

          if (name)
            fprintf (fp, "[%s] %s: %s\n", timestr, name, buf);
          else
            fprintf (fp, "[%s] %s\n", timestr, buf);
          fflush (fp);
        }
    }

  tr_lockUnlock (getMessageLock ());
  errno = err;
}