00001 #ifdef WIN32
00002 #include <windows.h>
00003 #endif
00004
00005 #include "debug.h"
00006
00007
00008 namespace audiere {
00009
00010 FILE* Log::handle;
00011 int Log::indent_count;
00012
00013
00014 void
00015 Log::Write(const char* str)
00016 {
00017 std::string s(std::string(indent_count * 2, ' ') + str + "\n");
00018
00019 #ifdef WIN32
00020 OutputDebugString(s.c_str());
00021 #endif
00022
00023 EnsureOpen();
00024 if (handle) {
00025 fputs(s.c_str(), handle);
00026 fflush(handle);
00027 }
00028 }
00029
00030
00031 void
00032 Log::EnsureOpen()
00033 {
00034 if (!handle) {
00035
00036 #ifdef WIN32
00037 handle = fopen("C:/audiere_debug.log", "w");
00038 #else
00039 std::string home(getenv("HOME"));
00040 handle = fopen((home + "/audiere_debug.log").c_str(), "w");
00041 if (!handle) {
00042 handle = stderr;
00043 }
00044 #endif
00045
00046 atexit(Close);
00047 }
00048 }
00049
00050
00051 void
00052 Log::Close()
00053 {
00054 fclose(handle);
00055 }
00056
00057 }