#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
-#include <time.h>
+
+#define PRINT_MEM() 0
+#if PRINT_MEM()
+#include <malloc.h>
+#endif
int debug_level = -1;
*/
static void log_puts(enum log_levels level, const char *file, int line, const char *function, const char *string)
{
+ char *f;
if (level == LOG_LVL_OUTPUT)
{
/* do not prepend any headers, just print out what we were given and return */
return;
}
- char *f = strrchr(file, '/');
+ f = strrchr(file, '/');
if (f != NULL)
file = f + 1;
{
/* print with count and time information */
int t=(int)(timeval_ms()-start);
- fprintf(log_output, "%s %d %d %s:%d %s(): %s", log_strings[level+1], count, t, file, line, function, string);
+#if PRINT_MEM()
+ struct mallinfo info;
+ info = mallinfo();
+#endif
+ fprintf(log_output, "%s %d %d %s:%d %s()"
+#if PRINT_MEM()
+ " %d"
+#endif
+ ": %s", log_strings[level+1], count, t, file, line, function,
+#if PRINT_MEM()
+ info.fordblks,
+#endif
+ string);
}
else
{
void log_printf(enum log_levels level, const char *file, int line, const char *function, const char *format, ...)
{
char *string;
+ va_list ap;
count++;
if (level > debug_level)
return;
- va_list ap;
va_start(ap, format);
string = alloc_vprintf(format, ap);
void log_printf_lf(enum log_levels level, const char *file, int line, const char *function, const char *format, ...)
{
char *string;
+ va_list ap;
count++;
if (level > debug_level)
return;
- va_list ap;
va_start(ap, format);
string = alloc_vprintf(format, ap);
for (;;)
{
char *t = string;
+ va_list ap_copy;
+ int ret;
string = realloc(string, size);
if (string == NULL)
{
return NULL;
}
- va_list ap_copy;
va_copy(ap_copy, ap);
- int ret;
ret = vsnprintf(string, size, fmt, ap_copy);
/* NB! The result of the vsnprintf() might be an *EMPTY* string! */
if ((ret >= 0) && ((ret + 1) < size))