diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-02-13 23:22:52 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-02-13 23:22:52 +0000 |
commit | 25b87e0d02f285fa8bacc4369f1d9251cf815a40 (patch) | |
tree | 7b28f4bf60ac11b1ec77edff528eea8741898f29 /src/log.cpp | |
parent | 00d7a2cee3904a5ef11b884d68b111ce2d7fd8a9 (diff) | |
download | mana-25b87e0d02f285fa8bacc4369f1d9251cf815a40.tar.gz mana-25b87e0d02f285fa8bacc4369f1d9251cf815a40.tar.bz2 mana-25b87e0d02f285fa8bacc4369f1d9251cf815a40.tar.xz mana-25b87e0d02f285fa8bacc4369f1d9251cf815a40.zip |
Now the resource manager will log a bit about images and cleanup.
Diffstat (limited to 'src/log.cpp')
-rw-r--r-- | src/log.cpp | 63 |
1 files changed, 38 insertions, 25 deletions
diff --git a/src/log.cpp b/src/log.cpp index 25d94faf..4a66a223 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -26,26 +26,21 @@ FILE* logfile; +#define LOG_FILE "tmw.log" -#define LOG_FILE "./docs/tmw.log" - -/* - * Initializes log file by opening it for writing. - */ -void init_log() { +void init_log() +{ logfile = fopen(LOG_FILE, "w"); if (!logfile) { printf("Warning: error while opening log file.\n"); } } -/* - * Enter a message in the log with a certain category. The message will be - * timestamped. - */ -void log(const char *category, const char *log_text, ...) { - if (logfile) { +void log(const char *category, const char *log_text, ...) +{ + if (logfile) + { char* buf = new char[1024]; va_list ap; time_t t; @@ -78,11 +73,33 @@ void log(const char *category, const char *log_text, ...) { } } -/* - * Log an error and quit. The error will pop-up in Windows and will be printed - * to standard error everywhere else. - */ -void error(const std::string error_text) { +void log(const std::string &text) +{ + if (logfile) + { + // Get the current system time + time_t t; + time(&t); + + // Print the log entry + fprintf(logfile, + "[%s%d:%s%d:%s%d] %s\n", + (((t / 60) / 60) % 24 < 10) ? "0" : "", + (int)(((t / 60) / 60) % 24), + ((t / 60) % 60 < 10) ? "0" : "", + (int)((t / 60) % 60), + (t % 60 < 10) ? "0" : "", + (int)(t % 60), + text.c_str() + ); + + // Flush the log file + fflush(logfile); + } +} + +void error(const std::string &error_text) +{ log("Error", error_text.c_str()); #ifdef WIN32 @@ -93,16 +110,12 @@ void error(const std::string error_text) { exit(1); } -/* - * Shortcut to log a warning. - */ -void warning(const char *warning_text) { +void warning(const char *warning_text) +{ log("Warning", warning_text); } -/* - * Shortcut to log a status update, will only really be logged in debug mode. - */ -void status(const char *status_text) { +void status(const char *status_text) +{ log("Status", status_text); } |