diff options
Diffstat (limited to 'src/utils.cc')
| -rw-r--r-- | src/utils.cc | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/src/utils.cc b/src/utils.cc index 4a3523b..11aa048 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -2,8 +2,9 @@ #include <sys/stat.h> -static void (*ErrorFunction)(const char *Text) = NULL; -static void (*PrintFunction)(int Level, const char *Text) = NULL; +static TErrorFunction *ErrorFunction; +static TPrintFunction *PrintFunction; +static char StandardLogFile[4096]; void SetErrorFunction(TErrorFunction *Function){ ErrorFunction = Function; @@ -13,6 +14,36 @@ void SetPrintFunction(TPrintFunction *Function){ PrintFunction = Function; } +void SetStandardLogFile(const char *FileName){ + strcpy(StandardLogFile, FileName); +} + +void SilentHandler(const char *Text){ + // no-op +} + +void SilentHandler(int Level, const char *Text){ + // no-op +} + +void LogFileHandler(const char *Text){ + if(StandardLogFile[0] == 0){ + return; + } + + FILE *File = fopen(StandardLogFile, "at"); + if(File != NULL){ + fprintf(File, "%s", Text); + if(fclose(File) != 0){ + error("LogfileHandler: Fehler %d beim Schließen der Datei.\n", errno); + } + } +} + +void LogFileHandler(int Level, const char *Text){ + LogFileHandler(Text); +} + void error(const char *Text, ...){ char s[1024]; |
