source: trunk/src/log.cpp @ 1646

Last change on this file since 1646 was 1646, checked in by sam, 8 years ago

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

  • Property svn:keywords set to Id
File size: 1.9 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
9//
10
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include <cstdio>
16
17#ifdef WIN32
18#   define WIN32_LEAN_AND_MEAN
19#   include <windows.h>
20#endif
21
22#if defined __ANDROID__
23#   include <android/log.h>
24#else
25#   include <cstdarg>
26#endif
27
28#include "core.h"
29
30namespace lol
31{
32
33/*
34 * Public Log class
35 */
36
37void Log::Debug(char const *fmt, ...)
38{
39    va_list ap;
40    va_start(ap, fmt);
41#if defined __ANDROID__
42    __android_log_vprint(ANDROID_LOG_DEBUG, "LOL", fmt, ap);
43#else
44    Helper("DEBUG: ", fmt, ap);
45#endif
46    va_end(ap);
47}
48
49void Log::Info(char const *fmt, ...)
50{
51    va_list ap;
52    va_start(ap, fmt);
53#if defined __ANDROID__
54    __android_log_vprint(ANDROID_LOG_INFO, "LOL", fmt, ap);
55#else
56    Helper("INFO: ", fmt, ap);
57#endif
58    va_end(ap);
59}
60
61void Log::Warn(char const *fmt, ...)
62{
63    va_list ap;
64    va_start(ap, fmt);
65#if defined __ANDROID__
66    __android_log_vprint(ANDROID_LOG_WARN, "LOL", fmt, ap);
67#else
68    Helper("WARN: ", fmt, ap);
69#endif
70    va_end(ap);
71}
72
73void Log::Error(char const *fmt, ...)
74{
75    va_list ap;
76    va_start(ap, fmt);
77#if defined __ANDROID__
78    __android_log_vprint(ANDROID_LOG_ERROR, "LOL", fmt, ap);
79#else
80    Helper("ERROR: ", fmt, ap);
81#endif
82    va_end(ap);
83}
84
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
103} /* namespace lol */
104
Note: See TracBrowser for help on using the repository browser.