src/SDL_log.c
changeset 7344 3d9397262c10
parent 7343 faf0d8c7dbec
child 7350 302af2a46a66
     1.1 --- a/src/SDL_log.c	Fri Jul 05 00:41:01 2013 -0400
     1.2 +++ b/src/SDL_log.c	Fri Jul 05 00:41:34 2013 -0400
     1.3 @@ -266,6 +266,7 @@
     1.4  SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va_list ap)
     1.5  {
     1.6      char *message;
     1.7 +    size_t len;
     1.8  
     1.9      /* Nothing to do if we don't have an output function */
    1.10      if (!SDL_log_function) {
    1.11 @@ -286,7 +287,18 @@
    1.12      if (!message) {
    1.13          return;
    1.14      }
    1.15 +
    1.16      SDL_vsnprintf(message, SDL_MAX_LOG_MESSAGE, fmt, ap);
    1.17 +
    1.18 +    /* Chop off final endline. */
    1.19 +    len = SDL_strlen(message);
    1.20 +    if ((len > 0) && (message[len-1] == '\n')) {
    1.21 +        message[--len] = '\0';
    1.22 +        if ((len > 0) && (message[len-1] == '\r')) {  /* catch "\r\n", too. */
    1.23 +            message[--len] = '\0';
    1.24 +        }
    1.25 +    }
    1.26 +
    1.27      SDL_log_function(SDL_log_userdata, category, priority, message);
    1.28      SDL_stack_free(message);
    1.29  }
    1.30 @@ -390,9 +402,9 @@
    1.31          char*        output;
    1.32          FILE*        pFile;
    1.33          /* !!! FIXME: is there any reason we didn't just use fprintf() here? */
    1.34 -        length = SDL_strlen(SDL_priority_prefixes[priority]) + 2 + SDL_strlen(message) + 1;
    1.35 +        length = SDL_strlen(SDL_priority_prefixes[priority]) + 2 + SDL_strlen(message) + 2;
    1.36          output = SDL_stack_alloc(char, length);
    1.37 -        SDL_snprintf(output, length, "%s: %s", SDL_priority_prefixes[priority], message);
    1.38 +        SDL_snprintf(output, length, "%s: %s\n", SDL_priority_prefixes[priority], message);
    1.39          pFile = fopen ("SDL_Log.txt", "a");
    1.40          fwrite (output, strlen (output), 1, pFile);
    1.41          SDL_stack_free(output);