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