Changeset 14620


Ignore:
Timestamp:
Dec 13, 2015, 10:34:53 AM (5 years ago)
Author:
mikedld
Message:

Print log messages in one OutputDebugString() call (Windows)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/log.c

    r14619 r14620  
    183183      char timestr[64];
    184184      char * message;
     185      size_t message_len;
    185186      struct evbuffer * buf = evbuffer_new ();
    186187      char * base = tr_sys_path_basename (file, NULL);
     
    193194      evbuffer_add_vprintf (buf, fmt, args);
    194195      va_end (args);
    195       evbuffer_add_printf (buf, " (%s:%d)", base, line);
     196      evbuffer_add_printf (buf, " (%s:%d)" TR_NATIVE_EOL_STR, base, line);
    196197      /* FIXME (libevent2) ifdef this out for nonwindows platforms */
    197       message = evbuffer_free_to_str (buf, NULL);
     198      message = evbuffer_free_to_str (buf, &message_len);
    198199      OutputDebugStringA (message);
    199       OutputDebugStringA (TR_NATIVE_EOL_STR);
    200200      if (fp != TR_BAD_SYS_FILE)
    201         tr_sys_file_write_line (fp, message, NULL);
     201        tr_sys_file_write (fp, message, message_len, NULL, NULL);
    202202
    203203      tr_free (message);
     
    220220  const int err = errno; /* message logging shouldn't affect errno */
    221221  char buf[1024];
     222  int buf_len;
    222223  va_list ap;
    223224  tr_lockLock (getMessageLock ());
     
    226227  *buf = '\0';
    227228  va_start (ap, fmt);
    228   evutil_vsnprintf (buf, sizeof (buf), fmt, ap);
     229  buf_len = evutil_vsnprintf (buf, sizeof (buf), fmt, ap);
    229230  va_end (ap);
    230231
    231   OutputDebugStringA (buf);
    232   OutputDebugStringA (TR_NATIVE_EOL_STR);
     232  if (buf_len < 0)
     233    return;
     234
     235#ifdef _WIN32
     236  if ((size_t) buf_len < sizeof (buf) - 3)
     237    {
     238      buf[buf_len + 0] = '\r';
     239      buf[buf_len + 1] = '\n';
     240      buf[buf_len + 2] = '\0';
     241      OutputDebugStringA (buf);
     242      buf[buf_len + 0] = '\0';
     243    }
     244  else
     245    {
     246      OutputDebugStringA (buf);
     247    }
     248#endif
    233249
    234250  if (*buf)
Note: See TracChangeset for help on using the changeset viewer.