From 6be227f3c4083b2fdb0da3eae374477cd9435712 Mon Sep 17 00:00:00 2001 From: VilhoRaatikka Date: Mon, 12 Jan 2015 14:25:37 +0200 Subject: [PATCH] Added comments, removed non-existing function, cleaned up a bit. --- log_manager/log_manager.cc | 39 +++++++++++++++++--------------------- log_manager/log_manager.h | 4 +--- server/core/gateway.c | 34 ++++++++++++++++++--------------- 3 files changed, 37 insertions(+), 40 deletions(-) diff --git a/log_manager/log_manager.cc b/log_manager/log_manager.cc index cffd934df..75bd03872 100644 --- a/log_manager/log_manager.cc +++ b/log_manager/log_manager.cc @@ -677,14 +677,18 @@ static int logmanager_write_log( logfile_rotate(lf); /*< wakes up file writer */ } } - else + else { /** Length of string that will be written, limited by bufsize */ int safe_str_len; /** Length of session id */ int sesid_str_len; - /** 2 braces, 2 spaces and terminating char */ + /** + * 2 braces, 2 spaces and terminating char + * If session id is stored to tls_log_info structure, allocate + * room for session id too. + */ if (id == LOGFILE_TRACE && tls_log_info.li_sesid != 0) { sesid_str_len = 2+2+get_decimal_len(tls_log_info.li_sesid)+1; @@ -747,7 +751,6 @@ static int logmanager_write_log( wp += strlen(wp); } #endif - /** * Write timestamp with at most characters * to wp. @@ -1511,7 +1514,7 @@ return_unregister: logmanager_unregister(); - return_err: +return_err: return err; } @@ -1848,10 +1851,9 @@ static char* fname_conf_get_suffix( * * * Parameters: - * @param lm - - * + * @param lm Log manager pointer * - * @return + * @return succp true if succeed, otherwise false. * * * @details If logfile is supposed to be located to shared memory @@ -1871,6 +1873,7 @@ static bool logfiles_init( bool store_shmem; bool write_syslog; + /** Open syslog immediately. Print pid of loggind process. */ if (syslog_id_str != NULL) { openlog(syslog_ident_str, LOG_PID | LOG_NDELAY, LOG_USER); @@ -2483,21 +2486,13 @@ static bool file_is_symlink( * link name. Create block buffer for logfile. * * Parameters: - * @param logfile - - * - * - * @param logfile_id - - * - * - * @param logmanager - - * - * - * @param store_shmem - - * - * + * @param logfile log file + * @param logfile_id identifier for log file + * @param logmanager log manager pointer + * @param store_shmem flag to indicate whether log is physically written to shmem + * @param write_syslog flag to indicate whether log is also written to syslog + * * @return true if succeed, false otherwise - * - * */ static bool logfile_init( logfile_t* logfile, @@ -2841,7 +2836,7 @@ static void* thr_filewriter_fun( } /** Process all logfiles which have buffered writes. */ - for (i=LOGFILE_FIRST; i<=LOGFILE_LAST; i <<= 1) + for (i=LOGFILE_FIRST; i<=LOGFILE_LAST; i <<= 1) { retry_flush_on_exit: /** diff --git a/log_manager/log_manager.h b/log_manager/log_manager.h index 23beb0d33..f2146d303 100644 --- a/log_manager/log_manager.h +++ b/log_manager/log_manager.h @@ -49,7 +49,7 @@ typedef struct log_info_st { size_t li_sesid; int li_enabled_logs; -} log_info_t; +} log_info_t; #define LE LOGFILE_ERROR #define LM LOGFILE_MESSAGE @@ -122,8 +122,6 @@ void skygw_log_sync_all(void); EXTERN_C_BLOCK_END -void writebuf_clear(void* data); - const char* get_trace_prefix_default(void); const char* get_trace_suffix_default(void); const char* get_msg_prefix_default(void); diff --git a/server/core/gateway.c b/server/core/gateway.c index c4599d270..a32c83a9a 100644 --- a/server/core/gateway.c +++ b/server/core/gateway.c @@ -1531,7 +1531,7 @@ int main(int argc, char **argv) free(log_context); } - /*< + /** * Init Log Manager for MaxScale. * If $MAXSCALE_HOME is set then write the logs into $MAXSCALE_HOME/log. * The skygw_logmanager_init expects to take arguments as passed to main @@ -1541,23 +1541,28 @@ int main(int argc, char **argv) { char buf[1024]; char *argv[8]; - bool succp; - + bool succp; + /** Set log directory under $MAXSCALE_HOME/log */ sprintf(buf, "%s/log", home_dir); - if(mkdir(buf, 0777) != 0){ - - if(errno != EEXIST){ - fprintf(stderr, - "Error: Cannot create log directory: %s\n",buf); - goto return_main; - } - } + + if(mkdir(buf, 0777) != 0) + { + if(errno != EEXIST) + { + fprintf(stderr, + "Error: Cannot create log directory: %s\n", + buf); + goto return_main; + } + } argv[0] = "MaxScale"; argv[1] = "-j"; argv[2] = buf; + if (logtofile) { argv[3] = "-l"; /*< write to syslog */ + /** Logs that should be syslogged */ argv[4] = "LOGFILE_MESSAGE,LOGFILE_ERROR" "LOGFILE_DEBUG,LOGFILE_TRACE"; argv[5] = NULL; @@ -1566,9 +1571,9 @@ int main(int argc, char **argv) else { argv[3] = "-s"; /*< store to shared memory */ - argv[4] = "LOGFILE_DEBUG,LOGFILE_TRACE"; /*< ..these logs to shm */ + argv[4] = "LOGFILE_DEBUG,LOGFILE_TRACE"; /*< to shm */ argv[5] = "-l"; /*< write to syslog */ - argv[6] = "LOGFILE_MESSAGE,LOGFILE_ERROR"; /*< ..these logs to syslog */ + argv[6] = "LOGFILE_MESSAGE,LOGFILE_ERROR"; /*< to syslog */ argv[7] = NULL; succp = skygw_logmanager_init(7, argv); } @@ -1579,8 +1584,7 @@ int main(int argc, char **argv) goto return_main; } } - - /*< + /** * Resolve the full pathname for configuration file and check for * read accessibility. */