Пример #1
0
/**
 * Send a debug message.
 * Do not call this directly -- use PED_DEBUG() instead.
 *
 * level        log level, 0 ~= "print definitely"
 */
void ped_debug ( const int level, const char* file, int line,
                 const char* function, const char* msg, ... )
{
        va_list         arg_list;
        char*           msg_concat = ped_malloc(8192);

        va_start ( arg_list, msg );
                vsnprintf ( msg_concat, 8192, msg, arg_list );
        va_end ( arg_list );

        debug_handler ( level, file, line, function, msg_concat );

        free ( msg_concat );
}
Пример #2
0
void
px_debug(const char *fmt,...)
{
	va_list		ap;

	va_start(ap, fmt);
	if (debug_handler)
	{
		char		buf[512];

		vsnprintf(buf, sizeof(buf), fmt, ap);
		debug_handler(buf);
	}
	va_end(ap);
}
Пример #3
0
void GP_DebugPrint(int level, const char *file, const char *function, int line,
                   const char *fmt, ...)
{
    int i, err;

    err = errno;

    if (!env_used) {
        char *level = getenv("GP_DEBUG");

        env_used = 1;

        if (level != NULL) {
            int new_level = atoi(level);

            if (new_level >= 0) {
                debug_level = new_level;

                GP_DEBUG(1, "Using debug level GP_DEBUG=%i "
                         "from enviroment variable",
                         debug_level);
            }
        }

        GP_DEBUG(1, "GFXprim library version " GP_VER_STR);
    }

    if (level > (int)debug_level)
        goto end;

    /* If handler is set, fill struct msg and call it */
    if (debug_handler) {
        char buf[256];

        va_list va;
        va_start(va, fmt);
        vsnprintf(buf, sizeof(buf), fmt, va);
        va_end(va);

        struct GP_DebugMsg msg = {
            .level = level,
            .file = file,
            .fn = function,
            .line = line,
            .msg = buf,
        };

        debug_handler(&msg);

        goto end;
    }

    for (i = 1; i < level; i++)
        fputc(' ', stderr);

    switch (level) {
    case GP_DEBUG_FATAL:
        GP_DebugPrintCStack();
        fprintf(stderr, "*** FATAL: %s:%s():%u: ", file, function, line);
        break;
    case GP_DEBUG_BUG:
        GP_DebugPrintCStack();
        fprintf(stderr, "*** BUG: %s:%s():%u: ", file, function, line);
        break;
    case GP_DEBUG_WARN:
        fprintf(stderr, "*** WARNING: %s:%s():%u: ", file, function, line);
        break;
    case GP_DEBUG_TODO:
        fprintf(stderr, "*** TODO: %s:%s():%u: ", file, function, line);
        break;
    default:
        fprintf(stderr, "%u: %s:%s():%u: ",
                level, file, function, line);
        break;
    }

    va_list va;
    va_start(va, fmt);
    vfprintf(stderr, fmt, va);
    va_end(va);

    fputc('\n', stderr);
end:
    errno = err;
}