diff options
author | Yohann Ferreira <bertram@cegetel.net> | 2005-03-23 22:03:08 +0000 |
---|---|---|
committer | Yohann Ferreira <bertram@cegetel.net> | 2005-03-23 22:03:08 +0000 |
commit | a3c07843e1852980edb9414f3fcb069e5a3e12ec (patch) | |
tree | 02a1fd099830a1055f90c8b22472cd2d6418eadd /src | |
parent | 255da423d061e6f0ee3db009a7ed2c1ec8e60315 (diff) | |
download | mana-a3c07843e1852980edb9414f3fcb069e5a3e12ec.tar.gz mana-a3c07843e1852980edb9414f3fcb069e5a3e12ec.tar.bz2 mana-a3c07843e1852980edb9414f3fcb069e5a3e12ec.tar.xz mana-a3c07843e1852980edb9414f3fcb069e5a3e12ec.zip |
First working implementation of new logger (Step 2/3)
Diffstat (limited to 'src')
-rw-r--r-- | src/log.cpp | 47 | ||||
-rw-r--r-- | src/main.cpp | 48 | ||||
-rw-r--r-- | src/main.h | 1 |
3 files changed, 49 insertions, 47 deletions
diff --git a/src/log.cpp b/src/log.cpp index da6d8fb2..b73b2662 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -29,7 +29,7 @@ FILE* logfile; Logger::Logger(std::string logFilename) { - logFile.open("tmw.log"); + logFile.open(logFilename.c_str(), std::ios_base::trunc); if ( !logFile.is_open() ) { std::cout << "Warning: error while opening log file." << std::endl; @@ -52,19 +52,19 @@ void Logger::log(std::string log_text) time(&t); // Print the log entry - std::string dateString = "["; - dateString += ((((t / 60) / 60) % 24 < 10) ? "0" : ""); - dateString += (((t / 60) / 60) % 24); - dateString += ":"; - dateString += (((t / 60) % 60 < 10) ? "0" : ""); - dateString += ((t / 60) % 60); - dateString += ":"; - dateString += ((t % 60 < 10) ? "0" : ""); - dateString += (t % 60); - dateString += "] "; + logFile << "["; + logFile << ((((t / 60) / 60) % 24 < 10) ? "0" : ""); + logFile << (int)(((t / 60) / 60) % 24); + logFile << ":"; + logFile << (((t / 60) % 60 < 10) ? "0" : ""); + logFile << (int)((t / 60) % 60); + logFile << ":"; + logFile << ((t % 60 < 10) ? "0" : ""); + logFile << (int)(t % 60); + logFile << "] "; // Print the log entry - logFile << dateString << log_text << std::endl; + logFile << log_text << std::endl; } } @@ -85,19 +85,18 @@ void Logger::log(const char *log_text, ...) time(&t); // Print the log entry - std::string dateString = "["; - dateString += ((((t / 60) / 60) % 24 < 10) ? "0" : ""); - dateString += (((t / 60) / 60) % 24); - dateString += ":"; - dateString += (((t / 60) % 60 < 10) ? "0" : ""); - dateString += ((t / 60) % 60); - dateString += ":"; - dateString += ((t % 60 < 10) ? "0" : ""); - dateString += (t % 60); - dateString += "] "; - dateString += buf; + logFile << "["; + logFile << ((((t / 60) / 60) % 24 < 10) ? "0" : ""); + logFile << (int)(((t / 60) / 60) % 24); + logFile << ":"; + logFile << (((t / 60) % 60 < 10) ? "0" : ""); + logFile << (int)((t / 60) % 60); + logFile << ":"; + logFile << ((t % 60 < 10) ? "0" : ""); + logFile << (int)(t % 60); + logFile << "] "; - logFile << dateString << std::endl; + logFile << buf << std::endl; // Delete temporary buffer delete[] buf; diff --git a/src/main.cpp b/src/main.cpp index ef1d1483..9a57555e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -70,6 +70,8 @@ Sound sound; // ini file configuration reader Configuration config; +// Log object +Logger logger("tmw.log2"); /** * Listener used for responding to map start error dialog. @@ -196,7 +198,7 @@ void init_engine() } #ifndef USE_OPENGL if ((int)config.getValue("hwaccel", 0)) { - log("Attempting to use hardware acceleration."); + logger.log("Attempting to use hardware acceleration."); displayFlags |= SDL_HWSURFACE | SDL_DOUBLEBUF; } else { @@ -217,10 +219,10 @@ void init_engine() char videoDriverName[64]; if (SDL_VideoDriverName(videoDriverName, 64)) { - log("Using video driver: %s", videoDriverName); + logger.log("Using video driver: %s", videoDriverName); } else { - log("Using video driver: unkown"); + logger.log("Using video driver: unkown"); } #ifdef USE_OPENGL @@ -229,31 +231,31 @@ void init_engine() glClearColor(0.0f, 0.0f, 0.0f, 0.0f); int gotDoubleBuffer; SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &gotDoubleBuffer); - log("OpenGL is %s double buffering.", + logger.log("OpenGL is %s double buffering.", (gotDoubleBuffer ? "using" : "not using")); #endif const SDL_VideoInfo *vi = SDL_GetVideoInfo(); - log("Possible to create hardware surfaces: %s", + logger.log("Possible to create hardware surfaces: %s", ((vi->hw_available) ? "yes" : "no ")); - log("Window manager available: %s", + logger.log("Window manager available: %s", ((vi->wm_available) ? "yes" : "no")); - log("Accelerated hardware to hardware blits: %s", + logger.log("Accelerated hardware to hardware blits: %s", ((vi->blit_hw) ? "yes" : "no")); - log("Accelerated hardware to hardware colorkey blits: %s", + logger.log("Accelerated hardware to hardware colorkey blits: %s", ((vi->blit_hw_CC) ? "yes" : "no")); - log("Accelerated hardware to hardware alpha blits: %s", + logger.log("Accelerated hardware to hardware alpha blits: %s", ((vi->blit_hw_A) ? "yes" : "no")); - log("Accelerated software to hardware blits: %s", + logger.log("Accelerated software to hardware blits: %s", ((vi->blit_sw) ? "yes" : "no")); - log("Accelerated software to hardware colorkey blits: %s", + logger.log("Accelerated software to hardware colorkey blits: %s", ((vi->blit_sw_CC) ? "yes" : "no")); - log("Accelerated software to hardware alpha blits: %s", + logger.log("Accelerated software to hardware alpha blits: %s", ((vi->blit_sw_A) ? "yes" : "no")); - log("Accelerated color fills: %s", + logger.log("Accelerated color fills: %s", ((vi->blit_fill) ? "yes" : "no")); - log("Available video memory: %d", vi->video_mem); + logger.log("Available video memory: %d", vi->video_mem); //vfmt Pixel format of the video device @@ -269,9 +271,9 @@ void init_engine() Image *hairImg = resman->getImage( "core/graphics/sprites/player_male_hair.png"); - if (!login_wallpaper) error("Couldn't load login_wallpaper.png"); - if (!playerImg) error("Couldn't load player_male_base.png"); - if (!hairImg) error("Couldn't load player_male_hair.png"); + if (!login_wallpaper) logger.error("Couldn't load login_wallpaper.png"); + if (!playerImg) logger.error("Couldn't load player_male_base.png"); + if (!hairImg) logger.error("Couldn't load player_male_hair.png"); playerset = new Spriteset(playerImg, 160, 120); hairset = new Spriteset(hairImg, 40, 40); @@ -296,7 +298,7 @@ void init_engine() catch (const char *err) { state = ERROR; new OkDialog("Sound Engine", err, &initWarningListener); - log("Warning: %s", err); + logger.log("Warning: %s", err); } } @@ -344,20 +346,20 @@ int main(int argc, char *argv[]) switch (state) { case LOGIN: - log("State: LOGIN"); + logger.log("State: LOGIN"); login(); break; case CHAR_SERVER: - log("State: CHAR_SERVER"); + logger.log("State: CHAR_SERVER"); char_server(); break; case CHAR_SELECT: - log("State: CHAR_SELECT"); + logger.log("State: CHAR_SELECT"); charSelect(); break; case GAME: sound.stopBgm(); - log("State: GAME"); + logger.log("State: GAME"); try { map_start(); game(); @@ -379,7 +381,7 @@ int main(int argc, char *argv[]) break; } } - log("State: EXIT"); + logger.log("State: EXIT"); exit_engine(); PHYSFS_deinit(); return 0; @@ -102,5 +102,6 @@ extern unsigned char state; extern Configuration config; extern Sound sound; extern Map *tiledMap; +extern Logger logger; #endif |