Skip to content
Snippets Groups Projects
Commit d75f8050 authored by alexander.lysikov's avatar alexander.lysikov
Browse files

fixed write into the log-file

parent fbf797eb
No related branches found
No related tags found
1 merge request!11fixed write into the log-file
......@@ -56,10 +56,18 @@
*/
bool dap_valid_ascii_symbols(const char *a_dir_path);
/**
* Check the file for exists
*
* @a_file_path filename pathname
* @return true, if file exists
*/
bool dap_file_test(const char * a_file_path)
/**
* Check the directory for exists
*
* @dir_path directory pathname
* @a_dir_path directory pathname
* @return true, if the file is a directory
*/
bool dap_dir_test(const char * a_dir_path);
......
......@@ -142,6 +142,7 @@ uint32_t ansi_seq_color_len[ 16 ];
static char s_last_error[LAST_ERROR_MAX] = {0};
static enum dap_log_level dap_log_level = L_DEBUG;
static FILE *s_log_file = NULL;
static char *s_log_file_path = NULL;
static char log_tag_fmt_str[10];
#ifdef DAP_LOG_HISTORY
......@@ -307,6 +308,9 @@ int dap_common_init( const char *console_title, const char *a_log_file )
dap_fprintf( stderr, "Can't open log file %s to append\n", a_log_file );
return -1;
}
if(s_log_file_path)
DAP_DELETE(s_log_file_path);
s_log_file_path = dap_strdup(a_log_file);
log_page = 0;
log_outindex = 0;
......@@ -336,6 +340,11 @@ void dap_common_deinit( )
if ( s_log_file )
fclose( s_log_file );
if(s_log_file_path){
DAP_DELETE(s_log_file_path);
s_log_file_path = NULL;
}
if ( temp_buffer )
DAP_FREE( temp_buffer );
......@@ -581,8 +590,16 @@ static void *log_thread_proc( void *arg )
fwrite( logstr->str, logstr->len, 1, stdout );
#endif
#endif
if ( s_log_file )
fwrite( logstr->str, logstr->len, 1, s_log_file );
if(s_log_file) {
if(!dap_file_test(s_log_file_path)) {
fclose(s_log_file);
s_log_file = fopen(s_log_file_path, "a");
}
if(s_log_file) {
fwrite(logstr->str, logstr->len, 1, s_log_file);
fflush(s_log_file);
}
}
// fwrite( "1234567890", 5, 1, stdout );
......
......@@ -59,6 +59,30 @@ bool dap_valid_ascii_symbols(const char *a_string)
return true;
}
/**
* Check the file for exists
*
* @a_file_path filename pathname
* @return true, if file exists
*/
bool dap_file_test(const char * a_file_path)
{
if(!a_file_path)
return false;
#ifdef _WIN32
int attr = GetFileAttributesA(a_dir_path);
if(attr != -1 && (attr & FILE_ATTRIBUTE_NORMAL))
return true;
#else
struct stat st;
if (!stat(a_file_path, &st)) {
if (S_ISREG(st.st_mode))
return true;
}
#endif
return false;
}
/**
* Check the directory for exists
*
......@@ -75,9 +99,9 @@ bool dap_dir_test(const char * a_dir_path)
return true;
#else
struct stat st;
if (!stat(a_dir_path, &st)) {
if (S_ISDIR(st.st_mode))
return true;
if(!stat(a_dir_path, &st)) {
if(S_ISDIR(st.st_mode))
return true;
}
#endif
return false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment