int main(int argc, char *argv[]){ sim_type_t stype = EVENT_DRIVEN; cs_engine_t *engine; cs_timer_t *timer; cs_event_manager_t *evm; int i; srand(time(NULL)); cs_event_type_t st = (rand() %2 == 0 ? et[0] : et[1]); log4c_init(); log4c_category_log(log4c_category_get("cs.sample"), LOG4C_PRIORITY_INFO, "*** %s, sim_type=%s",\ argv[0], (stype==ACTIVITY_SCAN ? "ACTIVITY_SCAN" : "EVENT_DRIVEN")); //timer initialization timer = (cs_timer_t*) calloc(1, sizeof(cs_timer_t)); cs_init_timer(timer, "CLOCK_TEST"); //set an event to start with cs_event_t *ev_start = CS_NEW_EVENT(1); CS_EVENT_SET_TYPE(ev_start,st); if((evm = (cs_event_manager_t *) malloc(sizeof(cs_event_manager_t)))==NULL){ log4c_category_log(log4c_category_get("cs.sample"), LOG4C_PRIORITY_FATAL, "*** %s, Memory error", argv[0]); return -1; } if(cs_init_event_manager(evm, 10, timer, stype)!=0){ log4c_category_log(log4c_category_get("cs.sample"), LOG4C_PRIORITY_FATAL, "*** %s, error\ initiating Event manager", argv[0]); return -1; }
cs_eh_status ev_handler(cs_event_t *ev, cs_event_manager_t *evm){ //the sequence of events is T0->T2 //or T1->T3,T4 cs_event_t *eva; int n = 0; int i; log4c_category_log(log4c_category_get("cs.sample"), LOG4C_PRIORITY_TRACE, "sample1.handler, T=%li, ev=%s",\ cs_get_clock(CS_EVM_TIMER(evm)), ev->etype); if(CS_EV_IS_TYPE(ev, et[0])){ //T0 --> T2 n = 1; eva = CS_NEW_EVENT(n); CS_EVENT_SET_TYPE(eva,et[2]); } else if(CS_EV_IS_TYPE(ev, et[1])){ //T1 --> T3,T4 n = 2; eva = CS_NEW_EVENT(n); CS_EVENT_SET_TYPE(eva,et[3]); //T3 CS_EVENT_SET_TYPE(&(eva[1]),et[4]); //T4 } for(i=0; i<n; i++){ log4c_category_log(log4c_category_get("cs.sample"), LOG4C_PRIORITY_INFO, "Scheduling event %s @%li", eva[i].etype,cs_get_clock(CS_EVM_TIMER(evm))+1); if(cs_evm_schedule_event(&(eva[i]), cs_get_clock(CS_EVM_TIMER(evm))+1 /* next time */, evm)!=0){ log4c_category_log(log4c_category_get("cs.sample"), LOG4C_PRIORITY_FATAL, "Error scheduling event %s", eva[0].etype); return CS_EH_ERROR; } } return CS_EH_NORMAL; }
void IfsInit(void) { #ifdef STAND_ALONE ifs_RILogCategory = log4c_category_get("RI.IFS"); ifsFileChunkSize = atoi(DEFAULT_IFS_CHUNK_SIZE); #else const char * chunk; ifs_RILogCategory = log4c_category_get("RI.IFS"); if ((chunk = ricfg_getValue("RIPlatform", "RI.Platform.dvr.IfsChunkSize")) == NULL) { RILOG_WARN( "RI.Platform.dvr.IfsChunkSize not specified in the platform config file!\n"); chunk = DEFAULT_IFS_CHUNK_SIZE; } ifsFileChunkSize = atoi(chunk); int i = 0; for (i = 0; i < MAX_WRITER_LIST_CNT; i++) { writerListHandles[i] = NULL; } #endif }
void configure_cgi_handlers(spade_server* server, config_t* configuration) { config_setting_t* handler_settings = config_lookup(configuration, "cgi.handlers"); int cgi_handler_count = config_setting_length(handler_settings); for (int n = 0; n < cgi_handler_count; n++) { config_setting_t* handler_setting = config_setting_get_elem( handler_settings, n); const char* handler = NULL; config_setting_lookup_string(handler_setting, "handler", &handler); const char* url = NULL; config_setting_lookup_string(handler_setting, "url", &url); if(!register_cgi_handler(server, url, handler)) { log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO, "Registered CGI handler '%s' for URL prefix '%s'", handler, url); } } if (server->cgi_handler_count == 0) { log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO, "No CGI handlers registered"); } else { log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO, "Registered a total of %d CGI handlers", server->cgi_handler_count); } }
void configure_clay_handlers(spade_server* server, config_t* configuration) { config_setting_t* handler_settings = config_lookup(configuration, "clay.handlers"); if (!handler_settings) { log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO, "No Clay handlers registered"); return; } int clay_handler_count = config_setting_length(handler_settings); for (int n = 0; n < clay_handler_count; n++) { config_setting_t* handler_setting = config_setting_get_elem( handler_settings, n); const char* endpoint = NULL; config_setting_lookup_string(handler_setting, "endpoint", &endpoint); const char* url = NULL; config_setting_lookup_string(handler_setting, "url", &url); if(!register_clay_handler(server, url, endpoint)) { log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO, "Registered Clay handler for URL prefix '%s' at endpoint %s", url, endpoint); } } if (server->clay_handler_count == 0) { log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO, "No Clay handlers registered"); } else { log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO, "Registered a total of %d Clay handlers", server->clay_handler_count); } }
void configure_hostname(spade_server* server, config_t* configuration) { const char* hostname = NULL; if(config_lookup_string(configuration, "hostname", &hostname)) { strcpy(server->hostname, hostname); log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO, "Using hostname '%s' from configuration file", server->hostname); } else { strcpy(server->hostname, DEFAULT_HOSTNAME); log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO, "Using default hostname '%s'", server->hostname); } }
void configure_cgi_file_path(spade_server* server, config_t* configuration) { const char* cgi_file_path = NULL; if(config_lookup_string(configuration, "cgi.document_root", &cgi_file_path)) { strcpy(server->cgi_file_path, cgi_file_path); log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO, "Using dynamic file path '%s' from configuration file", server->cgi_file_path); } else { strcpy(server->cgi_file_path, DEFAULT_CGI_FILE_PATH); log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO, "Using default CGI file path '%s'", server->cgi_file_path); } }
void configure_static_file_path(spade_server* server, config_t* configuration) { const char* static_file_path = NULL; if(config_lookup_string(configuration, "static.document_root", &static_file_path)) { strcpy(server->static_file_path, static_file_path); log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO, "Using static file path '%s' from configuration file", server->static_file_path); } else { strcpy(server->static_file_path, DEFAULT_STATIC_FILE_PATH); log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO, "Using default static file path '%s'", server->static_file_path); } }
//class related ParseTsStream::ParseTsStream() { #if !defined(CROSS_COMPILE) // log4c_init(); #endif pat_packet = new PatParse(); pmt_packet = new PmtParse(); ts_packet_count = 1; mycat = log4c_category_get("tsparser.tsstream"); input_memcopy_timer = Profiler("input_memcpy"); pes_pkt_copy_timer = Profiler("pes_pktcopy"); pes_parse_timer = Profiler("peshdr_parse"); ts_pkt_profiler = Profiler("overall_pkt"); video_pkt_profiler = Profiler("vidpkt_parse"); audio_pkt_profiler = Profiler("audpkt_parse"); ts_header_profiler = Profiler("tshdr_parse"); pat_parse_timer = Profiler("pathdr_parse"); pmt_parse_timer = Profiler("pmthdr_parse"); // skip_timer = Profiler("skip2end_time"); level1_timer = Profiler("level1_timer"); level2_timer = Profiler("level2_timer"); pmt_pid = 0; video_pid = 0; audio_pid = 0; }
int configure_server(spade_server* server, char* configuration_path, unsigned int override_port) { config_t configuration_struct, *configuration; configuration = &configuration_struct; config_init(configuration); if (!config_read_file(configuration, configuration_path)) { log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_ERROR, "Configuration error: %s:%d - %s", configuration_path, config_error_line(configuration), config_error_text(configuration)); config_destroy(configuration); return(EXIT_FAILURE); } configure_hostname(server, configuration); configure_port(server, override_port, configuration); configure_reverse_lookups(server, configuration); configure_static_file_path(server, configuration); configure_dynamic_file_paths(server, configuration); configure_dynamic_handlers(server, configuration); config_destroy(configuration); return 0; }
CartProducts::CartProducts(const Volume<double>& volume, unsigned image_side, unsigned sample_square_size) : mapping(volume[0].beam_size), fullres(volume[0].beam_size), scaled(mapping, image_side, sample_square_size), z_out(image_side), top_1x1(image_side), qual_Z_1x1(image_side), quota_1x1(image_side), dato_corr_1x1(image_side), elev_fin_1x1(image_side), beam_blocking_1x1(image_side), neve_1x1(image_side), corr_1x1(image_side), conv_1x1(image_side) { logging_category = log4c_category_get("radar.cart"); quota_1x1.fill(128); LOG_INFO("Creazione Matrice Cartesiana"); fullres.map_max_sample(volume[0], mapping); //assets.write_gdal_image(fullres.map_azimuth, "DIR_DEBUG", "map_azimuth", "PNG"); //assets.write_gdal_image(fullres.map_range, "DIR_DEBUG", "map_range", "PNG"); LOG_INFO("Creazione Matrice Cartesiana ridimensionata"); scaled.map_max_sample(volume[0], fullres); FullsizeRes = volume.at(0).cell_size; ScaledRes = FullsizeRes*sample_square_size; }
void configure_port(spade_server* server, unsigned int override_port, config_t* configuration) { if (override_port) { server->port = override_port; log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO, "Using override port %d", server->port); } else if(config_lookup_int(configuration, "port", (long int *)&server->port)) { log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO, "Using port %d from configuration file", server->port); } else { server->port = DEFAULT_PORT; log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO, "Using default port %d", server->port); } }
CalcoloVIZ::CalcoloVIZ(const CylindricalVolume& cil, double htbb, double hbbb, double t_ground) : cil(cil), x_size(cil.x_size), z_size(cil.z_size), htbb(htbb), hbbb(hbbb), t_ground(t_ground), res_vert_cil (cil.resol[1]), conv_VIZ(Matrix2D<unsigned char>::Constant(cil.slices.size(), x_size, MISSING)), stratiform(Matrix2D<unsigned char>::Constant(cil.slices.size(), x_size, MISSING)) { logging_category = log4c_category_get("radar.vpr"); }
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; }
TsPacket::TsPacket(int ts_packet_count) { mycat = log4c_category_get("tsparser.tspacket"); count = ts_packet_count; tsheader = new ParseTsHeader(); pes_packet = new ParsePESPacket(); adaptation_header = new ParseAdaptationField(); }
void configure_reverse_lookups(spade_server* server, config_t* configuration) { int do_reverse_lookups = 0; if(config_lookup_int(configuration, "do_reverse_lookups", (long int*) &do_reverse_lookups)) { server->do_reverse_lookups = do_reverse_lookups; } else { server->do_reverse_lookups = 0; } if (server->do_reverse_lookups) { log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO, "Will perform reverse lookups for client hostnames"); } else { log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO, "Will not perform reverse lookups for client hostnames"); } }
bool_ CBase::initialize() { if (0 != log4c_init()) { return false_v; } _category = log4c_category_get("HFRSLog"); return true_v; }
int check_error(int result, const char* function) { if(result < 0) { log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_WARN, "ERROR: %s failed with error %d: %s\n", function, errno, strerror(errno)); return -1; } return 0; }
int log_open(const char *category) { if (log4c_init() == 1) { return -1; } log_category = log4c_category_get(category); return 0 ; }
void configure_dirt_handlers(spade_server* server, config_t* configuration) { config_setting_t* handler_settings = config_lookup(configuration, "dirt.handlers"); if (!handler_settings) { log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO, "No Dirt handlers registered"); return; } int dirt_handler_count = config_setting_length(handler_settings); for (int n = 0; n < dirt_handler_count; n++) { config_setting_t* handler_setting = config_setting_get_elem( handler_settings, n); const char* library = NULL; config_setting_lookup_string(handler_setting, "library", &library); const char* handler = NULL; config_setting_lookup_string(handler_setting, "handler", &handler); const char* url = NULL; config_setting_lookup_string(handler_setting, "url", &url); if(!register_dirt_handler(server, url, handler, library)) { log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO, "Registered Dirt handler '%s' for URL prefix '%s'", handler, url); } } if (server->dirt_handler_count == 0) { log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO, "No Dirt handlers registered"); } else { log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO, "Registered a total of %d Dirt handlers", server->dirt_handler_count); } }
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; }
int main(int argc, char **argv) { int i; int ret = 0; FILE *file; char *line; int16_t port; ret = log4c_init(); if (ret != 0) { printf("log4c_init failed[%d]\n", ret); return (ret); } mycat = log4c_category_get("six13log.log.app.application1"); if (!mycat) { printf("log4c_category_get(\"six13log.log.app.application1\"); failed\n"); return (0); } for (i = 1; i < argc; ++i) { if (strcmp(argv[i], "-d") == 0) { change_to_deamon(); break; } } log4c_category_log(mycat, LOG4C_PRIORITY_INFO, "conn_srv run"); if (init_conn_client_map() != 0) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "init client map failed"); goto done; } ret = game_event_init(); if (ret != 0) goto done; callback_server.cb_get_client_map = get_server_client_map; callback_server.cb_listen_pre = conn_cb_server_listen_pre; callback_server.cb_listen_after = conn_cb_server_listen_after; callback_client.cb_get_client_map = get_client_client_map; callback_client.cb_listen_pre = conn_cb_client_listen_pre; callback_client.cb_listen_after = conn_cb_client_listen_after; file = fopen("../server_info.ini", "r"); if (!file) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "open server_info.ini failed[%d]", errno); ret = -1; goto done; } line = get_first_key(file, "conn_srv_listen_port"); port = atoi(get_value(line)); if (port <= 0) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "config file wrong, no conn_srv_listen_port"); ret = -1; goto done; } ret = game_add_listen_event(port, &callback_client); if (ret != 0) goto done; line = get_first_key(file, "conn_srv_port"); port = atoi(get_value(line)); if (port <= 0) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "config file wrong, no conn_srv_port"); ret = -1; goto done; } ret = game_add_listen_event(port, &callback_server); if (ret != 0) goto done; fclose(file); struct event event_timer; struct timeval t1 = {5, 0}; add_timer(t1, &event_timer); // event_timer.ev_callback = cb_testtool_timer; struct timeval t2 = {2, 0}; add_timer(t2, NULL); struct timeval t3 = {4, 0}; add_timer(t3, NULL); if (SIG_ERR == signal(SIGPIPE,SIG_IGN)) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "set sigpipe ign failed"); return (0); } ret = event_base_loop(base, 0); log4c_category_log(mycat, LOG4C_PRIORITY_INFO, "event_base_loop stoped[%d]", ret); struct timeval tv; event_base_gettimeofday_cached(base, &tv); done: log4c_category_log(mycat, LOG4C_PRIORITY_INFO, "conn_srv stoped[%d]", ret); return (ret); }
extern int log4c_init(void) { size_t i; int ret = 0; sd_debug("log4c_init["); /* activate GLIBC allocation debugging */ #if defined(__LOG4C_DEBUG__) && defined(__GLIBC__) mtrace(); #endif if (log4c_is_init){ sd_debug("log4c already initialized ]"); return 0; } log4c_is_init++; /* Initialize default types: layouts, appenders, rollingpolicies */ sd_debug("intializing default types: appenders, layouts, rollingpolicies"); for (i = 0; i < nlayout_types; i++) log4c_layout_type_set(layout_types[i]); for (i = 0; i < nappender_types; i++) log4c_appender_type_set(appender_types[i]); #ifdef WITH_ROLLINGFILE for (i = 0; i < nrollingpolicy_types; i++) log4c_rollingpolicy_type_set(rollingpolicy_types[i]); #endif /* load configuration files */ { int i; sd_debug("looking for conf files..."); snprintf(rcfiles[0].name, sizeof(rcfiles[0].name) - 1, "%s/log4crc", getenv("LOG4C_RCPATH") ? getenv("LOG4C_RCPATH") : LOG4C_RCPATH); snprintf(rcfiles[1].name, sizeof(rcfiles[1].name) - 1, "%s/.log4crc", getenv("HOME") ? getenv("HOME") : ""); for (i = 0; i < nrcfiles; i++) { sd_debug("checking for conf file at '%s'", rcfiles[i].name); if (SD_ACCESS_READ(rcfiles[i].name)) continue; if (SD_STAT_CTIME(rcfiles[i].name,&rcfiles[i].ctime) != 0) sd_error("sd_stat_ctime %s failed", rcfiles[i].name); rcfiles[i].exists=1; if (log4c_load(rcfiles[i].name) == -1) { sd_error("loading %s failed", rcfiles[i].name); ret = -1; } else sd_debug("loading %s succeeded", rcfiles[i].name); } } /* override configuration with environment variables */ { const char* priority; const char* appender; sd_debug("checking environment variables..."); if ( (priority = getenv("LOG4C_PRIORITY")) != NULL){ sd_debug("setting priority of root category to '%s'", priority); log4c_category_set_priority(log4c_category_get("root"), log4c_priority_to_int(priority)); } if ( (appender = getenv("LOG4C_APPENDER")) != NULL){ sd_debug("setting appender of root category to '%s'", appender); log4c_category_set_appender(log4c_category_get("root"), log4c_appender_get(appender)); } } /* * For debug dump current types and instances: * this allows the caller of log4c_init() to see: * 1. all types currently registered, including perhaps his own. * 2. all instances instantiated via the configuration file. * * If the caller goes on to programmatically create instaces then he * can call log4c_dump_all_instances() later himself to * verify that they were created as expected. * */ #ifdef __SD_DEBUG__ if( getenv("SD_DEBUG")){ log4c_dump_all_types(stderr); log4c_dump_all_instances(stderr); } #endif sd_debug("]"); return ret; }
void init(CodecConfiguration *configuration) { // Need to initialize loggers. // Then need to pre-allocate pinned memory and Cuda Global Memory. gpuTunerCategory = log4c_category_get("performance_tuning_gpu_logger"); cpuTunerCategory = log4c_category_get("performance_tuning_cpu_logger"); log4c_init(); currentMode = PRODUCTION; config_t propConfig; config_init(&propConfig); if (!config_read_file(&propConfig, configuration->propertyFilePath)) { fprintf(stderr, "%s:%d - %s\n", config_error_file(&propConfig), config_error_line(&propConfig), config_error_text(&propConfig)); config_destroy(&propConfig); return; } config_lookup_bool(&propConfig, "isUseGpu", &useGpu); config_lookup_bool(&propConfig, "isUseDynamicParallelism", &useDynamicParallelism); config_lookup_int(&propConfig, "max_packet_size", &maxPacketSize); config_lookup_int(&propConfig, "max_batch_size", &maxBatchSize); config_lookup_int(&propConfig, "tuner_loop_count", &tunerLoopCount); config_lookup_int(&propConfig, "number_of_cpu_cores", &nCpuCores); config_lookup_int(&propConfig, "cuda_stream_count", &cudaStreamCount); config_lookup_bool(&propConfig, "print_accuracy_log", &printAccuracyLog); currentCudaContextSize = (uint32_t) maxBatchSize; cudaPduContext = allocatePinnedPduContext(maxBatchSize); initCudaParameters((uint32_t) maxBatchSize, ((uint64_t) maxPacketSize * (uint64_t) maxBatchSize)); int isTunerMode = 0; config_lookup_bool(&propConfig, "isTunerMode", &isTunerMode); currentMode = isTunerMode ? TUNER : PRODUCTION; printf("Is Use GPU %d | Max Packet Size %d | Max Batch Size %d | Tuner Mode %d | Accuracy Log %d\n", useGpu, maxPacketSize, maxBatchSize, currentMode, printAccuracyLog); fflush(stdout); switch (currentMode) { case TUNER: { configureTuner(&propConfig); break; } default: { int x, y, z; config_setting_t *block = config_lookup(&propConfig, "production.block"); config_setting_t *grid = config_lookup(&propConfig, "production.grid"); config_setting_lookup_int(block, "x", &x); config_setting_lookup_int(block, "y", &y); config_setting_lookup_int(block, "z", &z); blockDimProdction.x = (uint32_t) x; blockDimProdction.y = (uint32_t) y; blockDimProdction.z = (uint32_t) z; config_setting_lookup_int(grid, "x", &x); config_setting_lookup_int(grid, "y", &y); config_setting_lookup_int(grid, "z", &z); gridDimProduction.x = (uint32_t) x; gridDimProduction.y = (uint32_t) y; gridDimProduction.z = (uint32_t) z; config_lookup_int(&propConfig, "production.cpu_decode_threshold", &cpuDecodeThreshold); } } }
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; }
int main(int argc, char *argv[]) { int i; int ret; // CONTAINER *tmp; int resume = 0; struct sockaddr_in sin; int16_t port; FILE *file; char *line; char *ip; srandom(time(NULL)); ret = log4c_init(); if (ret != 0) { printf("log4c_init failed[%d]\n", ret); return ret; } mycat = log4c_category_get("six13log.log.app"); if (!mycat) { printf("log4c_category_get(\"six13log.log.app.application1\"); failed\n"); return (0); } obj_count_loger = log4c_category_get("count_obj_cate"); if (!obj_count_loger) { printf("log4c_category_get(\"six13log.log.app.application2\"); failed\n"); return (0); } for (i = 1; i < argc; ++i) { if (strcmp(argv[i], "-d") == 0) { change_to_deamon(); --argc; break; } } if (argc > 1) resume = 1; ret = load_all_config(); if (ret != 0) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "load all config fail[%d]\n", ret); return (-1); } ret = init_gm_system(); if (ret != 0) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "init gm system fail[%d]\n", ret); return (-1); } sc_interface = load_game_script(); if (!sc_interface) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "load script fail[%d]\n"); return (-1); } log4c_category_log(mycat, LOG4C_PRIORITY_INFO, "game_srv run"); role_rbdata_init_head(); file = fopen("../server_info.ini", "r"); if (!file) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "open server_info.ini failed[%d]", errno); return (-1); } line = get_first_key(file, "game_srv_key"); key = strtoul(get_value(line), NULL, 0); if (key == 0 || key == ULONG_MAX) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "config file wrong, no game_srv_key"); return (-1); } if (alloc_shared_mem(resume) != 0) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "alloc_shared_mem[%d] failed", resume); return (-1); } ret = init_all_objs(resume); if (ret != 0) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "init_all_objs[%d] failed[%d]", resume, ret); return (-1); } ret = create_all_static_scene(); if (ret != 0) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "creeate_all_static_scene[%d] failed[%d]", resume, ret); return (-1); } // test_fight(); // return (0); ret = game_event_init(); if (ret != 0) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "game_event_init failed[%d]", ret); return (-1); } line = get_first_key(file, "conn_srv_ip"); for (i = 0; i < MAX_CONN_SRV && line != NULL; ++i) { memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; conn_server[i].cb_recv = gamesrv_cb_conn_recv; ip = get_value(line); if (!ip) break; line = get_next_key(file, "conn_srv_port"); if (!line) break; port = atoi(get_value(line)); if (port <= 0) break; line = get_next_key(file, "conn_srv_ip"); sin.sin_port = htons(port); ret = evutil_inet_pton(AF_INET, ip, &sin.sin_addr); if (ret != 1) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "evutil_inet_pton failed[%d], ip[%s] port[%d]", ret, ip, port); return (-1); } ret = game_add_connect_event((struct sockaddr *)&sin, sizeof(sin), &conn_server[i]); if (ret < 0) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "game_add_connect_event to conn server failed[%d], ip[%s] port[%d]", ret, ip, port); return (-1); } conn_server[i].fd = ret; } if (i == 0) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "config file wrong, no conn_srv"); return (-1); } max_conn_srv = i; line = get_first_key(file, "db_srv_ip"); for (i = 0; i < MAX_ROLEDB_SRV && line != NULL; ++i) { memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; roledb_server[i].cb_recv = gamesrv_cb_roledb_recv; ip = get_value(line); if (!ip) break; line = get_next_key(file, "db_srv_port"); if (!line) break; port = atoi(get_value(line)); if (port <= 0) break; line = get_next_key(file, "db_srv_ip"); sin.sin_port = htons(port); ret = evutil_inet_pton(AF_INET, ip, &sin.sin_addr); if (ret != 1) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "evutil_inet_pton failed[%d], ip[%s] port[%d]", ret, ip, port); return (-1); } ret = game_add_connect_event((struct sockaddr *)&sin, sizeof(sin), &roledb_server[i]); if (ret < 0) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "game_add_connect_event to conn server failed[%d], ip[%s] port[%d]", ret, ip, port); return (-1); } roledb_server[i].fd = ret; } if (i == 0) { log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "config file wrong, no roldb_srv"); return (-1); } max_roledb_srv = i; active_roledb_srv = &roledb_server[0]; fclose(file); struct timeval t1 = {5, 0}; add_timer(t1, &log_object_timer); log_object_timer.ev_callback = cb_log_object_timer; ret = event_base_loop(base, 0); log4c_category_log(mycat, LOG4C_PRIORITY_INFO, "event_base_loop stoped[%d]", ret); /* tmp = create_container(); tmp = create_container(); tmp = create_container(); destory_container(tmp); tmp = create_container(); destory_container(tmp); tmp = create_container(); */ /* GAME_CIRCLEQ_FOREACH(tmp, pool_container_freed, base.list_free) { printf("tmp[idx] = %d:%d\n", tmp->base.list_free.idx, tmp->base.list_used.idx); } printf("\n ================== \n"); GAME_CIRCLEQ_FOREACH(tmp, pool_container_used, base.list_used) { printf("tmp[idx] = %d:%d\n", tmp->base.list_free.idx, tmp->base.list_used.idx); } */ return (0); }
int main(int argc, char* argv[]) { struct nfq_handle *handle = NULL; struct nfq_q_handle *queue = NULL; struct nfnl_handle *netlink_handle = NULL; struct sigaction action; uint32_t nfqueue_fd = 0; int err = 0; const char* traffic_tap_cat = sff-tap.log"; /* * ----------------------------------------------------------- * Daemonize so that we run in the background * ----------------------------------------------------------- */ int pid; if(getppid() == 1) { printf("No parent PID already a daemon"); exit(0); } pid = fork(); if(pid < 0) { printf("Fork failed"); exit(-1); } if(pid > 0) { /* The parent */ exit(0); } err = init_log4c(); if(err) { return err; } log4c_cat = log4c_category_get(traffic_tap_cat); if (!log4c_cat) { printf("Failed to get log4c category: %s\n", traffic_tap_cat); uninit_log4c(); return TRAFFIC_TAP_INIT_ERROR; } /* Set up handler for SIGTERM for graceful shutdown */ memset(&action, 0, sizeof(struct sigaction)); action.sa_handler = sig_handler; sigaction(SIGTERM, &action, NULL); /* Initialize NF_QUEUE stuff */ handle = nfq_open(); if(!handle) { log4c_category_log(log4c_cat, LOG4C_PRIORITY_ERROR, "Error initializing sff-tap: during nfq_open()"); uninit_log4c(); return SFF_TAP_INIT_ERROR; } if(nfq_unbind_pf(handle, AF_INET) < 0) { log4c_category_log(log4c_cat, LOG4C_PRIORITY_ERROR, "Error initializing sff-tap: during nfq_unbind_pf()"); uninit_log4c(); return SFF_TAP_INIT_ERROR; } if(nfq_bind_pf(handle, AF_INET) < 0) { log4c_category_log(log4c_cat, LOG4C_PRIORITY_ERROR, "Error initializing sff-tap: during nfq_bind_pf()"); uninit_log4c(); return SFF_TAP_INIT_ERROR; } queue = nfq_create_queue(handle, 0, &manage_packet, NULL); if(!queue) { log4c_category_log(log4c_cat, LOG4C_PRIORITY_ERROR, "Error initializing traffic-tap: during nfq_create_queue()"); uninit_log4c(); return SFF_TAP_INIT_ERROR; } if(nfq_set_mode(queue, NFQNL_COPY_PACKET, 0xffff) < 0) { log4c_category_log(log4c_cat, LOG4C_PRIORITY_ERROR, "Error initializing traffic-tap: can't set packet_copy mode"); uninit_log4c(); return SFF_TAP_INIT_ERROR; } netlink_handle = nfq_nfnlh(handle); nfqueue_fd = nfnl_fd(netlink_handle); log4c_category_log(log4c_cat, LOG4C_PRIORITY_NOTICE, "Tap initialized successfully."); while(!exit_flag) { char rcv_buf[RCV_BUF_SIZE]; int received; if((received = recv(nfqueue_fd, rcv_buf, sizeof(rcv_buf), 0)) >= 0 ) { // Call the handle nfq_handle_packet(handle, rcv_buf, received); } } log4c_category_log(log4c_cat, LOG4C_PRIORITY_NOTICE, "SIGTERM caught in tap; exiting."); if(queue != NULL) { nfq_destroy_queue(queue); } if(handle != NULL) { nfq_close(handle); } err = uninit_log4c(); return err; }
AudioStream::AudioStream() { mycat = log4c_category_get("tsparser.elementarystream"); prev = nullptr; }
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; }
ParseAdaptationField::ParseAdaptationField() { mycat = log4c_category_get("tsparser.adaptationfield"); }