Exemple #1
0
int main(int argc, char** argv)
{
	int rc = 0;
	zlog_category_t *zc = NULL;

	// 初始化库, 给出配置文件路径
	rc = zlog_init("test_hello.conf");
	if (rc) {
		printf("init failed\n");
		return -1;
	}

	// 获取分类名, 表示要打印哪些日志
	zc = zlog_get_category("my_cat");
	if (!zc) {
		printf("get cat fail\n");
		zlog_fini();
		return -2;
	}

	zlog_info(zc, "hello, zlog");

	zlog_fini();
	
	return 0;
}
Exemple #2
0
int main(int argc, char** argv)
{
	int rc;
	zlog_category_t *zc;

	rc = zlog_init("test_mdc.conf");
	if (rc) {
		printf("init failed\n");
		return -1;
	}

	zc = zlog_get_category("my_cat");
	if (!zc) {
		printf("get cat fail\n");
		zlog_fini();
		return -2;
	}


	zlog_info(zc, "1.hello, zlog");

	zlog_put_mdc("myname", "Zhang");

	zlog_info(zc, "2.hello, zlog");

	zlog_put_mdc("myname", "Li");

	zlog_info(zc, "3.hello, zlog");

	zlog_fini();
	
	return 0;
}
Exemple #3
0
int zlog_test()
{
	int rc;
	zlog_category_t *c;

	rc = zlog_init("d:\\tmp\\zlog.conf");
	if (rc) {
		printf("init failed\n");
		return -1;
	}

	c = zlog_get_category("my_cat");
	if (!c) {
		printf("get cat fail\n");
		zlog_fini();

		return -2;
	}


	zlog_info(c, "hello, zlog");
	zlog_debug(c, "hello, zlog");
	zlog_error(c, "hello, zlog");

	zlog_fini();
	printf("exit.\n");

	return 0;
} 
Exemple #4
0
int main(int argc, char** argv)
{
	int rc;
	zlog_category_t *zc;

	rc = zlog_init("test_syslog.conf");
	if (rc) {
		printf("init failed\n");
		return -1;
	}

	zc = zlog_get_category("my_cat");
	if (!zc) {
		printf("get cat fail\n");
		zlog_fini();
		return -2;
	}

	zlog_info(zc, "hello, zlog -- info");
	zlog_error(zc, "hello, zlog -- error");

	zlog_fini();
	
	return 0;
}
Exemple #5
0
int main(int argc, char** argv)
{
	int rc;

	if (argc != 4) {
		fprintf(stderr, "test nprocess nthreads nloop\n");
		exit(1);
	}

	rc = zlog_init("test_press_zlog.conf");
	if (rc) {
		printf("init failed\n");
		return 2;
	}

	zc = zlog_get_category("my_cat");
	if (!zc) {
		printf("get cat failed\n");
		zlog_fini();
		return 3;
	}

	loop_count = atol(argv[3]);
	test(atol(argv[1]), atol(argv[2]));

	zlog_fini();
	
	return 0;
}
Exemple #6
0
int main(int argc, char** argv)
{
	int rc;
	zlog_category_t *zc;
	

	rc = zlog_init("test_conf.conf");
	if (rc) {
		printf("init failed, try zlog-chk-conf test_conf.conf for more detail\n");
		return -1;
	}

	zc = zlog_get_category("my_cat");
	if (!zc) {
		printf("get cat fail\n");
		zlog_fini();
		return -2;
	}

	zlog_info(zc, "hello, zlog");

	zlog_fini();
	printf("log end\n");
	
	return 0;
}
Exemple #7
0
int main(int argc, char** argv)
{
	int rc;
	zlog_category_t *zc;

	rc = zlog_init("test_level.conf");
	if (rc) {
		printf("init failed\n");
		return -1;
	}

	zc = zlog_get_category("my_cat");
	if (!zc) {
		printf("get cat fail\n");
		zlog_fini();
		return -2;
	}

	zlog_trace(zc, "hello, zlog - trace");
	zlog_debug(zc, "hello, zlog - debug");
	zlog_info(zc, "hello, zlog - info");

	zlog_fini();
	
	return 0;
}
Exemple #8
0
int main(int argc, char** argv)
{
	int rc;
	zlog_category_t *zc;

	rc = zlog_init("test_by_roy.conf");
	if (rc) {
		printf("init failed\n");
		return -1;
	}

	zc = zlog_get_category(MY_CATEGORY);
	if (!zc) {
		printf("get cat fail\n");
		zlog_fini();
		return -2;
	}

	zlog_info(zc, "hello, zlog");
	sleep(1);
	zlog_info(zc, "hello, zlog2");
	sleep(2);
	zlog_info(zc, "hello, zlog3");
	zlog_info(zc, "hello, zlog4");

	zlog_fini();
	
	return 0;
}
Exemple #9
0
int main(int argc, char** argv)
{
	int rc; 
	zlog_category_t *zc;
	rc = zlog_init("test_tmp.conf");
	if (rc) {
		printf("init failed\n");
		return -1;
	}

	zc = zlog_get_category("my_cat");
	if (!zc) {
		printf("get cat fail\n");
		zlog_fini();
		return -2;
	}

	zlog_debug(zc, "%s%d");
	zlog_info(zc, "hello, zlog 2");

	sleep(1);

	zlog_info(zc, "hello, zlog 3");
	zlog_debug(zc, "hello, zlog 4");

//	zlog_profile();

	zlog_fini();
	
	return 0;
}
END_TEST

START_TEST( test_borrar_arbol_binario) {

	const tipo_dato VALORES[7] = { 20, 30, 40, 50, 60, 70, 80 };
	const tipo_dato VALORES_FINALES_INORDER[4] = { 40, 60, 70, 80 };

	int resultado = 0;
	tipo_dato valores_preorder_resultado[4] = { 0 };
	arbol_binario_contexto ctx;

	arbol_avl_init(&ctx, NULL, (unsigned long *) VALORES, 7, NULL);

	arbol_binario_borrar_nodo(&ctx.raiz, 20);
	arbol_binario_borrar_nodo(&ctx.raiz, 30);
	arbol_binario_borrar_nodo(&ctx.raiz, 50);

	arbol_binario_colectar_datos_recorrido_inoder(ctx.raiz,
			valores_preorder_resultado, &resultado);

	resultado = memcmp(VALORES_FINALES_INORDER, valores_preorder_resultado, 4);

	caca_log_debug("La secuencia es:");

	arbol_binario_recorrido_inoder(ctx.raiz);

	zlog_fini();

	ck_assert_msg(!resultado, "todo en orden %d", resultado);
}
END_TEST

START_TEST( test_init_grapho_busq_bin) {

	const tipo_dato VALORES[12][3] =
			{ { 1, 2, 66 }, { 2, 8, 330 }, { 3, 1, 50 }, { 1, 4, 3 },
					{ 4, 2, 8 }, { 2, 9, 74 }, { 1, 5, 90 }, { 1, 6, 12 }, { 1,
							7, 83 }, { 8, 3, 45 }, { 8, 5, 5 }, { 5, 7, 53 } };
	/*
	 * 1 8=====D 2 3 4 5 6 7
	 * 2 8=====D 1 8 4 9
	 * 3 8=====D 1 8
	 * 4 8=====D 1 2
	 * 5 8=====D 1 8 7
	 * 6 8=====D 1
	 * 7 8=====D 1 5
	 * 8 8=====D 2 3 5
	 */

	int filas = 12;
	int resultado = 0;
	grafo_contexto ctx;

	caca_log_debug("los valores %p", VALORES);

	resultado = init_grafo((void*) VALORES, filas, &ctx, verdadero, verdadero);

	imprimir_lista_adjacencia(ctx.inicio);
	zlog_fini();

	ck_assert_msg(resultado, "todo en orden %d", resultado);
}
END_TEST

START_TEST( test_borrar_arbol_avl) {

	const tipo_dato VALORES[9] = { 9, 5, 10, 1, 6, 11, 0, 2, 3 };
	const tipo_dato VALORES_FINALES_PREORDER[8] = { 2, 1, 0, 9, 5, 3, 6, 11 };

	int resultado = 0;
	tipo_dato valores_preorder_resultado[8] = { 0 };
	arbol_binario_contexto ctx;

	arbol_avl_init(&ctx, NULL, (unsigned long *) VALORES, 9, NULL);

	caca_log_debug("La secuencia inicial es:");
	arbol_binario_recorrido_preoder(ctx.raiz);

	arbol_avl_borrar(&ctx.raiz, 10);

	arbol_binario_colectar_datos_recorrido_preoder(ctx.raiz,
			valores_preorder_resultado, &resultado);

	resultado = memcmp(VALORES_FINALES_PREORDER, valores_preorder_resultado, 8);

	caca_log_debug("La secuencia final es:");
	arbol_binario_recorrido_preoder(ctx.raiz);

	zlog_fini();

	ck_assert_msg(!resultado, "todo en orden %d", resultado);
}
END_TEST

START_TEST( test_init_arbol_avl) {

	const tipo_dato VALORES[6] = { 10, 20, 30, 40, 50, 25 };
	const tipo_dato VALORES_PREORDER[6] = { 30, 20, 10, 25, 40, 50 };

	int resultado = 0;
	tipo_dato valores_preorder_resultado[6] = { 0 };
	arbol_binario_contexto ctx;

	arbol_avl_init(&ctx, NULL, (unsigned long *) VALORES, 6, NULL);

	arbol_binario_colectar_datos_recorrido_preoder(ctx.raiz,
			valores_preorder_resultado, &resultado);

	resultado = memcmp(VALORES_PREORDER, valores_preorder_resultado, 6);

	caca_log_debug("La secuencia es:");

	arbol_binario_recorrido_preoder(ctx.raiz);

	zlog_fini();

	ck_assert_msg(!resultado, "todo en orden %d", resultado);
}
Exemple #14
0
int s_zlog_init(const char *conf)
{
	int rc;

	rc = zlog_init(conf);
	if (rc) {
		printf("BNC_LOG: init config failed!\n");
		printf("BNC_LOG: Now init to default!\n");

		rc= zlog_init(NULL);
		if(rc){
			printf("BNC_LOG: init to default faild!\n");
			return -1;
		}
	}

	zc = zlog_get_category("bnc_cat");
	if (!zc) {
		printf("BNC_LOG: get cat fail\n");
		printf("BNC_LOG: bnc_log system will not work!");
		zlog_fini();
		return -2;
	};
	
	return 0;
}
Exemple #15
0
int main(int argc, char** argv)
{
	int rc = 0;
	int j = 100;

    	rc = zlog_init("change_rule.conf");
    	if (rc){
    		printf("init failed\n");
        	return 2;
    	}

	zlog_category_t *zc;
	zc = zlog_get_category("yang");

	pthread_t  tid;
	pthread_create(&tid, NULL, work, (void*)("yang"));
	
	while(j-- > 0) {
		zlog_debug(zc, "debuglog");
		zlog_info(zc, "infolog");
		zlog_error(zc, "errorlog");
		sleep(1);
	}

	pthread_join(tid, NULL);
	zlog_fini();
	
	return 0;
}
Exemple #16
0
int log_close()
{
	int returnCode=0;
	if(log!=NULL)
	{
		zlog_fini();
		log=NULL;
	}
	return returnCode;
}
Exemple #17
0
int main(int argc, char *argv[])
{
	int rc = 0;
	int op;
	int quiet = 0;
	static const char *help = 
		"useage: zlog-chk-conf [conf files]...\n"
		"\t-q,\tsuppress non-error message\n"
		"\t-h,\tshow help message\n"
		"zlog version: " ZLOG_VERSION "\n";

#ifndef _MSC_VER
	while((op = getopt(argc, argv, "qhv")) > 0) {
		if (op == 'h') {
			fputs(help, stdout);
			return 0;
		} else if (op == 'q') {
			quiet = 1;
		}
	}

	argc -= optind;
	argv += optind;
#endif

	if (argc == 0) {
		fputs(help, stdout);
		return -1;
	}

#ifdef _MSC_VER
#define setenv(a,b,c) _putenv_s(a,b)
#endif
	setenv("ZLOG_PROFILE_ERROR", "/dev/stderr", 1);
	setenv("ZLOG_CHECK_FORMAT_RULE", "1", 1);

	while (argc > 0) {
		rc = zlog_init(*argv);
		if (rc) {
			printf("\n---[%s] syntax error, see error message above\n",
				*argv);
			exit(2);
		} else {
			zlog_fini();
			if (!quiet) {
				printf("--[%s] syntax right\n", *argv);
			}
		}
		argc--;
		argv++;
	}

	exit(0);
}
END_TEST

START_TEST( test_dijkstra_modificar_valor_nodo) {

	const tipo_dato VALORES[9] = { 9, 5, 10, 1, 6, 11, 0, 2, 3 };
	const tipo_dato VALORES_FINALES_INORDER[10] = { 0, 1, 2, 3, 4, 5, 6, 9, 10 };

	int resultado = 0;
	int num_datos_colectados = 0;
	arbol_binario_contexto ctx;
	cola_prioridad_contexto cpctx;
	tipo_dato valores_preorder_resultado[10] = { 0 };
	nodo_arbol_binario *referencias_directas[11] = { NULL };

	arbol_avl_init(&ctx, NULL, (unsigned long *) VALORES, 9,
			referencias_directas);

	for (int i = 0; i < 11; i++) {
		caca_log_debug("referencias directas indice %d  valor %ld", i,
				ARBOL_AVL_GET_VALOR(*(referencias_directas + i)));
	}

	caca_log_debug("La secuencia inicial es:");
	arbol_binario_recorrido_inoder(ctx.raiz);

	cola_prioridad_init(&cpctx, NULL, NULL, NULL, 0, &ctx,
			referencias_directas);

	cola_prioridad_modificar_valor_nodo(&cpctx, 6, 4);

	arbol_binario_colectar_datos_recorrido_inoder(ctx.raiz,
			valores_preorder_resultado, &num_datos_colectados);

	for (int i = 0; i < 11; i++) {
		caca_log_debug("eien pressure %d %ld", i,
				*(valores_preorder_resultado + i));
		caca_log_debug("referencias directas indice %ld, valor %ld",
				ARBOL_AVL_GET_INDICE(*(referencias_directas + i)),
				ARBOL_AVL_GET_VALOR(*(referencias_directas + i)));
	}

	resultado = num_datos_colectados == 9
			&& !memcmp(VALORES_FINALES_INORDER, valores_preorder_resultado, 9)
			&& (*(referencias_directas + 6))->valor == 4;

	caca_log_debug("La secuencia final es:");
	arbol_binario_recorrido_inoder(ctx.raiz);

	zlog_fini();

	ck_assert_msg(resultado,
			"los datos colectados %d, el valor en el indice 5 ",
			num_datos_colectados);
}
Exemple #19
0
void zlogInit(std::string path)
{
    rc =zlog_init(path.c_str());
    if (rc)
    {
        printf("init failed\n");
        zlog_fini();
        return;
    }

    zc = zlog_get_category("my_cat");
}
Exemple #20
0
int main(int argc, char** argv)
{
	int rc;
	int k;
	int i;

	if (argc != 2) {
		printf("test_leak ntime\n");
		return -1;
	}

	rc = zlog_init("test_leak.conf");

	k = atoi(argv[1]);
	while (k-- > 0) {
		i = rand();
		switch (i % 4) {
		case 0:
			rc = dzlog_init("test_leak.conf", "xxx");
			dzlog_info("init");
			break;
		case 1:
			rc = zlog_reload(NULL);
			dzlog_info("reload null");
			break;
		case 2:
			rc = zlog_reload("test_leak.2.conf");
			dzlog_info("reload 2");
			break;
		case 3:
			zlog_fini();
			printf("fini\n");
	//		printf("zlog_finish\tj=[%d], rc=[%d]\n", j, rc);
			break;
		}
	}

	zlog_fini();
	return 0;
}
Exemple #21
0
/* Architecture note: For the time being (as of early 2014, at least),
 * we're using libuv to handle asynchronous I/O stuff.  It would be
 * lovely if we could "embed" libuv's event loop in the yield logic.
 * Unfortunately, libuv embedding is not totally solidified yet.  So
 * we're going to have a separate thread for running the I/O event
 * loop.  Eventually we should be able to get rid of that.
 *
 * ... On the other hand, having a separate thread for the event loop
 * means that we can do the heartbeat timer there and not have to worry
 * about signal handling junk.  Seems like that might be a nicer way to
 * go for many systems.  In the long term, probably should support
 * both. */
int main( int argc, char **argv, char **env )
{
    /* Okay to stack-allocate these here because the I/O thread should
     * always be the last thing running in a Charcoal process.
     * TODO: Document why we need these for the I/O thread */
    int rc;
    if( ( rc = zlog_init( zlog_config_full_filename ) ) )
    {
        return -1;
    }

    if( !( crcl(c) = zlog_get_category( "main_cat" ) ) )
    {
        zlog_error( crcl(c), "Failure: Missing logging category\n" );
        zlog_fini();
        return -2;
    }

    __argc = argc;
    __argv = argv;
    __env  = env;
    if( ( rc = crcl(init_io_loop)( start_application_main ) ) )
    {
        zlog_error( crcl(c), "Failure: Initialization of the I/O loop: %d\n", rc );
        return rc;
    }

    if( ( rc = uv_run( crcl(evt_loop), UV_RUN_DEFAULT ) ) )
    {
        zlog_error( crcl(c), "Failure: Running the I/O loop: %d", rc );
        return rc;
    }

    zlog_info( crcl(c), "switch cnt: %ld", crcl(switch_cnt) );
    zlog_info( crcl(c), "Charcoal application finished.  Exit code: %d",
               crcl(process_exit_code) );
    zlog_fini();
    return crcl(process_exit_code);
}
END_TEST

START_TEST( test_apuntador_arreglo) {

	const tipo_dato VALORES[3][3] = { { 10, 20, 30 }, { 100, 200, 300 }, { 1000,
			2000, 3000 } };
	void *ptr = NULL;

	ptr = (void *) VALORES;

	zlog_fini();

	ck_assert_msg(!from_stack(ptr), "El valor %p no es apuntador valido", ptr);
}
Exemple #23
0
int log_init()
{
	if(log)
		return 0;
	int flag=zlog_init("/data/zlog.conf");
	if(flag!=0)
		return -1;
	log= zlog_get_category("my_cat");
	if(!log)
	{
		zlog_fini();
		return -2;
	}
}
Exemple #24
0
int main(int argc, char** argv)
{
	int rc;
	
	zlog_category_t *zc;

	rc = zlog_init("test_init.conf");
	if (rc) {
		printf("init fail");
		return -2;
	}

	zc = zlog_get_category("my_cat");
	if (!zc) {
		printf("zlog_get_category fail\n");
		zlog_fini();
		return -1;
	}

	ZLOG_INFO(zc, "before update");

	sleep(3);

	rc = zlog_reload("test_init.2.conf");
	if (rc) {
		printf("update fail\n");
	}

	ZLOG_INFO(zc, "after update");

	zlog_profile();

	zlog_fini();

	
	return 0;
}
END_TEST

#define NUM_VALORES  9
START_TEST( test_cola_prioridad_pop) {


	const tipo_dato VALORES[NUM_VALORES] = { 9, 5, 10, 1, 6, 11, 0, 2, 3 };
	const tipo_dato VALORES_FINALES_INORDER[NUM_VALORES - 2] = { 2, 3, 4, 5, 6,
			9, 10 };

	int resultado = 0;
	int num_datos_colectados = 0;
	cola_prioridad_contexto ctx;
	tipo_dato valores_inorder_resultado[NUM_VALORES] = { 0 };
	nodo_cola_prioridad **referencias_directas = NULL;
	nodo_cola_prioridad *nodo_pop_1 = NULL;
	nodo_cola_prioridad *nodo_pop_2 = NULL;

	caca_log_debug("empezando el año");

	cola_prioridad_init(&ctx, NULL, (tipo_dato *) VALORES, NULL, NUM_VALORES,
			NULL, NULL);

	referencias_directas = ctx.referencias_directas_por_indice;

	for (int i = 0; i < NUM_VALORES + 1; i++) {
		caca_log_debug("referencias directas indice %d  valor %ld", i,
				ARBOL_AVL_GET_VALOR(*(referencias_directas + i)));
	}

	nodo_pop_1 = cola_prioridad_pop(&ctx);
	nodo_pop_2 = cola_prioridad_pop(&ctx);

	cola_prioridad_get_valores(&ctx, valores_inorder_resultado,
			&num_datos_colectados);

	for (int i = 0; i < NUM_VALORES; i++) {
		caca_log_debug("eien pressure %d %ld", i,
				*(valores_inorder_resultado + i));
	}

	resultado = num_datos_colectados == (NUM_VALORES - 2)
			&& !memcmp(VALORES_FINALES_INORDER, valores_inorder_resultado, 9)
			&& nodo_pop_1->valor == 0 && nodo_pop_2->valor == 1;

	zlog_fini();

	ck_assert_msg(resultado, "los datos colectados %d", num_datos_colectados);
}
END_TEST

START_TEST( test_imprime_array) {

	const tipo_dato VALORES[3][3] = { { 10, 20, 30 }, { 100, 200, 300 }, { 1000,
			2000, 3000 } };
	void *ptr = NULL;

	ptr = (void *) VALORES;

	zlog_fini();

	ck_assert_msg(!caca_imprime_matrix(ptr, 3, NULL, 3),
			"El valor %p no es apuntador valido", ptr);
}
Exemple #27
0
void * work(void *ptr)
{
	int zc;
	sleep(5);
	char *str = (char *)ptr;
	zc = zlog_change_rule(str,"=info");
	
	if(zc){ 
		printf("change rule fail\n");
		zlog_fini();
		return (void *)-1;
	}

	return (void *)0;
}
Exemple #28
0
int main(int argc, char** argv)
{
	int rc;
	zlog_category_t *zc;

	rc = zlog_init("test_hello.conf");
	if (rc) {
		printf("init failed\n");
		return -1;
	}

	zc = zlog_get_category("my_cat");
	if (!zc) {
		printf("get cat fail\n");
		zlog_fini();
		return -2;
	}

	ZLOG_INFO(zc, "hello, zlog");

	zlog_fini();
	
	return 0;
}
END_TEST

START_TEST( test_apuntador_allocado) {

	tipo_dato **valores = NULL;

	valores = (tipo_dato **) malloc(3 * sizeof(tipo_dato *));

	for (int i = 0; i < 3; i++) {
		*(valores + i) = (tipo_dato *) malloc(10 * sizeof(tipo_dato));
	}

	zlog_fini();

	ck_assert_msg(from_stack(*valores), "El valor %p no es apuntador valido",
			*valores);
}
int main () {
	int state = zlog_init("../zlog.conf");
    category = zlog_get_category("default");
    zlog_info (category, "Server starts!");

    init_server (&server);
    server.run (&server);

    while (1) {
        char c = getchar ();
        if (c == 'q')
            break;
    }

    destroy_server (&server);

    zlog_fini ();
}