diff options
Diffstat (limited to 'src/logger.c')
-rw-r--r-- | src/logger.c | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/logger.c b/src/logger.c index d6bf3f9..c90f364 100644 --- a/src/logger.c +++ b/src/logger.c @@ -15,7 +15,7 @@ Logger __logger; -static char *colours[5] = { +static char *ansiColourPrefix[5] = { "[\x1b[36mD\x1b[37m]", "[\x1b[32mI\x1b[37m]", "[\x1b[35mW\x1b[37m]", @@ -23,6 +23,14 @@ static char *colours[5] = { "[\x1b[31mFl\x1b[37m]", }; +static char uiColourPrefix[5][11] = { + { 6, '[', 'D', 'e', 'b', 'u', 'g', ']', ' ', 1, '\0' }, + { 3, '[', 'I', 'n', 'f', 'o', ']', ' ', 1, '\0', ' ' }, + { 5, '[', 'W', 'a', 'r', 'n', ']', ' ', 1, '\0', ' ' }, + { 8, '[', 'E', 'r', 'r', 'o', 'r', ']', ' ', 1, '\0' }, + { 2, '[', 'F', 'a', 't', 'a', 'l', ']', ' ', 1, '\0' } +}; + Size logger_init( void ) { String logfile[512]; @@ -58,6 +66,8 @@ void logger_term( void ) void logger( Size level, const char *fmt, ... ) { + static char uiString[256]; + time_t currentTime; struct tm *m_time; @@ -68,23 +78,26 @@ void logger( Size level, const char *fmt, ... ) time(¤tTime); m_time = localtime(¤tTime); - - ui_add_message( fmt, args ); /* XXX */ - + snprintf( uiString, 256, "%s%s", uiColourPrefix[level], fmt ); dprintf( __logger.fd, "Engine33 [%02d:%02d:%02d] -", m_time->tm_hour, m_time->tm_min, m_time->tm_sec ); - dprintf( __logger.fd, " %s ", colours[level] ); + dprintf( __logger.fd, " %s ", ansiColourPrefix[level] ); vdprintf(__logger.fd, fmt, args); - if( (level > LOG_INFO) && errno ) { - dprintf( __logger.fd, ". Reason: %s", strerror(errno) ); + if( (level > LOG_INFO) && errno ) + { + String strerr = strerror(errno); + dprintf( __logger.fd, ". Reason: %s", strerr ); + snprintf( uiString, 256, "%s >> %s", uiString, strerr ); errno = 0; } dprintf( __logger.fd, ".\r\n" ); + ui_add_message( uiString, args ); + va_end(args); } |