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