Esempio n. 1
0
int main(int argc, char *argv[])
{
    (void)argc;
    (void)argv;

    /* Current log level is set to ZF_LOG_INFO by defining ZF_LOG_LEVEL
     * before zf_log.h include. All log messages below INFO level will be
     * compiled out.
     */
    ZF_LOGV("Argument of this VERBOSE message will not be evaluated: %i",
            call_exit());
    ZF_LOGI("So you will see that INFO message");

    /* Output log level is set to WARN and then to INFO. Argument of INFO log
     * statement will be evaluated only once (after setting output log level to
     * INFO).
     */
    zf_log_set_output_level(ZF_LOG_WARN);
    int count = 0;
    for (int i = 2; 0 < i--;)
    {
        ZF_LOGI("Argument of this INFO message will be evaluated only once: %i",
                ++count);
        zf_log_set_output_level(ZF_LOG_INFO);
    }
    if (1 != count)
    {
        abort();
    }
    ZF_LOGI("And you will see that INFO message");
    return 0;
}
int main(int argc, char *argv[])
{
	zf_log_set_output_v(ZF_LOG_PUT_STD, mock_output_callback, 0);
	ZF_LOGI("log from cpp, argc=%i", argc);
	ZF_LOGI_MEM(argv, argc * sizeof(*argv), "log from cpp, argv pointers:");
	return 0;
}
Esempio n. 3
0
int main(int argc, char *argv[])
{
	zf_log_set_tag_prefix("hello");

	ZF_LOGI("You will see the number of arguments: %i", argc);
	ZF_LOGD("You will NOT see the first argument: %s", *argv);

	zf_log_set_output_level(ZF_LOG_WARN);
	ZF_LOGW("You will see this WARNING message");
	ZF_LOGI("You will NOT see this INFO message");

	const char data[] =
			"Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
			"Aliquam pharetra orci id velit porttitor tempus.";
	ZF_LOGW_MEM(data, sizeof(data), "Lorem ipsum at %p:", data);

	return 0;
}
Esempio n. 4
0
int main(int argc, char *argv[])
{
	file_output_open("example.log");

	ZF_LOGI("Writing number of arguments to log file: %i", argc);
	ZF_LOGI_MEM(argv, argc * sizeof(*argv), "argv pointers:");

	return 0;
}
Esempio n. 5
0
void test_module()
{
	zf_log_set_output_v(ZF_LOG_PUT_STD, 0, module_output_callback);
	ZF_LOGI("module");
	if (!module_called)
	{
		fprintf(stderr, "module callback was not called\n");
		exit(1);
	}
}
Esempio n. 6
0
static void test_conditional()
{
	ZF_LOG_IF(1 < 2, ZF_LOGI("True"));
	EXPECTED_LINES(1);
	ZF_LOG_IF(2 < 1, ZF_LOGI("False"));
	EXPECTED_LINES(0);

	ZF_LOG_IF(g_forty_two == 42, ZF_LOGI("True"));
	EXPECTED_LINES(1);
	ZF_LOG_IF(g_forty_two != 42, ZF_LOGI("False"));
	EXPECTED_LINES(0);

	ZF_LOG_IF(g_forty_two == 42, ZF_LOGI("True"));
	EXPECTED_LINES(1);
	ZF_LOG_IF(g_forty_two != 42, ZF_LOGI("False"));
	EXPECTED_LINES(0);

	ZF_LOG_IF(forty_two() == 42, ZF_LOGI("True"));
	EXPECTED_LINES(1);
	ZF_LOG_IF(forty_two() != 42, ZF_LOGI("False"));
	EXPECTED_LINES(0);
}
Esempio n. 7
0
static void test_function()
{
	const unsigned line = __LINE__ + 1;
	ZF_LOGI("test message");

	char expected[64];
#if ZF_LOG_SRCLOC_NONE==TEST_SRCLOC
	(void)line;
	*expected = 0;
#endif
#if ZF_LOG_SRCLOC_SHORT==TEST_SRCLOC
	snprintf(expected, sizeof(expected), "@%s:%u",
			 c_filename, line);
#endif
#if ZF_LOG_SRCLOC_LONG==TEST_SRCLOC
	snprintf(expected, sizeof(expected), "%s@%s:%u",
			 __FUNCTION__, c_filename, line);
#endif
	TEST_VERIFY_EQUAL(strcmp(expected, g_srcloc), 0);
}
Esempio n. 8
0
int main(int argc, char *argv[])
{
#if defined(OUTPUT_SYSLOG)
	openlog("custom_output", LOG_CONS|LOG_PERROR|LOG_PID, LOG_USER);
#endif

	const unsigned put_mask =
#if defined(OUTPUT_SYSLOG)
			ZF_LOG_PUT_STD & !ZF_LOG_PUT_CTX;
#else
			ZF_LOG_PUT_STD;
#endif
			;
	zf_log_set_output_v(put_mask, custom_output_callback, 0);

	ZF_LOGI("Number of arguments goes into custom output: %i", argc);
	ZF_LOGI_MEM(argv, argc * sizeof(*argv), "and argv pointers as well:");

#if defined(OUTPUT_SYSLOG)
	closelog();
#endif
	return 0;
}