/src/shared/log.cpp
https://bitbucket.org/vivkin/gam3b00bs/ · C++ · 63 lines · 42 code · 16 blank · 5 comment · 3 complexity · 7b42ac6dd8432f95d915745f01b79cf6 MD5 · raw file
- #include "common.h"
- #include "log.h"
- #include <stdio.h>
- #include <windows.h>
- #include <assert.h>
- //-----------------------------------------------------------------------------
-
- FILE* log_file = 0;
- CRITICAL_SECTION log_mutex;
- //-----------------------------------------------------------------------------
-
- int log_open( const char* path )
- {
- assert(path);
-
- if( log_file )
- fclose(log_file);
-
- log_file = fopen(path, "w");
-
- if( !log_file )
- return 1;
-
- InitializeCriticalSection( &log_mutex );
-
- return 0;
- }
- //-----------------------------------------------------------------------------
-
- void log_write( const char* format, ... )
- {
- assert(format);
- assert(log_file);
-
- EnterCriticalSection( &log_mutex );
-
- va_list ap;
- va_start(ap, format);
- vfprintf(log_file, format, ap);
- va_end(ap);
-
- va_start(ap, format);
- vfprintf( stderr, format, ap );
- va_end(ap);
-
- fprintf(stderr, "\n");
- fprintf(log_file, "\n");
-
- fflush(log_file);
-
- LeaveCriticalSection( &log_mutex );
- }
- //-----------------------------------------------------------------------------
-
- void log_close()
- {
- DeleteCriticalSection( &log_mutex );
-
- if( log_file )
- fclose(log_file);
- log_file = 0;
- }
- //-----------------------------------------------------------------------------