debug.cpp

Go to the documentation of this file.
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       char* log = getenv("ADR_LOG_FILE");
00036       if (log && log[0]) {
00037         handle = fopen(log, "w");
00038       } else {
00039         #ifdef WIN32
00040           handle = fopen("C:/audiere_debug.log", "w");
00041         #else
00042           std::string home(getenv("HOME"));
00043           handle = fopen((home + "/audiere_debug.log").c_str(), "w");
00044         #endif
00045       }
00046         
00047       if (!handle) {
00048         handle = stderr;
00049       }
00050 
00051       atexit(Close);
00052     }
00053   }
00054 
00055 
00056   void
00057   Log::Close()
00058   {
00059     fclose(handle);
00060   }
00061 
00062 }

Generated on Mon Feb 13 23:07:45 2006 for audiere by  doxygen 1.4.6