src/SDL_log.c
author David Ludwig <dludwig@pobox.com>
Sun, 27 Oct 2013 21:26:46 -0400
changeset 8535 e8ee0708ef5c
parent 8478 337b5dc0797b
parent 7828 1451063c8ecd
child 8536 a2be4a225f91
permissions -rw-r--r--
WinRT: merged with SDL 2.0.1 codebase
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8535
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
     1
/*
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
     2
  Simple DirectMedia Layer
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
     4
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
     5
  This software is provided 'as-is', without any express or implied
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
     7
  arising from the use of this software.
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
     8
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    11
  freely, subject to the following restrictions:
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    12
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    14
     claim that you wrote the original software. If you use this software
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    16
     appreciated but is not required.
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    18
     misrepresented as being the original software.
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    20
*/
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    21
#include "SDL_config.h"
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    22
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    23
#if defined(__WIN32__)
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    24
#include "core/windows/SDL_windows.h"
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    25
#endif
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    26
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    27
/* Simple log messages in SDL */
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    28
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    29
#include "SDL_log.h"
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    30
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    31
#if HAVE_STDIO_H
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    32
#include <stdio.h>
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    33
#endif
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    34
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    35
#if defined(__ANDROID__)
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    36
#include <android/log.h>
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    37
#endif
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    38
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    39
#define DEFAULT_PRIORITY                SDL_LOG_PRIORITY_CRITICAL
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    40
#define DEFAULT_ASSERT_PRIORITY         SDL_LOG_PRIORITY_WARN
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    41
#define DEFAULT_APPLICATION_PRIORITY    SDL_LOG_PRIORITY_INFO
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    42
#define DEFAULT_TEST_PRIORITY           SDL_LOG_PRIORITY_VERBOSE
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    43
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    44
/* Forward definition of error function */
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    45
extern int SDL_SetError(const char *fmt, ...);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    46
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    47
typedef struct SDL_LogLevel
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    48
{
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    49
    int category;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    50
    SDL_LogPriority priority;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    51
    struct SDL_LogLevel *next;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    52
} SDL_LogLevel;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    53
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    54
/* The default log output function */
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    55
static void SDL_LogOutput(void *userdata,
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    56
                          int category, SDL_LogPriority priority,
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    57
                          const char *message);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    58
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    59
static SDL_LogLevel *SDL_loglevels;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    60
static SDL_LogPriority SDL_default_priority = DEFAULT_PRIORITY;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    61
static SDL_LogPriority SDL_assert_priority = DEFAULT_ASSERT_PRIORITY;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    62
static SDL_LogPriority SDL_application_priority = DEFAULT_APPLICATION_PRIORITY;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    63
static SDL_LogPriority SDL_test_priority = DEFAULT_TEST_PRIORITY;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    64
static SDL_LogOutputFunction SDL_log_function = SDL_LogOutput;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    65
static void *SDL_log_userdata = NULL;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    66
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    67
static const char *SDL_priority_prefixes[SDL_NUM_LOG_PRIORITIES] = {
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    68
    NULL,
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    69
    "VERBOSE",
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    70
    "DEBUG",
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    71
    "INFO",
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    72
    "WARN",
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    73
    "ERROR",
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    74
    "CRITICAL"
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    75
};
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    76
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    77
#ifdef __ANDROID__
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    78
static const char *SDL_category_prefixes[SDL_LOG_CATEGORY_RESERVED1] = {
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    79
    "APP",
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    80
    "ERROR",
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    81
    "SYSTEM",
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    82
    "AUDIO",
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    83
    "VIDEO",
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    84
    "RENDER",
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    85
    "INPUT"
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    86
};
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    87
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    88
static int SDL_android_priority[SDL_NUM_LOG_PRIORITIES] = {
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    89
    ANDROID_LOG_UNKNOWN,
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    90
    ANDROID_LOG_VERBOSE,
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    91
    ANDROID_LOG_DEBUG,
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    92
    ANDROID_LOG_INFO,
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    93
    ANDROID_LOG_WARN,
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    94
    ANDROID_LOG_ERROR,
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    95
    ANDROID_LOG_FATAL
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    96
};
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    97
#endif /* __ANDROID__ */
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    98
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
    99
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   100
void
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   101
SDL_LogSetAllPriority(SDL_LogPriority priority)
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   102
{
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   103
    SDL_LogLevel *entry;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   104
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   105
    for (entry = SDL_loglevels; entry; entry = entry->next) {
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   106
        entry->priority = priority;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   107
    }
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   108
    SDL_default_priority = priority;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   109
    SDL_assert_priority = priority;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   110
    SDL_application_priority = priority;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   111
}
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   112
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   113
void
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   114
SDL_LogSetPriority(int category, SDL_LogPriority priority)
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   115
{
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   116
    SDL_LogLevel *entry;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   117
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   118
    for (entry = SDL_loglevels; entry; entry = entry->next) {
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   119
        if (entry->category == category) {
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   120
            entry->priority = priority;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   121
            return;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   122
        }
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   123
    }
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   124
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   125
    /* Create a new entry */
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   126
    entry = (SDL_LogLevel *)SDL_malloc(sizeof(*entry));
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   127
    if (entry) {
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   128
        entry->category = category;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   129
        entry->priority = priority;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   130
        entry->next = SDL_loglevels;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   131
        SDL_loglevels = entry;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   132
    }
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   133
}
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   134
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   135
SDL_LogPriority
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   136
SDL_LogGetPriority(int category)
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   137
{
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   138
    SDL_LogLevel *entry;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   139
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   140
    for (entry = SDL_loglevels; entry; entry = entry->next) {
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   141
        if (entry->category == category) {
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   142
            return entry->priority;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   143
        }
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   144
    }
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   145
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   146
    if (category == SDL_LOG_CATEGORY_TEST) {
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   147
        return SDL_test_priority;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   148
    } else if (category == SDL_LOG_CATEGORY_APPLICATION) {
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   149
        return SDL_application_priority;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   150
    } else if (category == SDL_LOG_CATEGORY_ASSERT) {
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   151
        return SDL_assert_priority;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   152
    } else {
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   153
        return SDL_default_priority;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   154
    }
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   155
}
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   156
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   157
void
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   158
SDL_LogResetPriorities(void)
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   159
{
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   160
    SDL_LogLevel *entry;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   161
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   162
    while (SDL_loglevels) {
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   163
        entry = SDL_loglevels;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   164
        SDL_loglevels = entry->next;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   165
        SDL_free(entry);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   166
    }
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   167
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   168
    SDL_default_priority = DEFAULT_PRIORITY;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   169
    SDL_assert_priority = DEFAULT_ASSERT_PRIORITY;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   170
    SDL_application_priority = DEFAULT_APPLICATION_PRIORITY;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   171
    SDL_test_priority = DEFAULT_TEST_PRIORITY;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   172
}
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   173
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   174
void
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   175
SDL_Log(const char *fmt, ...)
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   176
{
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   177
    va_list ap;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   178
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   179
    va_start(ap, fmt);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   180
    SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, fmt, ap);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   181
    va_end(ap);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   182
}
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   183
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   184
void
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   185
SDL_LogVerbose(int category, const char *fmt, ...)
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   186
{
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   187
    va_list ap;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   188
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   189
    va_start(ap, fmt);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   190
    SDL_LogMessageV(category, SDL_LOG_PRIORITY_VERBOSE, fmt, ap);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   191
    va_end(ap);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   192
}
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   193
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   194
void
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   195
SDL_LogDebug(int category, const char *fmt, ...)
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   196
{
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   197
    va_list ap;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   198
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   199
    va_start(ap, fmt);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   200
    SDL_LogMessageV(category, SDL_LOG_PRIORITY_DEBUG, fmt, ap);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   201
    va_end(ap);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   202
}
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   203
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   204
void
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   205
SDL_LogInfo(int category, const char *fmt, ...)
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   206
{
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   207
    va_list ap;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   208
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   209
    va_start(ap, fmt);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   210
    SDL_LogMessageV(category, SDL_LOG_PRIORITY_INFO, fmt, ap);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   211
    va_end(ap);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   212
}
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   213
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   214
void
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   215
SDL_LogWarn(int category, const char *fmt, ...)
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   216
{
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   217
    va_list ap;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   218
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   219
    va_start(ap, fmt);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   220
    SDL_LogMessageV(category, SDL_LOG_PRIORITY_WARN, fmt, ap);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   221
    va_end(ap);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   222
}
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   223
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   224
void
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   225
SDL_LogError(int category, const char *fmt, ...)
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   226
{
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   227
    va_list ap;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   228
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   229
    va_start(ap, fmt);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   230
    SDL_LogMessageV(category, SDL_LOG_PRIORITY_ERROR, fmt, ap);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   231
    va_end(ap);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   232
}
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   233
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   234
void
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   235
SDL_LogCritical(int category, const char *fmt, ...)
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   236
{
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   237
    va_list ap;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   238
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   239
    va_start(ap, fmt);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   240
    SDL_LogMessageV(category, SDL_LOG_PRIORITY_CRITICAL, fmt, ap);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   241
    va_end(ap);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   242
}
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   243
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   244
void
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   245
SDL_LogMessage(int category, SDL_LogPriority priority, const char *fmt, ...)
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   246
{
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   247
    va_list ap;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   248
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   249
    va_start(ap, fmt);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   250
    SDL_LogMessageV(category, priority, fmt, ap);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   251
    va_end(ap);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   252
}
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   253
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   254
#ifdef __ANDROID__
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   255
static const char *
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   256
GetCategoryPrefix(int category)
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   257
{
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   258
    if (category < SDL_LOG_CATEGORY_RESERVED1) {
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   259
        return SDL_category_prefixes[category];
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   260
    }
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   261
    if (category < SDL_LOG_CATEGORY_CUSTOM) {
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   262
        return "RESERVED";
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   263
    }
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   264
    return "CUSTOM";
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   265
}
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   266
#endif /* __ANDROID__ */
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   267
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   268
void
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   269
SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va_list ap)
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   270
{
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   271
    char *message;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   272
    size_t len;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   273
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   274
    /* Nothing to do if we don't have an output function */
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   275
    if (!SDL_log_function) {
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   276
        return;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   277
    }
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   278
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   279
    /* Make sure we don't exceed array bounds */
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   280
    if ((int)priority < 0 || priority >= SDL_NUM_LOG_PRIORITIES) {
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   281
        return;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   282
    }
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   283
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   284
    /* See if we want to do anything with this message */
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   285
    if (priority < SDL_LogGetPriority(category)) {
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   286
        return;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   287
    }
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   288
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   289
    message = SDL_stack_alloc(char, SDL_MAX_LOG_MESSAGE);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   290
    if (!message) {
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   291
        return;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   292
    }
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   293
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   294
    SDL_vsnprintf(message, SDL_MAX_LOG_MESSAGE, fmt, ap);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   295
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   296
    /* Chop off final endline. */
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   297
    len = SDL_strlen(message);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   298
    if ((len > 0) && (message[len-1] == '\n')) {
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   299
        message[--len] = '\0';
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   300
        if ((len > 0) && (message[len-1] == '\r')) {  /* catch "\r\n", too. */
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   301
            message[--len] = '\0';
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   302
        }
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   303
    }
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   304
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   305
    SDL_log_function(SDL_log_userdata, category, priority, message);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   306
    SDL_stack_free(message);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   307
}
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   308
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   309
#if defined(__WIN32__)
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   310
/* Flag tracking the attachment of the console: 0=unattached, 1=attached, -1=error */
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   311
static int consoleAttached = 0;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   312
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   313
/* Handle to stderr output of console. */
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   314
static HANDLE stderrHandle = NULL;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   315
#endif
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   316
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   317
static void
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   318
SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority,
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   319
              const char *message)
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   320
{
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   321
#if defined(__WIN32__) || defined(__WINRT__)
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   322
    /* Way too many allocations here, urgh */
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   323
    /* Note: One can't call SDL_SetError here, since that function itself logs. */
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   324
    {
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   325
        char *output;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   326
        size_t length;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   327
        LPTSTR tstr;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   328
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   329
#ifndef __WINRT__
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   330
        BOOL attachResult;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   331
        DWORD attachError;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   332
        unsigned long charsWritten; 
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   333
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   334
        /* Maybe attach console and get stderr handle */
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   335
        if (consoleAttached == 0) {
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   336
            attachResult = AttachConsole(ATTACH_PARENT_PROCESS);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   337
            if (!attachResult) {
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   338
                    attachError = GetLastError();
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   339
                    if (attachError == ERROR_INVALID_HANDLE) {
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   340
                        OutputDebugString(TEXT("Parent process has no console\r\n"));
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   341
                        consoleAttached = -1;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   342
                    } else if (attachError == ERROR_GEN_FAILURE) {
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   343
                         OutputDebugString(TEXT("Could not attach to console of parent process\r\n"));
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   344
                         consoleAttached = -1;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   345
                    } else if (attachError == ERROR_ACCESS_DENIED) {  
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   346
                         /* Already attached */
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   347
                        consoleAttached = 1;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   348
                    } else {
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   349
                        OutputDebugString(TEXT("Error attaching console\r\n"));
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   350
                        consoleAttached = -1;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   351
                    }
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   352
                } else {
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   353
                    /* Newly attached */
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   354
                    consoleAttached = 1;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   355
                }
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   356
			
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   357
                if (consoleAttached == 1) {
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   358
                        stderrHandle = GetStdHandle(STD_ERROR_HANDLE);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   359
                }
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   360
        }
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   361
#endif /* ifndef __WINRT__ */
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   362
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   363
        length = SDL_strlen(SDL_priority_prefixes[priority]) + 2 + SDL_strlen(message) + 1 + 1 + 1;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   364
        output = SDL_stack_alloc(char, length);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   365
        SDL_snprintf(output, length, "%s: %s\r\n", SDL_priority_prefixes[priority], message);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   366
        tstr = WIN_UTF8ToString(output);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   367
        
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   368
        /* Output to debugger */
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   369
        OutputDebugString(tstr);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   370
       
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   371
#ifndef __WINRT__
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   372
        /* Screen output to stderr, if console was attached. */
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   373
        if (consoleAttached == 1) {
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   374
                if (!WriteConsole(stderrHandle, tstr, lstrlen(tstr), &charsWritten, NULL)) {
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   375
                    OutputDebugString(TEXT("Error calling WriteConsole\r\n"));
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   376
                }
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   377
                if (charsWritten == ERROR_NOT_ENOUGH_MEMORY) {
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   378
                    OutputDebugString(TEXT("Insufficient heap memory to write message\r\n"));
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   379
                }
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   380
        }
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   381
#endif /* ifndef __WINRT__ */
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   382
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   383
        SDL_free(tstr);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   384
        SDL_stack_free(output);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   385
    }
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   386
#elif defined(__ANDROID__)
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   387
    {
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   388
        char tag[32];
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   389
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   390
        SDL_snprintf(tag, SDL_arraysize(tag), "SDL/%s", GetCategoryPrefix(category));
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   391
        __android_log_write(SDL_android_priority[priority], tag, message);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   392
    }
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   393
#elif defined(__APPLE__) && defined(SDL_VIDEO_DRIVER_COCOA)
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   394
    /* Technically we don't need SDL_VIDEO_DRIVER_COCOA, but that's where this function is defined for now.
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   395
    */
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   396
    extern void SDL_NSLog(const char *text);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   397
    {
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   398
        char *text;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   399
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   400
        text = SDL_stack_alloc(char, SDL_MAX_LOG_MESSAGE);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   401
        if (text) {
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   402
            SDL_snprintf(text, SDL_MAX_LOG_MESSAGE, "%s: %s", SDL_priority_prefixes[priority], message);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   403
            SDL_NSLog(text);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   404
            SDL_stack_free(text);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   405
            return;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   406
        }
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   407
    }
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   408
#elif defined(__PSP__)
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   409
    {
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   410
        FILE*        pFile;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   411
        pFile = fopen ("SDL_Log.txt", "a");
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   412
        fprintf(pFile, "%s: %s\n", SDL_priority_prefixes[priority], message);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   413
        fclose (pFile);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   414
    }
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   415
#endif
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   416
#if HAVE_STDIO_H
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   417
    fprintf(stderr, "%s: %s\n", SDL_priority_prefixes[priority], message);
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   418
#endif
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   419
}
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   420
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   421
void
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   422
SDL_LogGetOutputFunction(SDL_LogOutputFunction *callback, void **userdata)
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   423
{
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   424
    if (callback) {
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   425
        *callback = SDL_log_function;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   426
    }
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   427
    if (userdata) {
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   428
        *userdata = SDL_log_userdata;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   429
    }
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   430
}
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   431
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   432
void
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   433
SDL_LogSetOutputFunction(SDL_LogOutputFunction callback, void *userdata)
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   434
{
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   435
    SDL_log_function = callback;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   436
    SDL_log_userdata = userdata;
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   437
}
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   438
e8ee0708ef5c WinRT: merged with SDL 2.0.1 codebase
David Ludwig <dludwig@pobox.com>
parents: 8478 7828
diff changeset
   439
/* vi: set ts=4 sw=4 expandtab: */