summaryrefslogtreecommitdiff
path: root/src/log.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2004-12-11 01:08:52 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2004-12-11 01:08:52 +0000
commit06c3e2cbf10034bd348376632ccc30de9da97e5d (patch)
treeb17a6f6dd71571aa8192003ecdc976ebb717027f /src/log.cpp
parent2a964c1fa537e58daee14af6a68a3ef0224c8d65 (diff)
downloadmana-client-06c3e2cbf10034bd348376632ccc30de9da97e5d.tar.gz
mana-client-06c3e2cbf10034bd348376632ccc30de9da97e5d.tar.bz2
mana-client-06c3e2cbf10034bd348376632ccc30de9da97e5d.tar.xz
mana-client-06c3e2cbf10034bd348376632ccc30de9da97e5d.zip
Removed Allegro dependency on logger, which now also produces timestamped
categorized messages instead of using the configuration file approach.
Diffstat (limited to 'src/log.cpp')
-rw-r--r--src/log.cpp184
1 files changed, 42 insertions, 142 deletions
diff --git a/src/log.cpp b/src/log.cpp
index f9c42cf7..3fac29e4 100644
--- a/src/log.cpp
+++ b/src/log.cpp
@@ -22,168 +22,68 @@
#include "log.h"
int warning_n; // Keep warning number
+FILE* logfile;
+
#define LOG_FILE "./docs/tmw.log"
-#define LOG_VERSION "0.3"
-void init_log() {
-#ifdef WIN32
- remove(LOG_FILE);
-#else
- unlink(LOG_FILE);
-#endif
- push_config_state();
- set_config_file(LOG_FILE);
-#ifdef WIN32 // for the moment i cant find a valuable unix function for _strdate // Sull
- char date[9];
- set_config_string("Core", "date", _strdate(date));
-#endif
- set_config_string("Core", "log_version", LOG_VERSION);
- set_config_string("Core", "Allegro_ID", allegro_id);
- switch(os_type) {
- case OSTYPE_UNKNOWN:
- set_config_string("Core", "Os", "unknown, or regular MSDOS");
- break;
- case OSTYPE_WIN3:
- set_config_string("Core", "Os", "Windows 3.1 or earlier");
- break;
- case OSTYPE_WIN95:
- set_config_string("Core", "Os", "Windows 95");
- break;
- case OSTYPE_WIN98:
- set_config_string("Core", "Os", "Windows 98");
- break;
- case OSTYPE_WINME:
- set_config_string("Core", "Os", "Windows ME");
- break;
- case OSTYPE_WINNT:
- set_config_string("Core", "Os", "Windows NT");
- break;
- case OSTYPE_WIN2000:
- set_config_string("Core", "Os", "Windows 2000");
- break;
- case OSTYPE_WINXP:
- set_config_string("Core", "Os", "Windows XP");
- break;
- case OSTYPE_OS2:
- set_config_string("Core", "Os", "OS/2");
- break;
- case OSTYPE_WARP:
- set_config_string("Core", "Os", "OS/2 Warp 3");
- break;
- case OSTYPE_DOSEMU:
- set_config_string("Core", "Os", "Linux DOSEMU");
- break;
- case OSTYPE_OPENDOS:
- set_config_string("Core", "Os", "Caldera OpenDOS");
- break;
- case OSTYPE_LINUX:
- set_config_string("Core", "Os", "Linux");
- break;
- case OSTYPE_SUNOS:
- set_config_string("Core", "Os", "SunOS/Solaris");
- break;
- case OSTYPE_FREEBSD:
- set_config_string("Core", "Os", "FreeBSD");
- break;
- case OSTYPE_NETBSD:
- set_config_string("Core", "Os", "NetBSD");
- break;
- case OSTYPE_IRIX:
- set_config_string("Core", "Os", "IRIX");
- break;
- case OSTYPE_QNX:
- set_config_string("Core", "Os", "QNX");
- break;
- case OSTYPE_UNIX:
- set_config_string("Core", "Os", "Unknown Unix variant");
- break;
- case OSTYPE_BEOS:
- set_config_string("Core", "Os", "BeOS");
- break;
- case OSTYPE_MACOS:
- set_config_string("Core", "Os", "MacOS");
- break;
- default:
- set_config_string("Core", "Os", "Unknown");
- break;
- }
- set_config_int("Core", "Os_version", os_version);
- set_config_int("Core", "Os_revision", os_revision);
- if(os_multitasking)set_config_string("Core", "Multitasking", "TRUE");
- else set_config_string("Core", "Multitasking", "FALSE");
-
- set_config_string("Core", "CPU_Vendor", cpu_vendor);
- switch(cpu_family) {
- case 3:
- set_config_string("Core", "CPU_Family", "386");
- break;
- case 4:
- set_config_string("Core", "CPU_Family", "486");
- break;
- case 5:
- set_config_string("Core", "CPU_Family", "Pentium");
- break;
- case 6:
- set_config_string("Core", "CPU_Family", "Pentium II/III/PRO/Athlon");
- break;
- case 15:
- set_config_string("Core", "CPU_Family", "Pentium IV");
- break;
- default:
- set_config_string("Core", "CPU_Family", "Unknown");
- set_config_int("Core", "CPU_Family_ID", cpu_family);
- break;
- }
-
- set_config_int("Core", "CPU_model", cpu_model);
-
- set_config_int("Core", "CPU_capabilities", cpu_capabilities);
- pop_config_state();
-
- warning_n = 0;
-}
-void log(const char *log_section, const char *log_name, const char *log_text) {
- push_config_state();
- set_config_file(LOG_FILE);
- set_config_string(log_section, log_name, log_text);
- pop_config_state();
+void init_log() {
+ logfile = fopen(LOG_FILE, "w");
+ if (!logfile) {
+ printf("Warning: error while opening log file.\n");
+ }
+ warning_n = 0;
}
-void log_hex(const char *log_section, const char *log_name, const short log_value) {
- push_config_state();
- set_config_file(LOG_FILE);
- set_config_hex(log_section, log_name, log_value);
- pop_config_state();
-}
+void log(const char *category, const char *log_text, ...) {
+ if (logfile) {
+ char* buf = new char[1024];
+
+ va_list ap;
+ va_start(ap, log_text);
+ vsprintf(buf, log_text, ap);
+ va_end(ap);
+
+ time_t t;
+ time(&t);
-void log_int(const char *log_section, const char *log_name, const int log_value) {
- push_config_state();
- set_config_file(LOG_FILE);
- set_config_int(log_section, log_name, log_value);
- pop_config_state();
+ fprintf(
+ logfile,
+ "[%s%d:%s%d:%s%d] %s: %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),
+ category, buf
+ );
+ fflush(logfile);
+
+ delete[] buf;
+ }
}
+
void error(const char *error_text) {
- log("Error", "Last_error", error_text);
+ log("Error", error_text);
+
#ifdef WIN32
- MessageBox(NULL, error_text, "Error", MB_ICONERROR|MB_OK);
+ MessageBox(NULL, error_text, "Error", MB_ICONERROR|MB_OK);
#else
- printf("Error: %s", error_text);
+ printf("Error: %s", error_text);
#endif
- exit(1);
+ exit(1);
}
void warning(const char *warning_text) {
- char warning_name[40];
- sprintf(warning_name, "warning_%i", warning_n);
- log("Error", warning_name, warning_text);
+ log("Warning", warning_text);
}
void status(const char *status_text) {
#ifdef DEBUG
- log("Status", "last_function", status_text);
+ log("Status", status_text);
#endif
}