aboutsummaryrefslogtreecommitdiff
path: root/src/logger.c
diff options
context:
space:
mode:
authorpk33 <pk33@pk33.space>2024-11-04 21:42:06 +0100
committerpk33 <pk33@pk33.space>2024-11-04 21:42:06 +0100
commit146a683b8d8315ef15dc1c9286f0983834f48d88 (patch)
tree44124fbaf1d49c25de8422ed29c7bade0bc11963 /src/logger.c
parent0ffb4f8463e3e06e8d88b7be22f5cb7adb702361 (diff)
downloadengine33-master.tar.gz
Change ui text colour at arbitrary positionHEADmaster
Diffstat (limited to 'src/logger.c')
-rw-r--r--src/logger.c27
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(&currentTime);
m_time = localtime(&currentTime);
-
- 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);
}