Example #1
0
void initLog(const char *confpath, const char *cname,const char* cname1, const char* cname2)
{
	dzlog_init(confpath, cname);

	// Find log file path from category
	zlog_category_t* c = zlog_get_category((char *)cname);

    category1 = zlog_get_category((char *)cname1);
    category2 = zlog_get_category((char *)cname2);

	zc_arraylist_t* a_list = c->fit_rules;
	assert(a_list->len == 1);

	//zlog_rule_t* a_rule = (zlog_rule_t *)a_list->array[0];
}
Example #2
0
int ips_module_init(const char* log_cat)
{
    int i;
    int ret;

    if (ips_zc) {
        fprintf(stderr, "%s: already initialized!\n", __func__);
        return(SPKERR_BADSEQ);
    }
    ips_zc = zlog_get_category(log_cat?log_cat:"IPS");
    if (!ips_zc) {
        fprintf(stderr, "%s: failed to initialize log system!\n", __func__);
//        return(SPKERR_LOGSYS);
    }

    assert(!ips_sriodev);

    for (i = 0; i < IPS_MAX_PORTS_IN_DEV; i++) {
        ips_epctx_tbl[i] = NULL;
    }

    pthread_mutex_init(&ips_dma_ch_lock, NULL);
    pthread_mutex_init(&ips_zlog_lock, NULL);

    of_init();
    ret = fsl_srio_uio_init(&ips_sriodev);
    IPS_LOGINFO(IPS_EPID_UNKNOWN, "fsl_srio_uio_init: ret=%d", ret);
    if (ret) {
        return(SPKERR_EAGAIN);
    }

    zlog_notice(ips_zc, "module initialized.");

    return(SPK_SUCCESS);
}
Example #3
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;
}
Example #4
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;
}
int _run_server (socket_manager_t *manager) {

	assert (manager != NULL);
	assert (manager->server != NULL);

	zlog_category_t *category = zlog_get_category ("socket");
	zlog_info (category, "Running server loop.");

	while (manager->shutdown == false) {

		// accept
		int size = sizeof (struct sockaddr_in);
		int sd = accept (manager->main_sd, (struct sockaddr *)&manager->name, &size);
		assert (sd >= 0);
		zlog_info (category, "New connection accepted at descriptor %d.", sd);

		// set sent buffer
	    int n = SOCK_SEND_BUFFER;
	    setsockopt (sd, SOL_SOCKET, SO_SNDBUF, &n, sizeof(n));

		manager->handle (manager, sd);
	}

	zlog_debug (category, "Destroying server socket manager.");	
}
Example #6
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;
}
Example #7
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;
}
Example #8
0
void _enqueue (task_queue_t *queue, void *(*fn) (void *), void *args) {
	assert (queue != NULL);
	assert (fn != NULL);

	zlog_category_t *category = zlog_get_category ("thread_pool");


	// malloc here, free at _thread_pool_worker
	task_t *task = (task_t *)malloc(sizeof (task_t));
	assert (task != NULL);

	task->task = fn;
	task->args = args;
	task->next = NULL;

	if (queue->tail == NULL && queue->head == NULL) {
		queue->head = task;
		queue->tail = task;
	} else {
		queue->tail->next = task;
		queue->tail = task;
	}

	int status = sem_post (&queue->sem);
	assert (status == 0);
	queue->count++;
}
Example #9
0
File: test_mdc.c Project: 3van/zlog
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;
}
Example #10
0
int _write_response (int sd, response_t *response) {
	assert (sd > 0);
	assert (response != NULL);

	// get log
    zlog_category_t *category = zlog_get_category("server");
    assert (category != NULL);

	// do real write, block
	int status = send (sd, response, sizeof (response_t), 0);
	//assert (status == sizeof (response_t));

	// client closed
	if (status < sizeof (response_t))
		return -1;

	// write movie
	status = send (sd, response->data, response->len, 0);
	//assert (status == response->len);
	
	// client closed
	if (status < response->len)
		return -1;


	return sizeof (request_t);
}
Example #11
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;
}
Example #12
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;
}
Example #13
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;
} 
Example #14
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;
}
Example #15
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;
}
Example #16
0
File: s_zlog.c Project: iskey/zlog
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;
}
Example #17
0
int logger_init(Logger *logger, 
                 int mode, 
                 const char *log_conf_path, 
                 const char *log_file_dir)
{
    int rc;
    zlog_category_t *zc;

    logger->log_i = my_zlog_info;
    logger->log_d = my_zlog_debug;
    logger->log_e = my_zlog_error;

    int ret = make_config(log_conf_path, log_file_dir);
    if (ret < 0) {
        goto ERROR;
    }

    rc = zlog_init(log_conf_path);
	if (rc) {
        fprintf(stderr, "logger_init: zlog_init error\n");
        goto ERROR;
	}

    if (mode == LOG_STDOUT) {
        zc = zlog_get_category("stdout");
    } else if (mode == LOG_FILE) {
        zc = zlog_get_category("file");
    }

    if (!zc) {
        fprintf(stderr, "logger_init: zlog_get_category error\n");
        goto ERROR;
    }

    logger->zc = zc;
    logger->log_mode = mode;
    logger->log_on = 1;

    s_init_zlog_success = 1;

    return 0;

ERROR:
    logger_destroy(logger);

    return -1;
}
Example #18
0
File: log.c Project: niks3089/nixia
zlog_category_t* 
log_get_cat_csperf()
{
    if (csperf_zc) {
        return csperf_zc;
    }
    
    csperf_zc = zlog_get_category(CSPERF_LOG_CATEGORY);
    return csperf_zc;
}
Example #19
0
File: log.c Project: niks3089/nixia
zlog_category_t* 
log_get_cat_http()
{
    if (http_zc) {
        return http_zc;
    }
    
    http_zc = zlog_get_category(HTTP_LOG_CATEGORY);
    return http_zc;
}
Example #20
0
File: log.c Project: niks3089/nixia
zlog_category_t* 
log_get_cat()
{
    if (common_zc) {
        return common_zc;
    }
    
    common_zc = zlog_get_category(LOG_CATEGORY);
    return common_zc;
}
Example #21
0
int destroy_socket_manager (socket_manager_t *manager) {
	assert (manager != NULL);

	zlog_category_t *category = zlog_get_category ("socket");
	zlog_info (category, "Destroying socket manager.");

	manager->shutdown = true;
	close (manager->main_sd);

	return 0;
}
Example #22
0
int _server_run (server_t *server) {
	assert (server != NULL);

    zlog_category_t *category = zlog_get_category("server");
	zlog_info (category, "Starting server loop.");

	// create thread for loop
	int status = pthread_create (&server->loop, NULL, _do_server_run, (void *)server);
	assert (status == 0);

	return 0;
}
Example #23
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");
}
Example #24
0
int _run_client (socket_manager_t *manager) {

	assert (manager != NULL);
	assert (manager->client != NULL);

	zlog_category_t *category = zlog_get_category ("socket");
	zlog_info (category, "Running client loop.");

	while (manager->shutdown == false) {
		manager->handle (manager, manager->main_sd);
	}

	zlog_debug (category, "Destroying client socket manager.");	
}
Example #25
0
void * work(void *ptr)
{
	long j = loop_count;
	char category[20];
	sprintf(category, "cat%ld", (long)ptr);
	zlog_category_t *zc;

	zc = zlog_get_category(category);
	
	while(j-- > 0) {
		ZLOG_INFO(zc, "loglog");
	}
	return 0;
}
Example #26
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;
	}
}
Example #27
0
int init_socket_client (socket_manager_t *manager, int port, char *host) {
	assert (manager != NULL);
	assert (port > 0);
	assert (host != NULL);

    manager->shutdown = false;

	zlog_category_t *category = zlog_get_category ("socket");
	zlog_info (category, "Initializing client socket manager with %s:%d.", host, port);

	// create sd
	zlog_debug (category, "Creating socket descriptor.");
	manager->port = port;
	strcpy (manager->host, host);
	manager->main_sd = socket (AF_INET, SOCK_STREAM, 0);
	
	assert (manager->main_sd > 0);

	// resolve host address
	zlog_debug (category, "Resolving host name.");
	struct hostent *hent;
	hent = gethostbyname (host);
	assert (hent != NULL);

	// prepare for connect
	memset ((void *)&manager->name, 0, sizeof (struct sockaddr_in));
	manager->name.sin_family = AF_INET;
	manager->name.sin_port = htons (port);
    bcopy (hent->h_addr, &manager->name.sin_addr, hent->h_length);

    // connect
    zlog_debug (category, "Connecting to server.");
    int status = connect (manager->main_sd, (struct sockaddr *)&manager->name, sizeof(struct sockaddr_in));
	// server not up
	if (status < 0)
		return -1;

    // change buffer
    int n = SOCK_RECV_BUFFER;
    setsockopt (manager->main_sd, SOL_SOCKET, SO_RCVBUF, &n, sizeof(n));

    //status = fcntl (manager->main_sd, F_GETFL, 0);
	//status = fcntl (manager->main_sd, F_SETFL, ~O_NONBLOCK);

    // hook
    manager->run = _run_client;

	return 0;
}
Example #28
0
int destroy_thread_pool (thread_pool_t *pool) {
	assert (pool != NULL);
	zlog_category_t *category = zlog_get_category ("thread_pool");

	zlog_debug (category,"Destroying thread pool.");

	// Shutdown workers
	zlog_debug (category, "Shutting down all workers.");
	pool->shutdown = true;

	int i;
	int status;
	for (i = 0; i < pool->size; i++) {
		status = sem_post (&pool->tasks.sem);
		assert (status == 0);
	}

	for (i = 0; i < pool->size; i++) {
		status = pthread_cancel (pool->threads[i]);
		//assert (status == 0);
		status = pthread_join (pool->threads[i], NULL);
		assert (status == 0);
	}

	free (pool->threads);


	// Destroy semaphore
	zlog_debug (category, "Destroying semaphore.");
	status = sem_destroy (&pool->tasks.sem);
	assert (status == 0);

	// Destroy task queue
	zlog_debug (category, "Destroying task queue.");

	task_t *curr = pool->tasks.head;
	while (curr != NULL) {
		task_t *next = curr->next;
		free (curr);
		curr = next;
	}

	// Destroy mutex
	status = pthread_mutex_destroy (&pool->mutex);
	assert (status == 0);

	return 0;
}
Example #29
0
int net_module_init(const char* log_cat)
{
    if (net_zc) {
        fprintf(stderr, "%s: already initialized!\n", __func__);
        return(SPKERR_BADSEQ);
    }

    net_zc = zlog_get_category(log_cat?log_cat:"NET");
    if (!net_zc) {
        fprintf(stderr, "%s: failed to initialize log system!\n", __func__);
        return(SPKERR_LOGSYS);
    }
    zlog_notice(net_zc, "module initialized.");

    return(SPK_SUCCESS);
}
int init_ring_buffer (buffer_t *buffer, buffer_config_t *config) {
	assert (buffer != NULL);
	assert (config != NULL);
	assert (config->buffer_size > 0);
	assert (config->consume_threshold <= config->buffer_size && config->consume_threshold >= 1);
	assert (config->produce_threshold < config->buffer_size && config->produce_threshold >= 0);


	zlog_category_t *category = zlog_get_category ("ring_buffer");
	assert (category != NULL);

	zlog_debug (category, "Initializing ring buffer with size %d.", config->buffer_size);
	
	// malloc
	zlog_debug (category, "Allocating buffer memory.");
	buffer->entries = (buffer_entry_t *)malloc(config->buffer_size * sizeof (buffer_entry_t));
	assert (buffer->entries != NULL);

	// reset buffer
	memset (buffer->entries, sizeof (buffer->entries), 0);

	// setup constants
	buffer->size = config->buffer_size;
	buffer->count = 0;
	buffer->consumer_index = 0;
	buffer->producer_index = 0;
	buffer->shutdown = false;
	buffer->consume_threshold = config->consume_threshold;
	buffer->produce_threshold = config->produce_threshold;

	// setup sync facilities
	zlog_debug (category, "Initializing mutex.");
	int status;
	status = simple_mutex_init (&buffer->mutex, NULL);
	assert (status == 0);
	status = simple_cond_init (&buffer->cond_not_full, NULL);
	assert (status == 0);
	status = simple_cond_init (&buffer->cond_not_empty, NULL);
	assert (status == 0);

	// hooking methods
	buffer->produce = _produce;
	buffer->consume = _consume;
	buffer->timed_consume = _timed_consume;
	return 0;
}