From d2ad84c6517902a7c7b64f39241a1b7a5f1d72f0 Mon Sep 17 00:00:00 2001 From: FreeArtMan Date: Sun, 26 Nov 2017 00:23:12 +0000 Subject: Added basic loging --- agni.c | 133 +++++++++++++------------ config_servers.h | 1 + log.c | 50 ++++++++++ log.h | 298 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ sock_conn.h | 8 +- version.h | 4 +- 6 files changed, 422 insertions(+), 72 deletions(-) create mode 100644 log.h diff --git a/agni.c b/agni.c index ea1936e..5ccb6ff 100644 --- a/agni.c +++ b/agni.c @@ -31,6 +31,7 @@ #include "irc_parse.h" #include "mmm.h" #include "stat.h" +#include "log.h" #include "arg.h" @@ -249,7 +250,7 @@ int th_start_client(void *data) qtbl = tbl_qcmd_c(100); if (qtbl == NULL) { - PERM(); + LOG_NONE_W(); } ////////////////////////////////////////////////////////////////////////////// @@ -266,8 +267,8 @@ int th_start_client(void *data) memset(&stats, 0, sizeof(stat_server)); atomic_fetch_add(&cfg->running,1); - printf("Start client\n"); - printf("Server %d\n",cfg->tid); + LOG_NONE_I("Start client\n"); + LOG_NONE_I("Server %d\n",cfg->tid); sleep(1); //PRINT("SERVER:%s PORT:%s USER:%s\n", cfg->server, cfg->port, cfg->user); @@ -294,7 +295,7 @@ int th_start_client(void *data) fret = irc_open(cfg->server, cfg->port, &conn); if (fret != 0) { - ERROR("Cant connect\n"); + LOG_NONE_E("Cant connect\n"); return -1; } //lets timeout after 150 sec, ping from server is 120 sec @@ -311,8 +312,7 @@ int th_start_client(void *data) mq = cfg->mq; if (mq_ntf_getattr(mq, MQ_OUT, &ptr_out_attr) == -1) { - printf("Cant get attribute\n"); - ENL(); + LOG_NONE_E("Cant get attribute\n"); } //PRINT("SERVER:%s PORT:%s USER:%s\n", cfg->server, cfg->port, cfg->user); PRINT("out_attr.mq_msgsize %ld\n", out_attr.mq_msgsize); @@ -320,22 +320,21 @@ int th_start_client(void *data) if (out_buf == NULL) { - ERROR("Can allocate out_buf, size of %ld\n", out_attr.mq_msgsize); + LOG_NONE_E("Can allocate out_buf, size of %ld\n", out_attr.mq_msgsize); } memset(out_buf, 0, out_attr.mq_msgsize); //PRINT("SERVER:%s PORT:%s USER:%s\n", cfg->server, cfg->port, cfg->user); if (mq_ntf_getattr(mq, MQ_IN, &ptr_in_attr) == -1) { - printf("Cant get attribute\n"); - ENL(); + LOG_NONE_E("Cant get attribute\n"); } in_buf = malloc(in_attr.mq_msgsize); memset(in_buf, 0, in_attr.mq_msgsize); if (in_buf == NULL) { - ENL(); + LOG_NONE_E(); } @@ -346,12 +345,12 @@ int th_start_client(void *data) ib = irc_buf_create(); if (ib == NULL) { - PERM(); + LOG_NONE_E(); //return 0; } //send command wait for response - printf("Start loop\n"); + LOG_NONE_I("Start loop\n"); run = 1; while (run) { @@ -368,15 +367,15 @@ int th_start_client(void *data) //memset(in_buf, 0, in_attr.mq_msgsize); if ((byte_num = mq_ntf_read(mq, MQ_IN, in_buf, in_attr.mq_msgsize)) == -1) { - printf("Cant read input message \n"); + LOG_NONE_W("Cant read input message \n"); } else { in_buf[byte_num] = 0x0; - PRINT("Recieve %s\n", in_buf); + LOG_NONE_E("Recieve %s\n", in_buf); } break; default: - printf("Unknown event type\n"); + LOG_NONE_W("Unknown event type\n"); } //fast code to exit if QUIT command is recieved @@ -387,7 +386,7 @@ int th_start_client(void *data) nb_init(nb_resp); nb_load(nb_resp, (unsigned char *)in_buf); rpc_resp_unmarsh(nb_resp, &resp); - PRINT("RESP: %d-%s(%s)\n", resp->id, resp->result, resp->error); + LOG_NONE_D("RESP: %d-%s(%s)\n", resp->id, resp->result, resp->error); tble_cmd_resp *match_resp = malloc(sizeof(tble_cmd_resp)); memset(match_resp, 0, sizeof(tble_cmd_resp)); @@ -400,7 +399,7 @@ int th_start_client(void *data) if (cmd_id > 0) { //BUG HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!.\.,\<\/\/\// - printf("cmd_id %d\n", cmd_id); + LOG_NONE_D("cmd_id %d\n", cmd_id); tble_qcmd *cmd = tbl_qcmd_match_id(qtbl, cmd_id); if (cmd != NULL) { @@ -439,7 +438,7 @@ int th_start_client(void *data) sds sending = sdsnew(cmd_buf); sending = sdscat(sending, tokens[out_i]); sending = sdscat(sending," \r\n"); - printf("SEND>>>>%s",sending); + LOG_NONE_D("SEND>>>>%s",sending); write(conn.conn_fd, sending, sdslen(sending)); sdsfree(sending); } @@ -475,7 +474,7 @@ int th_start_client(void *data) //if((cret = read(conn,conn_buf, 256))>0) if ((cret = irc_read(&conn, conn_buf, 256))>0) { - PRINT(">>READ %d<<\n", cret); + LOG_NONE_D(">>READ %d<<\n", cret); irc_buf_puts(ib, conn_buf, cret); while (irc_buf_ready(ib) == 1) { @@ -491,10 +490,10 @@ int th_start_client(void *data) int fret; const int pong_buf_sz = 128; char pong_buf[pong_buf_sz]; - snprintf(pong_buf,pong_buf_sz,"PONG %s\n",cfg->user); - PRINT("%s",pong_buf) - fret = write(conn.conn_fd,pong_buf,strlen(pong_buf)); - printf("OUT>>PONG %d\n",fret); + snprintf(pong_buf, pong_buf_sz, "PONG %s\n", cfg->user); + LOG_NONE_D("%s", pong_buf) + fret = write(conn.conn_fd, pong_buf, strlen(pong_buf)); + LOG_NONE_D("OUT>>PONG %d\n",fret); } @@ -504,7 +503,7 @@ int th_start_client(void *data) int j; for (j=0;jtk_list[j]->token); + LOG_NONE_D("TK:[%s]\n", itok->tk_list[j]->token); } if (token_cmp(itok,1,"NOTICE")==1) @@ -516,13 +515,13 @@ int th_start_client(void *data) { memset(cmd_buf,0,128); - char *uname = token_new_str(itok,0); - char *ircident = token_new_str(itok,0); - char *irccmd = token_new_str(itok,1); + char *uname = token_new_str(itok,0); + char *ircident = token_new_str(itok,0); + char *irccmd = token_new_str(itok,1); char *dest_name = token_new_str(itok,2); - char *msg = token_new_str(itok,3); //could send without first symbol pal + char *msg = token_new_str(itok,3); //could send without first symbol pal - PRINT("dest_name %s\n",dest_name); + LOG_NONE_D("dest_name %s\n",dest_name); char *sep = strchr(uname,'!'); uname[sep-uname] = 0x0; @@ -531,8 +530,8 @@ int th_start_client(void *data) { //lets check if one more argument is there { - char *chan_name=NULL; - int iter=0; + char *chan_name = NULL; + int iter = 0; char *sep_chan = strchr(msg,' ')+1; //small hack //check if channel in allowed list, if yes then continue @@ -540,7 +539,7 @@ int th_start_client(void *data) while (cfg->channels[iter]!=NULL) { chan_name = cfg->channels[iter]; - printf("%s\n",chan_name); + LOG_NONE_D("%s\n",chan_name); if ((strncmp(chan_name,sep_chan,strlen(chan_name))==0) && (strlen(sep_chan)==strlen(chan_name))) { @@ -553,7 +552,7 @@ int th_start_client(void *data) iter++; if (cfg->channels[iter]==NULL) { - PRINT("Cant find this chan in da list\n"); + LOG_NONE_W("Cant find this chan in da list\n"); } } } @@ -592,7 +591,7 @@ int th_start_client(void *data) memcpy(out_buf, buf_nb, nb_req->size > out_attr.mq_msgsize ? out_attr.mq_msgsize : nb_req->size); mq_ntf_write(mq, MQ_OUT, out_buf, out_attr.mq_msgsize); FREE(buf_nb); - PRINT("Write %d bytes\n", nb_req->size); + LOG_NONE_D("Write %d bytes\n", nb_req->size); rpc_req_free(req); nb_free(nb_req); @@ -626,7 +625,7 @@ int th_start_client(void *data) { while (-1 == irc_reconnect(&conn)) { - printf("Reconnect in 10 sec\n"); + LOG_NONE_I("Reconnect in 10 sec\n"); sleep(10); } //sleep(1); @@ -640,13 +639,13 @@ int th_start_client(void *data) { if (conn.err == ERR_SC_TIMEOUT) { - printf("TIMEOUT\n"); + LOG_NONE_I("TIMEOUT\n"); if (irc_reconnect(&conn)==-1) { while (-1 == irc_reconnect(&conn)) { - printf("Reconnect in 10 sec\n"); + LOG_NONE_I("Reconnect in 10 sec\n"); sleep(10); } //sleep(1); @@ -662,7 +661,7 @@ int th_start_client(void *data) //send command over queue } - printf("End client\n"); + LOG_NONE_I("End client\n"); atomic_fetch_sub( &cfg->running,1); return 0; @@ -753,7 +752,7 @@ int th_event_manager(void *data) ecmd->type = TBL_T_LUA; break; default: - ERROR("No such type, something wrong here\n"); + LOG_NONE_E("No such type, something wrong here\n"); } ecmd->callback = single_cmd->callback; @@ -769,17 +768,17 @@ int th_event_manager(void *data) tbl_exec_print_tbl(etbl, TBL_PF_EXEC_ALL); //config mq - printf("Start event thread\n"); + LOG_NONE_I("Start event thread\n"); mq = cfg->mq_listen; //get mq attributes, FIX out/in everytime could be different pal if (mq_ntf_getattr(mq, MQ_OUT, &ptr_out_attr) == -1) { - printf("Cant get attribute\n"); + LOG_NONE_E("Cant get attribute\n"); } if (mq_ntf_getattr(mq, MQ_IN, &ptr_in_attr) == -1) { - printf("Cant get attribute\n"); + LOG_NONE_E("Cant get attribute\n"); } ////////////////////////////////////////////////////////////////////////////// @@ -796,7 +795,7 @@ int th_event_manager(void *data) //maybe its not null in_buf = malloc(in_attr.mq_msgsize); - printf("Start event loop\n"); + LOG_NONE_I("Start event loop\n"); run = 1; while(run) { @@ -815,12 +814,12 @@ int th_event_manager(void *data) //will fail if some of queue have different buffer size param if ((bytes = mq_ntf_read(&mq[i_mq], MQ_OUT, out_buf, out_attr.mq_msgsize)) == -1) { - printf("Cant read output message\n"); + LOG_NONE_D("Cant read output message\n"); } else { out_buf[out_attr.mq_msgsize-1] = 0x0; stats.cnt_ipc_rx += bytes; - printf("Recieve %s\n", out_buf); + LOG_NONE_D("Recieve %s\n", out_buf); } break; } @@ -834,7 +833,7 @@ int th_event_manager(void *data) if (0 == nb_load(nb_req, (unsigned char *)out_buf)) { rpc_req_unmarsh(nb_req, &req); - PRINT("EVENT-REQ: %d-%s(%s) %s-%s-%s\n", req->id, req->method, req->params, req->user, req->mask, req->server); + LOG_NONE_D("EVENT-REQ: %d-%s(%s) %s-%s-%s\n", req->id, req->method, req->params, req->user, req->mask, req->server); //nb_print(nb_req); if (strncmp(req->method,":PRIVMSG",8)) @@ -860,7 +859,7 @@ int th_event_manager(void *data) { if (ret_msg != NULL) { - printf("Ret message %s\n",(char *)ret_msg); + LOG_NONE_D("Ret message %s\n",(char *)ret_msg); //send response resp = rpc_resp_new(ret_msg,"None",req->id); @@ -873,7 +872,7 @@ int th_event_manager(void *data) mq_ntf_write(mq_cur, MQ_IN, buf_nb, nb_resp->size > in_attr.mq_msgsize ? in_attr.mq_msgsize : nb_resp->size); stats.cnt_ipc_tx += nb_resp->size > in_attr.mq_msgsize ? in_attr.mq_msgsize : nb_resp->size; FREE(buf_nb); - printf("EVENT-Write %ld bytes\n", nb_resp->size > in_attr.mq_msgsize ? in_attr.mq_msgsize : nb_resp->size); + LOG_NONE_D("EVENT-Write %ld bytes\n", nb_resp->size > in_attr.mq_msgsize ? in_attr.mq_msgsize : nb_resp->size); FREE(ret_msg); nb_free(nb_resp); @@ -883,24 +882,24 @@ int th_event_manager(void *data) } } else { - ERROR("Command execution error\n"); + LOG_NONE_E("Command execution error\n"); stats.cnt_cmd_err += 1; } sdsfree(exec_params); } else { - PRINT("Command not in a table\n"); + LOG_NONE_E("Command not in a table\n"); } } else { - ERROR("Unsupporetd irc command\n"); + LOG_NONE_E("Unsupporetd irc command\n"); } //PNL();nb_free(nb_req);PNL(); } else { - ERROR("wrong recieved rpc command\n"); + LOG_NONE_E("wrong recieved rpc command\n"); } } @@ -915,8 +914,7 @@ int th_event_manager(void *data) } FREE(out_buf); - PNL(); - printf("End event thread\n"); + LOG_NONE_D("End event thread\n"); atomic_fetch_sub( &cfg->running,1); return 0; @@ -938,6 +936,9 @@ int main(int argc, char **argv) /*set atomic variables to init value*/ atomic_store(&_glbl_id, 0); + /*logging facilities*/ + log_init(); + log_register_sub(LOG_SUB_NONE, LOG_LEVEL_DEBUG, LOG_LOC_STDIO, NULL); /*Load configs*/ cfg = arg_load(argc, argv, agni_cmd_args); @@ -983,15 +984,15 @@ int main(int argc, char **argv) srvc->stack = malloc(STACK_SIZE); //NULL will brake everything ;) if (srvc->stack == NULL) { - ERROR("BLow"); + LOG_NONE_F("BLow"); } srvc->user = alloc_new_str(isrvc.user); - IF_NULL(srvc->user,{},{ERROR("Cant allocate srvc->user\n")}); + IF_NULL(srvc->user,{},{LOG_NONE_F("Cant allocate srvc->user\n")}); //srvc->password = alloc_new_str(isrvc.password); srvc->server = alloc_new_str(isrvc.server); - IF_NULL(srvc->user,{},{ERROR("Cant allocate srvc->server\n")}); + IF_NULL(srvc->user,{},{LOG_NONE_F("Cant allocate srvc->server\n")}); srvc->port = alloc_new_str(isrvc.port); - IF_NULL(srvc->user,{},{ERROR("Cant allocate srvc->port\n")}); + IF_NULL(srvc->user,{},{LOG_NONE_F("Cant allocate srvc->port\n")}); srvc->ssl = isrvc.ssl; //srvc->channels = isrvc.channels; for (j=0;jchannels[j] = alloc_new_str(isrvc.channels[j]); - IF_NULL(srvc->channels[j],{},{ERROR("Cannt alloc srvc->channels[j]\n");}) + IF_NULL(srvc->channels[j],{},{LOG_NONE_F("Cannt alloc srvc->channels[j]\n");}) } else { srvc->channels[j] = NULL; @@ -1013,18 +1014,18 @@ int main(int argc, char **argv) /* initalise posix mq */ if (0 != mq_ntf_open(&mq_array[i], i)) { - printf("Couldnt open mq_ntf_open\n"); + LOG_NONE_F("Couldnt open mq_ntf_open\n"); } srvc->mq = &mq_array[i]; //try to drain mq mq_ntf_drain(&mq_array[i]); - PRINT("SERVER:%s PORT:%s USER:%s\n", srvc->server, srvc->port, srvc->user); + LOG_NONE_I("SERVER:%s PORT:%s USER:%s\n", srvc->server, srvc->port, srvc->user); /* clone new proc */ if (-1 == clone(th_start_client, srvc->stack+STACK_SIZE, CLONE_VM|CLONE_FILES, (void *)srvc)) { - ERROR("Cant allocate new server process\n"); + LOG_NONE_E("Cant allocate new server process\n"); } } @@ -1032,20 +1033,20 @@ int main(int argc, char **argv) evhnd_cfg = malloc(sizeof(event_handler_cfg)); if (evhnd_cfg == NULL) { - ERROR("cant allocate event handler\n"); + LOG_NONE_E("cant allocate event handler\n"); } memset(evhnd_cfg, 0, sizeof(event_handler_cfg)); evhnd_cfg->stack = malloc(EVENT_HND_STACK_SIZE); if (evhnd_cfg->stack == NULL) { - ERROR("Cant allocate event handler stack\n"); + LOG_NONE_E("Cant allocate event handler stack\n"); } atomic_store(&evhnd_cfg->running, 0); evhnd_cfg->mq_num = cnt_servers; evhnd_cfg->mq_listen = mq_array; if (-1 == clone(th_event_manager, evhnd_cfg->stack+EVENT_HND_STACK_SIZE, CLONE_VM|CLONE_FILES, (void *)evhnd_cfg)) { - ERROR("Couldnt create process\n"); + LOG_NONE_E("Couldnt create process\n"); } //PNL(); @@ -1071,7 +1072,7 @@ int main(int argc, char **argv) FREE(cfg_list); - ERROR("Exit\n"); + LOG_NONE_E("Exit\n"); return 0; } \ No newline at end of file diff --git a/config_servers.h b/config_servers.h index c61c053..bdc4e42 100644 --- a/config_servers.h +++ b/config_servers.h @@ -17,6 +17,7 @@ typedef struct irc_server_conf int ssl; int enabled; char *channels[SERV_CHAN_MAX_NUM]; + int connected; //show that was allready connected to chan } irc_server_conf; void free_irc_server_conf(irc_server_conf *isc); diff --git a/log.c b/log.c index e69de29..a3c2798 100644 --- a/log.c +++ b/log.c @@ -0,0 +1,50 @@ +#include "log.h" + +int log_register_sub(int sub, int level, int loc, char *location) +{ + FILE *fd=NULL; + + if ((sub < LOG_SUB_NONE) || (sub > LOG_SUB_NET)) + { + printf("Cant register logging\n"); + return -1; + } + + if (loc == LOG_LOC_FILE) + { + fd = fopen(location, "a"); + if (fd == NULL) + { + printf("Cant open file for logging %s\n", location); + return -1; + } + + } + + __logs[sub].disabled = 0; + __logs[sub].sub = sub; + __logs[sub].level = level; + __logs[sub].location = loc; + __logs[sub].fd = fd; + __logs[sub].fname = location; + + return 0; +} + +int log_init() +{ + int i; + + for (i=0;i +#include + +//bunch of macroses that will just disable log code and save some binary space +#define LOG_DEBUG_ENABLE +#define LOG_ERROR_ENABLE +#define LOG_WARNING_ENABLE +#define LOG_FATAL_ENABLE +#define LOG_INFO_ENABLE + +#define SUB_MEM +#define SUB_CMDS +#define SUB_MSG +#define SUB_NET + +//log level +#define LOG_LEVEL_NONE 0 +#define LOG_LEVEL_FATAL 1 +#define LOG_LEVEL_ERROR 2 +#define LOG_LEVEL_WARNING 3 +#define LOG_LEVEL_INFO 4 +#define LOG_LEVEL_DEBUG 5 + +//logging subsystem +#define LOG_SUB_NONE 0 +#define LOG_SUB_MEM 1 +#define LOG_SUB_CMDS 2 +#define LOG_SUB_MSG 3 +#define LOG_SUB_NET 4 + +//loging location +#define LOG_LOC_STDIO 0 +#define LOG_LOC_FILE 1 + +typedef struct logging_t +{ + int disabled; + int sub; + int level; + int location; + FILE *fd; + char *fname; +} logging_t; + +#define NUM_OF_LOG 5 +logging_t __logs[NUM_OF_LOG]; //<-be carefull with this number woop woop + +int log_init(); +int log_register_sub(int sub, int level, int type, char *location); + +#define LOG_PRINTF fprintf +#define LOG_COLORIZE +#define LOG_PRINT_LINENUM +#define LOG_PRINT_FILENAME +#define LOG_PRINT_DEBUG + +//use color +#ifdef LOG_COLORIZE + #define LOG_D_COLOR "7;32m" + #define LOG_D_COLOR_S "\033[" LOG_D_COLOR + #define LOG_D_COLOR_E "\033[0m" + #define LOG_E_COLOR "0;31m" + #define LOG_E_COLOR_S "\033[" LOG_E_COLOR + #define LOG_E_COLOR_E "\033[0m" + #define LOG_W_COLOR "0;35m" + #define LOG_W_COLOR_S "\033[" LOG_W_COLOR + #define LOG_W_COLOR_E "\033[0m" + #define LOG_F_COLOR "5;31m" + #define LOG_F_COLOR_S "\033[" LOG_F_COLOR + #define LOG_F_COLOR_E "\033[0m" + #define LOG_I_COLOR "0;36m" + #define LOG_I_COLOR_S "\033[" LOG_I_COLOR + #define LOG_I_COLOR_E "\033[0m" +#else + #define LOG_D_COLOR + #define LOG_D_COLOR_S + #define LOG_D_COLOR_E + #define LOG_E_COLOR + #define LOG_E_COLOR_S + #define LOG_E_COLOR_E + #define LOG_W_COLOR + #define LOG_W_COLOR_S + #define LOG_W_COLOR_E + #define LOG_F_COLOR + #define LOG_F_COLOR_S + #define LOG_F_COLOR_E + #define LOG_I_COLOR + #define LOG_I_COLOR_S + #define LOG_I_COLOR_E +#endif + +//print debug line +#ifdef LOG_PRINT_LINENUM + #define LOG_PRINT_LINE_F ":%d " + #define LOG_PRINT_LINE_D __LINE__ +#else + #define LOG_PRINT_LINE_F "%s" + #define LOG_PRINT_LINE_D " " +#endif + +//print +#ifdef LOG_PRINT_FILENAME + #define LOG_PRINT_FILE_F "%s" + #define LOG_PRINT_FILE_D __FILE__ +#else + #define LOG_PRINT_FILE_F "%s" + #define LOG_PRINT_FILE_D " " +#endif + +//print debug string +#ifdef LOG_PRINT_DEBUG + #define LOG_PRINT_DEBUG_F "DEBUG: " + #define LOG_PRINT_WARNING_F "WARN: " + #define LOG_PRINT_FATAL_F "FATAL: " + #define LOG_PRINT_INFO_F "INFO: " + #define LOG_PRINT_ERROR_F "ERROR: " +#else + #define LOG_PRINT_DEBUG_F "" + #define LOG_PRINT_WARNING_F "" + #define LOG_PRINT_FATAL_F "" + #define LOG_PRINT_ERROR_F "" + #define LOG_PRINT_INFO_F "" +#endif + +#define LOG_INFO( fd, format, args ... ) LOG_PRINTF( fd, LOG_I_COLOR_S LOG_PRINT_INFO_F \ + LOG_PRINT_FILE_F LOG_PRINT_LINE_F format LOG_I_COLOR_E, LOG_PRINT_FILE_D, \ + LOG_PRINT_LINE_D, ##args); + +#define LOG_DEBUG( fd, format, args ... ) LOG_PRINTF( fd, LOG_D_COLOR_S LOG_PRINT_DEBUG_F \ + LOG_PRINT_FILE_F LOG_PRINT_LINE_F format LOG_D_COLOR_E, LOG_PRINT_FILE_D, \ + LOG_PRINT_LINE_D, ##args); + +#define LOG_ERROR( fd, format, args ... ) LOG_PRINTF( fd, LOG_E_COLOR_S LOG_PRINT_ERROR_F \ + LOG_PRINT_FILE_F LOG_PRINT_LINE_F format LOG_E_COLOR_E, LOG_PRINT_FILE_D, \ + LOG_PRINT_LINE_D, ##args); + +#define LOG_WARNING( fd, format, args ... ) LOG_PRINTF( fd, LOG_W_COLOR_S LOG_PRINT_WARNING_F \ + LOG_PRINT_FILE_F LOG_PRINT_LINE_F format LOG_W_COLOR_E, LOG_PRINT_FILE_D, \ + LOG_PRINT_LINE_D, ##args); + +#define LOG_FATAL( fd, format, args ... ) LOG_PRINTF( fd, LOG_F_COLOR_S LOG_PRINT_FATAL_F \ + LOG_PRINT_FILE_F LOG_PRINT_LINE_F format LOG_F_COLOR_E, LOG_PRINT_FILE_D, \ + LOG_PRINT_LINE_D, ##args); + +//------------------------------------------------------------------------------ +#ifdef LOG_INFO_ENABLE + #define LOG_NONE_I(format,args ... ) {\ + if (0 == __logs[LOG_SUB_NONE].disabled){\ + if (__logs[LOG_SUB_NONE].level >= LOG_LEVEL_INFO){\ + if (__logs[LOG_SUB_NONE].location == LOG_LOC_STDIO){\ + LOG_INFO(stdout, format, ##args );\ + } else {\ + LOG_INFO(__logs[LOG_SUB_NONE].fd, format, ##args );\ + }}}\ + } + #ifdef SUB_MEM + #define LOG_MEM_I(format,args ... ) {\ + if (0 == __logs[LOG_SUB_MEM].disabled){\ + if (__logs[LOG_SUB_MEM].level >= LOG_LEVEL_INFO){\ + if (__logs[LOG_SUB_MEM].location == LOG_LOC_STDIO){\ + LOG_INFO(stdout, "MEM-" );\ + LOG_INFO(stdout, format, ##args );\ + } else {\ + LOG_INFO(stdout, "MEM-" );\ + LOG_INFO(__logs[LOG_SUB_MEM].fd, format, ##args );\ + }}}\ + } + #else + #define LOG_MEM_I(format,args ...) {} + #endif +#else + LOG_NONE_I(format,args ...) {} +#endif + +//------------------------------------------------------------------------------ +#ifdef LOG_INFO_ENABLE + #define LOG_NONE_D(format,args ... ) {\ + if (0 == __logs[LOG_SUB_NONE].disabled){\ + if (__logs[LOG_SUB_NONE].level >= LOG_LEVEL_DEBUG){\ + if (__logs[LOG_SUB_NONE].location == LOG_LOC_STDIO){\ + LOG_DEBUG(stdout, format, ##args );\ + } else {\ + LOG_DEBUG(__logs[LOG_SUB_NONE].fd, format, ##args );\ + }}}\ + } + #ifdef SUB_MEM + #define LOG_MEM_D(format,args ... ) {\ + if (0 == __logs[LOG_SUB_MEM].disabled){\ + if (__logs[LOG_SUB_MEM].level >= LOG_LEVEL_DEBUG){\ + if (__logs[LOG_SUB_MEM].location == LOG_LOC_STDIO){\ + LOG_DEBUG(stdout, "MEM-" );\ + LOG_DEBUG(stdout, format, ##args );\ + } else {\ + LOG_DEBUG(__logs[LOG_SUB_MEM].fd, "MEM-" );\ + LOG_DEBUG(__logs[LOG_SUB_MEM].fd, format, ##args );\ + }}}\ + } + #else + #define LOG_MEM_D(format,args ...) {} + #endif +#else + LOG_NONE_D(format,args ...) {} +#endif + +//------------------------------------------------------------------------------ +#ifdef LOG_INFO_ENABLE + #define LOG_NONE_E(format,args ... ) {\ + if (0 == __logs[LOG_SUB_NONE].disabled){\ + if (__logs[LOG_SUB_NONE].level >= LOG_LEVEL_ERROR){\ + if (__logs[LOG_SUB_NONE].location == LOG_LOC_STDIO){\ + LOG_ERROR(stdout, format, ##args );\ + } else {\ + LOG_ERROR(__logs[LOG_SUB_NONE].fd, format, ##args );\ + }}}\ + } + #ifdef SUB_MEM + #define LOG_MEM_E(format,args ... ) {\ + if (0 == __logs[LOG_SUB_MEM].disabled){\ + if (__logs[LOG_SUB_MEM].level >= LOG_LEVEL_ERROR){\ + if (__logs[LOG_SUB_MEM].location == LOG_LOC_STDIO){\ + LOG_ERROR(stdout, "MEM-" );\ + LOG_ERROR(stdout, format, ##args );\ + } else {\ + LOG_ERROR(__logs[LOG_SUB_MEM].fd, "MEM-" );\ + LOG_ERROR(__logs[LOG_SUB_MEM].fd, format, ##args );\ + }}}\ + } + #else + #define LOG_MEM_E(format,args ...) {} + #endif +#else + LOG_NONE_E(format,args ...) {} +#endif + +//------------------------------------------------------------------------------ +#ifdef LOG_INFO_ENABLE + #define LOG_NONE_W(format,args ... ) {\ + if (0 == __logs[LOG_SUB_NONE].disabled){\ + if (__logs[LOG_SUB_NONE].level >= LOG_LEVEL_WARNING){\ + if (__logs[LOG_SUB_NONE].location == LOG_LOC_STDIO){\ + LOG_WARNING(stdout, format, ##args );\ + } else {\ + LOG_WARNING(__logs[LOG_SUB_NONE].fd, format, ##args );\ + }}}\ + } + #ifdef SUB_MEM + #define LOG_MEM_W(format,args ... ) {\ + if (0 == __logs[LOG_SUB_MEM].disabled){\ + if (__logs[LOG_SUB_MEM].level >= LOG_LEVEL_WARNING){\ + if (__logs[LOG_SUB_MEM].location == LOG_LOC_STDIO){\ + LOG_WARNING(stdout, "MEM-" );\ + LOG_WARNING(stdout, format, ##args );\ + } else {\ + LOG_WARNING(__logs[LOG_SUB_MEM].fd, "MEM-" );\ + LOG_WARNING(__logs[LOG_SUB_MEM].fd, format, ##args );\ + }}}\ + } + #else + #define LOG_MEM_W(format,args ...) {} + #endif +#else + LOG_NONE_W(format,args ...) {} +#endif + +//------------------------------------------------------------------------------ +#ifdef LOG_INFO_ENABLE + #define LOG_NONE_F(format,args ... ) {\ + if (0 == __logs[LOG_SUB_NONE].disabled){\ + if (__logs[LOG_SUB_NONE].level >= LOG_LEVEL_FATAL){\ + if (__logs[LOG_SUB_NONE].location == LOG_LOC_STDIO){\ + LOG_FATAL(stdout, format, ##args );\ + } else {\ + LOG_FATAL(__logs[LOG_SUB_NONE].fd, format, ##args );\ + }}}\ + } + #ifdef SUB_MEM + #define LOG_MEM_F(format,args ... ) {\ + if (0 == __logs[LOG_SUB_MEM].disabled){\ + if (__logs[LOG_SUB_MEM].level >= LOG_LEVEL_FATAL){\ + if (__logs[LOG_SUB_MEM].location == LOG_LOC_STDIO){\ + LOG_FATAL(stdout, "MEM-" );\ + LOG_FATAL(stdout, format, ##args );\ + } else {\ + LOG_FATAL(__logs[LOG_SUB_MEM].fd, "MEM-" );\ + LOG_FATAL(__logs[LOG_SUB_MEM].fd, format, ##args );\ + }}}\ + } + #else + #define LOG_MEM_F(format,args ...) {} + #endif +#else + LOG_NONE_f(format,args ...) {} +#endif + +#endif \ No newline at end of file diff --git a/sock_conn.h b/sock_conn.h index 8cf64be..b72271a 100644 --- a/sock_conn.h +++ b/sock_conn.h @@ -47,13 +47,13 @@ int irc_buf_destroy(irc_buf *ib); //connecto to irc typedef struct irc_conn { - int conn_fd; //save connection fd + int conn_fd; //save connection fd char *hostname; char *port; struct timespec last_read; //when last read where happening - int timeout; - int err; //local error type - int liberr; //save error from libc + int timeout; + int err; //local error type + int liberr; //save error from libc } irc_conn; int irc_connect(char *hostname, char *port); diff --git a/version.h b/version.h index e2f929e..c1037a0 100644 --- a/version.h +++ b/version.h @@ -1,5 +1,5 @@ #ifndef __VERSION_H #define __VERSION_H -#define VERSION_DATE "Sat Nov 25 11:30:56 GMT 2017" -#define VERSION_COMMIT "3967218 Bug in todo handling usernames, needed to use base64 encoded username" +#define VERSION_DATE "Sun Nov 26 00:22:31 GMT 2017" +#define VERSION_COMMIT "32f380f Hunting down all warnings" #endif -- cgit v1.2.3