static void Log_Stop(void) { if (!Log_IsLogging()) return; fclose(logfile); logfile = NULL; }
void Log_Write(char *s) { if (!Log_IsLogging()) return; VFS_WRITE(memlogfile, s, strlen(s)); // fprintf(logfile, "%s", s); }
void Log_AutoLogging_StartMatch(char *logname) { char extendedname[MAX_OSPATH * 2], *fullname; FILE *templog; void *buf; temp_log_ready = false; if (!match_auto_logconsole.value) return; if (Log_IsLogging()) { if (autologging) { autologging = false; Log_Stop(); } else { Com_Printf("Auto console logging skipped (already logging)\n"); return; } } strlcpy(auto_matchname, logname, sizeof(auto_matchname)); strlcpy (extendedname, TEMP_LOG_NAME, sizeof(extendedname)); COM_ForceExtensionEx (extendedname, ".log", sizeof (extendedname)); fullname = va("%s/%s", MT_TempDirectory(), extendedname); if (!(templog = fopen (fullname, log_readable.value ? "w" : "wb"))) { FS_CreatePath(fullname); if (!(templog = fopen (fullname, log_readable.value ? "w" : "wb"))) { Com_Printf("Error: Couldn't open %s\n", fullname); return; } } buf = Q_calloc(1, LOGFILEBUFFER); if (!buf) { Com_Printf("Not enough memory to allocate log buffer\n"); return; } memlogfile = FSMMAP_OpenVFS(buf, LOGFILEBUFFER); Com_Printf ("Auto console logging commenced\n"); logfile = templog; autologging = true; auto_starttime = cls.realtime; }
static void Log_Stop(void) { int read; vfserrno_t err; char buf[1024]; int size; if (!Log_IsLogging()) return; size = (int) VFS_TELL(memlogfile); VFS_SEEK(memlogfile, 0, SEEK_SET); while (size > 0 && (read = VFS_READ(memlogfile, buf, 1024, &err))) { fwrite(buf, 1, min(read, size), logfile); size -= read; } VFS_CLOSE(memlogfile); fclose(logfile); logfile = NULL; memlogfile = NULL; }
static void Log_log_f(void) { char *fulllogname; FILE *templog; switch (Cmd_Argc()) { case 1: if (autologging) Com_Printf("Auto console logging is in progress\n"); else if (Log_IsLogging()) Com_Printf("Logging to %s\n", logfilename); else Com_Printf("Not logging\n"); return; case 2: if (!strcasecmp(Cmd_Argv(1), "stop")) { if (autologging) { Log_AutoLogging_StopMatch(); } else { if (Log_IsLogging()) { Log_Stop(); Com_Printf("Stopped logging to %s\n", logfilename); } else { Com_Printf("Not logging\n"); } } return; } if (autologging) { Com_Printf("Auto console logging must be stopped first!\n"); return; } if (Log_IsLogging()) { Log_Stop(); Com_Printf("Stopped logging to %s\n", logfilename); } strlcpy(logfilename, Cmd_Argv(1), sizeof(logfilename) - 4); Util_Process_Filename(logfilename); if (!Util_Is_Valid_Filename(logfilename)) { Com_Printf(Util_Invalid_Filename_Msg("filename")); return; } COM_ForceExtensionEx (logfilename, ".log", sizeof (logfilename)); fulllogname = va("%s/%s", Log_LogDirectory(), logfilename); if (!(templog = fopen (fulllogname, log_readable.value ? "w" : "wb"))) { FS_CreatePath(fulllogname); if (!(templog = fopen (fulllogname, log_readable.value ? "w" : "wb"))) { Com_Printf("Error: Couldn't open %s\n", logfilename); return; } } Com_Printf("Logging to %s\n", logfilename); logfile = templog; break; default: Com_Printf("Usage: %s [filename | stop]\n", Cmd_Argv(0)); return; } }
void Log_Write(char *s) { if (!Log_IsLogging()) return; fprintf(logfile, "%s", s); }
void Log_Shutdown(void) { if (Log_IsLogging()) Log_Stop(); }