do not write single chars to log file.

git-svn-id: svn://svn.berlios.de/openocd/trunk@388 b42882b7-edfa-0310-969c-e2dbd0fdcd60
__archive__
oharboe 2008-02-29 11:23:26 +00:00
parent 43126e8f49
commit 0a749feb8e
1 changed files with 39 additions and 23 deletions

View File

@ -48,7 +48,16 @@ static char *log_strings[5] =
static int count = 0; static int count = 0;
/* The log_printfv() serves to somewhat different goals:
*
* - logging
* - feeding low-level info to the user in GDB or Telnet
*
* The latter dictates that strings without newline are not logged, lest there
* will be *MANY log lines when sending one char at the time(e.g.
* target_request.c).
*
*/
static void log_puts(enum log_levels level, const char *file, int line, const char *function, const char *string) static void log_puts(enum log_levels level, const char *file, int line, const char *function, const char *string)
{ {
log_callback_t *cb; log_callback_t *cb;
@ -65,16 +74,23 @@ static void log_puts(enum log_levels level, const char *file, int line, const ch
if (f != NULL) if (f != NULL)
file = f + 1; file = f + 1;
if (debug_level >= LOG_DEBUG) if (strchr(buffer, '\n')!=NULL)
{ {
/* print with count and time information */ if (debug_level >= LOG_DEBUG)
int t=(int)(time(NULL)-start); {
/* print with count and time information */
int t=(int)(time(NULL)-start);
fprintf(log_output, "%s %d %d %s:%d %s(): %s", log_strings[level+1], count, t, file, line, function, string); fprintf(log_output, "%s %d %d %s:%d %s(): %s", log_strings[level+1], count, t, file, line, function, string);
} }
else else
{
/* do not print count and time */
fprintf(log_output, "%s %s:%d %s(): %s", log_strings[level+1], file, line, function, string);
}
} else
{ {
/* do not print count and time */ /* only entire lines are logged. Otherwise it's
fprintf(log_output, "%s %s:%d %s(): %s", log_strings[level+1], file, line, function, string); * single chars intended for the log callbacks. */
} }
fflush(log_output); fflush(log_output);
@ -258,17 +274,17 @@ char *alloc_printf(const char *fmt, va_list ap)
{ {
size *= 2; /* double the buffer size */ size *= 2; /* double the buffer size */
char *t = string; char *t = string;
string = realloc(string, size); string = realloc(string, size);
if (string == NULL) if (string == NULL)
{ {
if (t != NULL) if (t != NULL)
free(t); free(t);
return NULL; return NULL;
} }
int ret; int ret;
ret = vsnprintf(string, size, fmt, ap); ret = vsnprintf(string, size, fmt, ap);
/* NB! The result of the vsnprintf() might be an *EMPTY* string! */ /* NB! The result of the vsnprintf() might be an *EMPTY* string! */
if ((ret >= 0) && ((ret + 1) < size)) if ((ret >= 0) && ((ret + 1) < size))
break; break;
@ -277,5 +293,5 @@ char *alloc_printf(const char *fmt, va_list ap)
} }
/* the returned buffer is by principle guaranteed to be at least one character longer */ /* the returned buffer is by principle guaranteed to be at least one character longer */
return string; return string;
} }