--- hatari/src/debug/log.c 2019/04/09 08:58:02 1.1.1.8 +++ hatari/src/debug/log.c 2019/04/09 08:59:17 1.1.1.9 @@ -20,6 +20,7 @@ const char Log_fileid[] = "Hatari log.c #include #include #include +#include #include "main.h" #include "configuration.h" @@ -158,6 +159,8 @@ Uint64 LogTraceFlags = TRACE_NONE; FILE *TraceFile = NULL; static FILE *hLogFile = NULL; + +/* local settings, to be able change them temporarily */ static LOGTYPE TextLogLevel; static LOGTYPE AlertDlgLogLevel; @@ -172,6 +175,15 @@ void Log_Default(void) TextLogLevel = LOG_INFO; } +/** + * Set local log levels from configuration values + */ +void Log_SetLevels(void) +{ + TextLogLevel = ConfigureParams.Log.nTextLogLevel; + AlertDlgLogLevel = ConfigureParams.Log.nAlertDlgLogLevel; +} + /*-----------------------------------------------------------------------*/ /** * Initialize the logging and tracing functionality (open the log files etc.). @@ -180,8 +192,7 @@ void Log_Default(void) */ int Log_Init(void) { - TextLogLevel = ConfigureParams.Log.nTextLogLevel; - AlertDlgLogLevel = ConfigureParams.Log.nAlertDlgLogLevel; + Log_SetLevels(); hLogFile = File_Open(ConfigureParams.Log.sLogFileName, "w"); TraceFile = File_Open(ConfigureParams.Log.sTraceFileName, "w"); @@ -215,6 +226,20 @@ void Log_UnInit(void) /*-----------------------------------------------------------------------*/ /** + * Print log prefix when needed + */ +static void Log_PrintPrefix(FILE *fp, LOGTYPE idx) +{ + static const char* prefix[] = LOG_NAMES; + + assert(idx >= 0 && idx < ARRAY_SIZE(prefix)); + if (prefix[idx]) + fprintf(fp, "%s: ", prefix[idx]); +} + + +/*-----------------------------------------------------------------------*/ +/** * Output string to log file */ void Log_Printf(LOGTYPE nType, const char *psFormat, ...) @@ -223,6 +248,7 @@ void Log_Printf(LOGTYPE nType, const cha if (hLogFile && nType <= TextLogLevel) { + Log_PrintPrefix(hLogFile, nType); va_start(argptr, psFormat); vfprintf(hLogFile, psFormat, argptr); va_end(argptr); @@ -244,6 +270,7 @@ void Log_AlertDlg(LOGTYPE nType, const c /* Output to log file: */ if (hLogFile && nType <= TextLogLevel) { + Log_PrintPrefix(hLogFile, nType); va_start(argptr, psFormat); vfprintf(hLogFile, psFormat, argptr); va_end(argptr);