Changeset 1646


Ignore:
Timestamp:
Jul 18, 2012, 6:41:23 PM (8 years ago)
Author:
sam
Message:

core: on Windows, output log messages to the Visual Studio debug window
if appropriate.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/log.cpp

    r1513 r1646  
    1414
    1515#include <cstdio>
     16
     17#ifdef WIN32
     18#   define WIN32_LEAN_AND_MEAN
     19#   include <windows.h>
     20#endif
    1621
    1722#if defined __ANDROID__
     
    3742    __android_log_vprint(ANDROID_LOG_DEBUG, "LOL", fmt, ap);
    3843#else
    39     fprintf(stderr, "DEBUG: ");
    40     vfprintf(stderr, fmt, ap);
     44    Helper("DEBUG: ", fmt, ap);
    4145#endif
    4246    va_end(ap);
     
    5054    __android_log_vprint(ANDROID_LOG_INFO, "LOL", fmt, ap);
    5155#else
    52     fprintf(stderr, "INFO: ");
    53     vfprintf(stderr, fmt, ap);
     56    Helper("INFO: ", fmt, ap);
    5457#endif
    5558    va_end(ap);
     
    6366    __android_log_vprint(ANDROID_LOG_WARN, "LOL", fmt, ap);
    6467#else
    65     fprintf(stderr, "WARN: ");
    66     vfprintf(stderr, fmt, ap);
     68    Helper("WARN: ", fmt, ap);
    6769#endif
    6870    va_end(ap);
     
    7678    __android_log_vprint(ANDROID_LOG_ERROR, "LOL", fmt, ap);
    7779#else
    78     fprintf(stderr, "ERROR: ");
    79     vfprintf(stderr, fmt, ap);
     80    Helper("ERROR: ", fmt, ap);
    8081#endif
    8182    va_end(ap);
    8283}
    8384
     85/*
     86 * Private helper function
     87 */
     88
     89void Log::Helper(char const *prefix, char const *fmt, va_list ap)
     90{
     91#if defined _WIN32
     92    char buf[4096];
     93    vsnprintf(buf, 4095, fmt, ap);
     94    buf[4095] = '\0';
     95    OutputDebugString(prefix);
     96    OutputDebugString(buf);
     97#else
     98    fprintf(stderr, "%s", prefix);
     99    vfprintf(stderr, fmt, ap);
     100#endif
     101}
     102
    84103} /* namespace lol */
    85104
  • trunk/src/log.h

    r905 r1646  
    1919
    2020#include <stdint.h>
     21#include <cstdarg>
    2122
    2223namespace lol
     
    3637    static void Error(char const *format, ...) LOL_FMT_ATTR(1, 2);
    3738#undef LOL_FMT_ATTR
     39
     40private:
     41    static void Helper(char const *prefix, char const *format, va_list ap);
    3842};
    3943
Note: See TracChangeset for help on using the changeset viewer.