src/SDL_log.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 30 Oct 2012 12:30:02 -0700
changeset 6616 4f272256d172
parent 6138 4c64952a58fb
child 6717 2acd95060548
child 8337 4a67a3cca43d
permissions -rw-r--r--
Added an assert log category, and NSLog support on Mac OS X and iOS
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
6138
4c64952a58fb Happy New Year!
Sam Lantinga <slouken@libsdl.org>
parents: 6040
diff changeset
     3
  Copyright (C) 1997-2012 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
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    23
/* Simple log messages in SDL */
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    24
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
#include "SDL_log.h"
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    27
#if HAVE_STDIO_H
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
#include <stdio.h>
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
#endif
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 defined(__WIN32__)
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    32
#include "core/windows/SDL_windows.h"
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    33
#elif defined(__ANDROID__)
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    34
#include <android/log.h>
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    35
#endif
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    36
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    37
#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
    38
#define DEFAULT_ASSERT_PRIORITY         SDL_LOG_PRIORITY_WARN
5221
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    39
#define DEFAULT_APPLICATION_PRIORITY    SDL_LOG_PRIORITY_INFO
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    40
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    41
typedef struct SDL_LogLevel
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    42
{
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    43
    int category;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    44
    SDL_LogPriority priority;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    45
    struct SDL_LogLevel *next;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    46
} SDL_LogLevel;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    47
5235
1e28342cb15d Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents: 5223
diff changeset
    48
/* The default log output function */
1e28342cb15d Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents: 5223
diff changeset
    49
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
    50
                          int category, SDL_LogPriority priority,
1e28342cb15d Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents: 5223
diff changeset
    51
                          const char *message);
1e28342cb15d Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents: 5223
diff changeset
    52
5221
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    53
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
    54
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
    55
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
    56
static SDL_LogPriority SDL_application_priority = DEFAULT_APPLICATION_PRIORITY;
5235
1e28342cb15d Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents: 5223
diff changeset
    57
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
    58
static void *SDL_log_userdata = NULL;
5221
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    59
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    60
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
    61
    NULL,
5221
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    62
    "VERBOSE",
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    63
    "DEBUG",
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    64
    "INFO",
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    65
    "WARN",
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    66
    "ERROR",
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    67
    "CRITICAL"
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    68
};
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    69
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    70
#ifdef __ANDROID__
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    71
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
    72
    "APP",
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
    "SYSTEM",
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    75
    "AUDIO",
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    76
    "VIDEO",
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    77
    "RENDER",
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    78
    "INPUT"
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    79
};
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    80
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    81
static int SDL_android_priority[SDL_NUM_LOG_PRIORITIES] = {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    82
    ANDROID_LOG_VERBOSE,
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    83
    ANDROID_LOG_DEBUG,
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    84
    ANDROID_LOG_INFO,
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    85
    ANDROID_LOG_WARN,
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    86
    ANDROID_LOG_ERROR,
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    87
    ANDROID_LOG_FATAL
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    88
};
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    89
#endif /* __ANDROID__ */
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    90
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    91
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    92
void
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    93
SDL_LogSetAllPriority(SDL_LogPriority priority)
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    94
{
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    95
    SDL_LogLevel *entry;
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
    for (entry = SDL_loglevels; entry; entry = entry->next) {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    98
        entry->priority = priority;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    99
    }
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
   100
    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
   101
    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
   102
    SDL_application_priority = priority;
5221
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   103
}
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
void
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   106
SDL_LogSetPriority(int category, SDL_LogPriority priority)
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   107
{
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   108
    SDL_LogLevel *entry;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   109
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   110
    for (entry = SDL_loglevels; entry; entry = entry->next) {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   111
        if (entry->category == category) {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   112
            entry->priority = priority;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   113
            return;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   114
        }
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
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   117
    /* Create a new entry */
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   118
    entry = (SDL_LogLevel *)SDL_malloc(sizeof(*entry));
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   119
    if (entry) {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   120
        entry->category = category;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   121
        entry->priority = priority;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   122
        entry->next = SDL_loglevels;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   123
        SDL_loglevels = entry;
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
}
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   126
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   127
SDL_LogPriority
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   128
SDL_LogGetPriority(int category)
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   129
{
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   130
    SDL_LogLevel *entry;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   131
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   132
    for (entry = SDL_loglevels; entry; entry = entry->next) {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   133
        if (entry->category == category) {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   134
            return entry->priority;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   135
        }
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   136
    }
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
    if (category == SDL_LOG_CATEGORY_APPLICATION) {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   139
        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
   140
    } 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
   141
        return SDL_assert_priority;
5221
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   142
    } else {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   143
        return SDL_default_priority;
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
}
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   146
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   147
void
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   148
SDL_LogResetPriorities(void)
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   149
{
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   150
    SDL_LogLevel *entry;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   151
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   152
    while (SDL_loglevels) {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   153
        entry = SDL_loglevels;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   154
        SDL_loglevels = entry->next;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   155
        SDL_free(entry);
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
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
   158
    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
   159
    SDL_assert_priority = DEFAULT_ASSERT_PRIORITY;
5221
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   160
    SDL_application_priority = DEFAULT_APPLICATION_PRIORITY;
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
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   163
void
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   164
SDL_Log(const char *fmt, ...)
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   165
{
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   166
    va_list ap;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   167
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   168
    va_start(ap, fmt);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   169
    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
   170
    va_end(ap);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   171
}
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
void
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   174
SDL_LogVerbose(int category, const char *fmt, ...)
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   175
{
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   176
    va_list ap;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   177
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   178
    va_start(ap, fmt);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   179
    SDL_LogMessageV(category, SDL_LOG_PRIORITY_VERBOSE, fmt, ap);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   180
    va_end(ap);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   181
}
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
void
5348
16202b090a63 Added missing log debug function
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   184
SDL_LogDebug(int category, const char *fmt, ...)
16202b090a63 Added missing log debug function
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   185
{
16202b090a63 Added missing log debug function
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   186
    va_list ap;
16202b090a63 Added missing log debug function
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   187
16202b090a63 Added missing log debug function
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   188
    va_start(ap, fmt);
16202b090a63 Added missing log debug function
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   189
    SDL_LogMessageV(category, SDL_LOG_PRIORITY_DEBUG, fmt, ap);
16202b090a63 Added missing log debug function
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   190
    va_end(ap);
16202b090a63 Added missing log debug function
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   191
}
16202b090a63 Added missing log debug function
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   192
16202b090a63 Added missing log debug function
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   193
void
5221
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   194
SDL_LogInfo(int category, const char *fmt, ...)
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   195
{
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   196
    va_list ap;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   197
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   198
    va_start(ap, fmt);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   199
    SDL_LogMessageV(category, SDL_LOG_PRIORITY_INFO, fmt, ap);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   200
    va_end(ap);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   201
}
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   202
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   203
void
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   204
SDL_LogWarn(int category, const char *fmt, ...)
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   205
{
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   206
    va_list ap;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   207
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   208
    va_start(ap, fmt);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   209
    SDL_LogMessageV(category, SDL_LOG_PRIORITY_WARN, fmt, ap);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   210
    va_end(ap);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   211
}
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
void
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   214
SDL_LogError(int category, const char *fmt, ...)
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   215
{
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   216
    va_list ap;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   217
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   218
    va_start(ap, fmt);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   219
    SDL_LogMessageV(category, SDL_LOG_PRIORITY_ERROR, fmt, ap);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   220
    va_end(ap);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   221
}
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
void
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   224
SDL_LogCritical(int category, const char *fmt, ...)
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   225
{
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   226
    va_list ap;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   227
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   228
    va_start(ap, fmt);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   229
    SDL_LogMessageV(category, SDL_LOG_PRIORITY_CRITICAL, fmt, ap);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   230
    va_end(ap);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   231
}
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
void
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   234
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
   235
{
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   236
    va_list ap;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   237
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   238
    va_start(ap, fmt);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   239
    SDL_LogMessageV(category, priority, fmt, ap);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   240
    va_end(ap);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   241
}
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
#ifdef __ANDROID__
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   244
static const char *
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   245
GetCategoryPrefix(int category)
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
    if (category < SDL_LOG_CATEGORY_RESERVED1) {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   248
        return SDL_category_prefixes[category];
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   249
    }
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   250
    if (category < SDL_LOG_CATEGORY_CUSTOM) {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   251
        return "RESERVED";
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
    return "CUSTOM";
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   254
}
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   255
#endif /* __ANDROID__ */
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   256
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   257
void
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   258
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
   259
{
5223
ab0d7cecc0f6 Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 5221
diff changeset
   260
    char *message;
5221
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   261
5235
1e28342cb15d Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents: 5223
diff changeset
   262
    /* 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
   263
    if (!SDL_log_function) {
1e28342cb15d Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents: 5223
diff changeset
   264
        return;
1e28342cb15d Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents: 5223
diff changeset
   265
    }
1e28342cb15d Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents: 5223
diff changeset
   266
5221
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   267
    /* Make sure we don't exceed array bounds */
6040
08aa9c1dfed6 Fixed warnings on iOS
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
   268
    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
   269
        return;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   270
    }
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   271
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   272
    /* 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
   273
    if (priority < SDL_LogGetPriority(category)) {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   274
        return;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   275
    }
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   276
5223
ab0d7cecc0f6 Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 5221
diff changeset
   277
    message = SDL_stack_alloc(char, SDL_MAX_LOG_MESSAGE);
ab0d7cecc0f6 Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 5221
diff changeset
   278
    if (!message) {
ab0d7cecc0f6 Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 5221
diff changeset
   279
        return;
ab0d7cecc0f6 Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 5221
diff changeset
   280
    }
ab0d7cecc0f6 Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 5221
diff changeset
   281
    SDL_vsnprintf(message, SDL_MAX_LOG_MESSAGE, fmt, ap);
5235
1e28342cb15d Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents: 5223
diff changeset
   282
    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
   283
    SDL_stack_free(message);
1e28342cb15d Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents: 5223
diff changeset
   284
}
5221
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   285
5235
1e28342cb15d Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents: 5223
diff changeset
   286
static void
1e28342cb15d Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents: 5223
diff changeset
   287
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
   288
              const char *message)
1e28342cb15d Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents: 5223
diff changeset
   289
{
5221
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   290
#if defined(__WIN32__)
5223
ab0d7cecc0f6 Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 5221
diff changeset
   291
    /* Way too many allocations here, urgh */
5221
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   292
    {
5223
ab0d7cecc0f6 Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 5221
diff changeset
   293
        char *output;
ab0d7cecc0f6 Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 5221
diff changeset
   294
        size_t length;
5221
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   295
        LPTSTR tstr;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   296
5223
ab0d7cecc0f6 Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 5221
diff changeset
   297
        length = SDL_strlen(SDL_priority_prefixes[priority]) + 2 + SDL_strlen(message) + 1;
ab0d7cecc0f6 Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 5221
diff changeset
   298
        output = SDL_stack_alloc(char, length);
ab0d7cecc0f6 Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 5221
diff changeset
   299
        SDL_snprintf(output, length, "%s: %s", SDL_priority_prefixes[priority], message);
5221
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   300
        tstr = WIN_UTF8ToString(output);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   301
        OutputDebugString(tstr);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   302
        SDL_free(tstr);
5223
ab0d7cecc0f6 Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 5221
diff changeset
   303
        SDL_stack_free(output);
5221
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   304
    }
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   305
#elif defined(__ANDROID__)
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   306
    {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   307
        char tag[32];
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   308
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   309
        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
   310
        __android_log_write(SDL_android_priority[priority], tag, message);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   311
    }
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
   312
#elif defined(__APPLE__)
4f272256d172 Added an assert log category, and NSLog support on Mac OS X and iOS
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   313
    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
   314
    {
4f272256d172 Added an assert log category, and NSLog support on Mac OS X and iOS
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   315
        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
   316
4f272256d172 Added an assert log category, and NSLog support on Mac OS X and iOS
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   317
        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
   318
        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
   319
            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
   320
            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
   321
            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
   322
            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
   323
        }
4f272256d172 Added an assert log category, and NSLog support on Mac OS X and iOS
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   324
    }
5221
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   325
#endif
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   326
#if HAVE_STDIO_H
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   327
    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
   328
#endif
5235
1e28342cb15d Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents: 5223
diff changeset
   329
}
1e28342cb15d Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents: 5223
diff changeset
   330
1e28342cb15d Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents: 5223
diff changeset
   331
void
1e28342cb15d Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents: 5223
diff changeset
   332
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
   333
{
1e28342cb15d Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents: 5223
diff changeset
   334
    if (callback) {
1e28342cb15d Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents: 5223
diff changeset
   335
        *callback = SDL_log_function;
1e28342cb15d Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents: 5223
diff changeset
   336
    }
1e28342cb15d Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents: 5223
diff changeset
   337
    if (userdata) {
1e28342cb15d Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents: 5223
diff changeset
   338
        *userdata = SDL_log_userdata;
1e28342cb15d Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents: 5223
diff changeset
   339
    }
1e28342cb15d Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents: 5223
diff changeset
   340
}
1e28342cb15d Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents: 5223
diff changeset
   341
1e28342cb15d Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents: 5223
diff changeset
   342
void
1e28342cb15d Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents: 5223
diff changeset
   343
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
   344
{
1e28342cb15d Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents: 5223
diff changeset
   345
    SDL_log_function = callback;
1e28342cb15d Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents: 5223
diff changeset
   346
    SDL_log_userdata = userdata;
5221
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   347
}
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   348
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   349
/* vi: set ts=4 sw=4 expandtab: */