int main(int argc, char *argv[]) { sd_test_t *t; int ret; FILE *f; t = sd_test_new(argc, argv); log4c_init(); appender = log4c_appender_get("stream"); f = fopen("/dev/null", "w+"); log4c_appender_set_udata(appender, f); root = log4c_category_get("root"); log4c_category_set_appender(root, appender); log4c_category_set_priority(root, LOG4C_PRIORITY_TRACE); sd_test_add(t, test_big); ret = sd_test_run(t, argc, argv); log4c_appender_set_udata(appender, NULL); fclose(f); sd_test_delete(t); log4c_fini(); return ! ret; }
/* Uninitialize log 4c and log error to stdout upon failure */ static int uninit_log4c() { int ret = log4c_fini(); if (ret) { printf("uninit_log4c() failed"); } return ret; }
int main(int argc, char** argv) { struct timeval start_time; struct timeval now_time; int looptime = 0; log4c_category_t* mycat = NULL; int i = 0; if (argc < 2) { printf("usage: %s loop_time_in_seconds\n",argv[0]); exit (1); } if (sscanf(argv[1],"%d",&looptime) != 1) { printf("could not convert %s to number of seconds to loop\n",argv[1]); exit(1); } /* You could put your category class into a file with a wrapper macro * to make calling it easier and more consistent */ log4c_init(); mycat = log4c_category_get("six13log.log.app.application1"); i = 0; while ( (now_time.tv_sec - start_time.tv_sec) < looptime) { log4c_category_log(mycat, LOG4C_PRIORITY_DEBUG, "Debugging app 1 - loop %d", i); log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "some error from app1 at line %d in file %s - loop %d", __LINE__, __FILE__, i); sleep(3); i++; } /* Explicitly call the log4c cleanup routine */ if ( log4c_fini()){ printf("log4c_fini() failed"); } return 0; }
void teardown() { gchar* content_db_path; gchar* container_db_path; log4c_fini(); content_db_path = g_strdup_printf("%s/%s", VOLUME_ROOT, CONTENT_DB_NAME); container_db_path = g_strdup_printf("%s/%s", VOLUME_ROOT, CONTAINER_DB_NAME); #if 1 unlink(content_db_path); unlink(container_db_path); rmdir(VOLUME_ROOT); #endif g_free(content_db_path); g_free(container_db_path); return; }
int log_close() { return (log4c_fini()); }
extern void __attribute__ ((destructor)) __log4c_fini(void) { #ifdef WITH_CONSTRUCTORS log4c_fini(); #endif }
int main(int argc, char** argv) { struct timeval start_time; struct timeval now_time; user_locinfo_t userloc; int looptime = 0; log4c_category_t* mycat = NULL; /* setup for the extra user location info */ char hostname[256]; int pid = getpid(); gethostname(hostname,255); hostname[255] = '\0'; userloc.hostname = hostname; userloc.pid = pid; if (argc < 2) { printf("usage: %s loop_time_in_seconds\n",argv[0]); exit (1); } if (sscanf(argv[1],"%d",&looptime) != 1) { printf("could not convert %s to number of seconds to loop\n",argv[1]); exit(1); } /* * Here, if using explicit initialization (as opposed to implicit via the * init phase of the library) it's important to initialize the custom appenders * and layouts before calling log4c_init(). * This is because when log4c_init() parses the config file it looks for the * types mentioned in the file to set up the relations between categories, * appenders and layouts. If it does not find a coresponding type in the * internal hash tables, it creates one with that type name, but the function * table is not set up--so that at log time nothing happens. * */ init_examples_lib(); init_userloc_formatters(); log4c_init(); /* * Here we add our own userdefined location info, and then pick that up in our formatter */ mycat = log4c_category_get("six13log.log.app.application3"); gettimeofday(&start_time, NULL); gettimeofday(&now_time, NULL); while ( (now_time.tv_sec - start_time.tv_sec) < looptime) { /* LINE and FILE are bad */ log4c_category_log(mycat, LOG4C_PRIORITY_DEBUG, "Debugging app 3, direct log call"); /* using the new API directly */ const log4c_location_info_t locinfo2 = LOG4C_LOCATION_INFO_INITIALIZER(&userloc); log4c_category_log_locinfo(mycat, &locinfo2, LOG4C_PRIORITY_DEBUG, "Debugging application number THREE with extra user location"); const log4c_location_info_t locinfo3 = LOG4C_LOCATION_INFO_INITIALIZER(NULL); log4c_category_log_locinfo(mycat, &locinfo3, LOG4C_PRIORITY_ERROR, "some error from app at line %d in file %s with NULL for extra user location info", __LINE__, __FILE__); /* using the new API with the define wrapper */ log4c_category_log_userinfo(mycat, &userloc, LOG4C_PRIORITY_DEBUG, "Debug app3 wrapper define"); sleep(3); gettimeofday(&now_time, NULL); } /* Explicitly call the log4c cleanup routine */ if ( log4c_fini()){ printf("log4c_fini() failed"); } return 0; }
none_ CBase::uninitialize() { log4c_fini(); }
int Logger::log_close() { return (log4c_fini()); }
/* mkfs.lhfs -l http://<path> -s name */ int main(int argc, char *argv[]) { if (log4c_init()) { g_message("log4c_init failed!"); } GError *error = NULL; GOptionContext *context; context = g_option_context_new("- mkfs hlfs"); g_option_context_add_main_entries(context, entries, NULL); g_option_context_set_help_enabled(context, TRUE); g_option_group_set_error_hook(g_option_context_get_main_group(context), (GOptionErrorFunc)error_func); if (!g_option_context_parse(context, &argc, &argv, &error)) { g_message("option parsing failed: %s", error->message); exit(EXIT_FAILURE); } //g_print("location is :%s\n",location); //g_print("fsname is :%s\n",fsname); //g_print("block size is :%d\n",block_size); //g_print("segment size is :%d\n",seg_size); // seg_size = SEGMENT_SIZE; if(seg_size <= 0 || seg_size%(1024*1024)!=0){ g_message("segsize <=0 or segment size must 1M margin"); return -1; } if(block_size <=0 || block_size%(512) != 0){ g_message("blocksize <=0 or block size must 512 margin"); return -1; } if(max_fs_size <=0){ g_message("max fs size <=0"); return -1; } struct back_storage *storage = init_storage_handler(uri); if(NULL ==storage){ g_message("can not get storage handler for uri:%s",uri); g_option_context_free(context); return -1; } if((0==storage->bs_file_is_exist(storage,NULL)) && (0==storage->bs_file_is_exist(storage,"superblock"))){ g_message("hlfs with uri:%s has exist",uri); g_option_context_free(context); return 1; } if( 0!=storage->bs_file_mkdir(storage,NULL)){ g_message("can not mkdir for our fs %s",uri); g_option_context_free(context); return -1; } GKeyFile *sb_keyfile= g_key_file_new(); g_key_file_set_string(sb_keyfile,"METADATA","uri",uri); g_key_file_set_integer(sb_keyfile,"METADATA","block_size",block_size); g_key_file_set_integer(sb_keyfile,"METADATA","segment_size",seg_size); g_key_file_set_uint64(sb_keyfile,"METADATA","max_fs_size",max_fs_size); gchar *data = g_key_file_to_data(sb_keyfile,NULL,NULL); g_message("key file data :%s",data); char *head,*hostname,*dir,*fs_name; int port; parse_from_uri(uri,&head,&hostname,&dir,&fs_name,&port); char *sb_file_path = g_build_filename(dir,fs_name,"superblock",NULL); g_message("sb file path %s",sb_file_path); bs_file_t file = storage->bs_file_create(storage,"superblock"); g_message("sb file path 1%s",sb_file_path); //bs_file_t file = storage->bs_file_open(storage,"superblock",BS_WRITEABLE); if (NULL == file) { g_message("open file :superblock failed"); g_free(sb_file_path); g_option_context_free(context); return -1; } g_message("sb file path 2%s",sb_file_path); int size = storage->bs_file_append(storage, file,(char*)data,strlen(data)+1); if(size != strlen(data)+1){ g_message("can not write superblock file"); g_free(sb_file_path); g_option_context_free(context); return -1; } g_message("append size:%d",size); storage->bs_file_flush(storage,file); storage->bs_file_close(storage,file); deinit_storage_handler(storage); if (log4c_fini()) { g_message("log4c_fini failed!"); } return 0; }
int main(int argc, char *argv[]) { int flags = 0; char *buffer = NULL; int i; usec_t start; usec_t stop; char *test_name; /* declare and get a reference to some unconfigured appenders */ log4c_appender_t *mmap_appender = log4c_appender_get("bench.mmap"); log4c_appender_t *stream_appender = log4c_appender_get("stdout"); log4c_appender_t *stream2_appender = log4c_appender_get("bench.stream2"); log4c_appender_t *streamfile_appender = log4c_appender_get("bench.stream"); /* * Obligatory log4c init call */ log4c_init(); /* * Get some categories */ catmmap = log4c_category_get("mmap"); catstream = log4c_category_get("stream"); catstream2 = log4c_category_get("stream2"); catstream_file = log4c_category_get("stream_file"); /* * Read command line options */ getopts(argc, argv); /* * Configure the categories and appenders */ log4c_appender_set_type(mmap_appender, log4c_appender_type_get("mmap")); log4c_category_set_appender(catmmap, mmap_appender); log4c_category_set_appender(catstream, stream_appender); log4c_appender_set_type(stream2_appender, log4c_appender_type_get("stream2")); log4c_category_set_appender(catstream2, stream2_appender); log4c_category_set_appender(catstream_file, streamfile_appender); log4c_category_set_priority(log4c_category_get("root"), LOG4C_PRIORITY_ERROR); /* * Get a buffer for the message */ buffer = (char *) malloc(g_msgsize * sizeof(char)); memset(buffer, 'X', g_msgsize); buffer[g_msgsize - 1] = '\0'; /* * Calibration: do a couple of 1 second sleeps to make sure * the timing routines are in working order. */ start = my_utime(); for (i = 0; i < 2; i++) { sleep(1); } stop = my_utime(); display_time("calibration 2 x 1 second sleep calls", start, stop, (stop - start), (stop - start) / 2); /* logs that write to the screen, if required */ if ( !g_noscreen_appenders) { /* * fprintf writing to the screen */ start = my_utime(); for (i = 0; i < g_num_msgs; i++) { fprintf(stdout, "%s\n", buffer); } stop = my_utime(); display_time("fprintf", start, stop, (stop - start), (stop - start) / g_num_msgs); /* * log4c writing to the screen */ start = my_utime(); for (i = 0; i < g_num_msgs; i++) { log4c_category_error(catstream, "%s", buffer); } stop = my_utime(); display_time("fprintf", start, stop, (stop - start), (stop - start) / g_num_msgs); } /* Logs that write to files */ /* * mmap appender writing to bench.mmap * * On windows as this type is not implemented it makes pretty much * null calls to log4c--so it does nothing but is safe. */ start = my_utime(); for (i = 0; i < g_num_msgs; i++) { log4c_category_error(catmmap, "%s", buffer); } stop = my_utime(); display_time("mmap", start, stop, (stop - start), (stop - start) / g_num_msgs); /* * stream appender writing to bench.stream */ start = my_utime(); for (i = 0; i < g_num_msgs; i++) { log4c_category_error(catstream_file, "%s", buffer); } stop = my_utime(); display_time("stream_file", start, stop, (stop - start), (stop - start) / g_num_msgs); /* * stream2 appender writing to bench.stream2 * in buffered mode */ log4c_appender_open(stream2_appender); flags = log4c_stream2_get_flags(stream2_appender); start = my_utime(); for (i = 0; i < g_num_msgs; i++) { log4c_category_error(catstream2, "%s", buffer); } stop = my_utime(); test_name = (flags & LOG4C_STREAM2_UNBUFFERED ? "stream2 unbuffered -" : "stream2 buffered -"); display_time(test_name, start, stop, (stop - start), (stop - start) / g_num_msgs); log4c_appender_close(stream2_appender); /* * stream2 appender writing to bench.stream2 * in unbuffered mode -- for comparison with buffered mode * test above */ log4c_appender_open(stream2_appender); log4c_stream2_set_flags(stream2_appender, LOG4C_STREAM2_UNBUFFERED); flags = log4c_stream2_get_flags(stream2_appender); start = my_utime(); for (i = 0; i < g_num_msgs; i++) { log4c_category_error(catstream2, "%s", buffer); } stop = my_utime(); display_time((flags & LOG4C_STREAM2_UNBUFFERED ? "stream2 unbuffered -" : "stream2 buffered -"), start, stop, (stop - start), (stop - start) / g_num_msgs); log4c_appender_close(stream2_appender); /* * Obligatory log4c cleanup call */ log4c_fini(); free(buffer); return 0; }