Skip to content

Commit

Permalink
add file log switch
Browse files Browse the repository at this point in the history
  • Loading branch information
FayeSpica committed Jun 5, 2024
1 parent 9394cea commit a1d96db
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ macro(tri_option name desc default)
set_property(CACHE "${name}" PROPERTY STRINGS AUTO ON OFF)
endmacro()

option(CHIAKI_ENABLE_FILE_LOG "Enable debug file log" OFF)
option(CHIAKI_ENABLE_TESTS "Enable tests for Chiaki" OFF)
option(CHIAKI_ENABLE_CLI "Enable CLI for Chiaki" OFF)
option(CHIAKI_ENABLE_ANDROID "Enable Android (Use only as part of the Gradle Project)" OFF)
Expand Down
7 changes: 4 additions & 3 deletions lib/src/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,15 @@ CHIAKI_EXPORT void chiaki_log(ChiakiLog *log, ChiakiLogLevel level, const char *
va_start(args, fmt);
int written = vsnprintf(buf, sizeof(buf), fmt, args);
va_end(args);

#ifdef CHIAKI_ENABLE_FILE_LOG
FILE *logFile = fopen("chiaki.log", "a");
if (logFile != NULL) {
fprintf(logFile, "%s\n", msg);
fclose(logFile);
} else {
fprintf(stderr, "Unable to open log file\n");
}
#endif

if(written < 0)
return;
Expand All @@ -94,15 +95,15 @@ CHIAKI_EXPORT void chiaki_log(ChiakiLog *log, ChiakiLogLevel level, const char *
va_start(args, fmt);
written = vsnprintf(msg, written + 1, fmt, args);
va_end(args);

#ifdef CHIAKI_ENABLE_FILE_LOG
FILE *logFile = fopen("chiaki.log", "a");
if (logFile != NULL) {
fprintf(logFile, "%s\n", msg);
fclose(logFile);
} else {
fprintf(stderr, "Unable to open log file\n");
}

#endif
if(written < 0)
{
free(msg);
Expand Down

0 comments on commit a1d96db

Please sign in to comment.