From 812bc70dae80637548a0ccfab649f8912a09faf5 Mon Sep 17 00:00:00 2001 From: Edward Rudd Date: Sun, 4 Apr 2004 07:45:30 +0000 Subject: Updated to new logging function with apaceh 2 prototype instead of 1.3 so i can properly log Error numbers in apache 2 (better debugging) --- apache13.h | 11 ++-------- apache20.h | 6 ++++-- functions.h | 10 ++++----- mod_log_sql.c | 62 ++++++++++++++++++++++++++++++----------------------- mod_log_sql.prj | 3 ++- mod_log_sql_mysql.c | 12 +++++------ mod_log_sql_ssl.c | 6 +++--- 7 files changed, 57 insertions(+), 53 deletions(-) diff --git a/apache13.h b/apache13.h index 6d756b6..d5aeac5 100644 --- a/apache13.h +++ b/apache13.h @@ -14,13 +14,6 @@ #define APR_SUCCESS 0 #define APR_OFFSETOF XtOffsetOf -/*AP_INIT_TAKE1("LogSQLTransferLogTable", set_server_nmv_string_slot, - (void *)APR_OFFSETOF(logsql_state, transfer_table_name), RSRC_CONF, - "The database table that holds the transfer log") - -{"LogSQLTransferLogTable", set_log_sql_transfer_table, NULL, RSRC_CONF, TAKE1, - "The database table that holds the transfer log"}*/ - /** method of declaring a directive which takes 1 argument */ # define AP_INIT_TAKE1(directive, func, mconfig, where, help) \ { directive, func, mconfig, where, TAKE1, help } @@ -66,8 +59,8 @@ #define apr_tolower ap_tolower -static void log_error(char *file, int line, int level, const server_rec *s, const char *fmt, ...) __attribute__ ((format (printf, 5,6))); -static inline void log_error(char *file, int line, int level, const server_rec *s, const char *fmt, ...) +static void log_error(char *file, int line, int level, apr_status_t status, const server_rec *s, const char *fmt, ...) __attribute__ ((format (printf, 5,6))); +static inline void log_error(char *file, int line, int level, apr_status_t status, const server_rec *s, const char *fmt, ...) { static char buff[MAX_STRING_LEN]; va_list args; diff --git a/apache20.h b/apache20.h index 1b54858..1c6d12c 100644 --- a/apache20.h +++ b/apache20.h @@ -20,7 +20,7 @@ #include "util_time.h" -static void log_error(char *file, int line, int level, const server_rec *s, const char *fmt, ...) __attribute__ ((format (printf, 5,6))); +/*static void log_error(char *file, int line, int level, const server_rec *s, const char *fmt, ...) __attribute__ ((format (printf, 5,6))); static inline void log_error(char *file, int line, int level, const server_rec *s, const char *fmt, ...) { static char buff[MAX_STRING_LEN]; @@ -29,6 +29,8 @@ static inline void log_error(char *file, int line, int level, const server_rec * apr_vsnprintf(buff,MAX_STRING_LEN, fmt,args); ap_log_error(file,line,level,0,s,"%s",buff); va_end(args); -} +}*/ + +#define log_error ap_log_error #endif /* APACHE20_H */ diff --git a/functions.h b/functions.h index 540376e..2c06f61 100644 --- a/functions.h +++ b/functions.h @@ -175,13 +175,13 @@ static const char *extract_specific_cookie(request_rec *r, char *a) char *cookiebuf; if (a != NULL) { - log_error(APLOG_MARK,APLOG_DEBUG, - r->server,"watching for cookie '%s'", a); + log_error(APLOG_MARK,APLOG_DEBUG, 0, r->server, + "watching for cookie '%s'", a); /* Fetch out the cookie header */ cookiestr = (char *)apr_table_get(r->headers_in, "cookie2"); if (cookiestr != NULL) { - log_error(APLOG_MARK,APLOG_DEBUG,r->server, + log_error(APLOG_MARK,APLOG_DEBUG, 0, r->server, "Cookie2: [%s]", cookiestr); /* Does the cookie string contain one with our name? */ isvalid = strstr(cookiestr, a); @@ -201,7 +201,7 @@ static const char *extract_specific_cookie(request_rec *r, char *a) cookiestr = (char *)apr_table_get(r->headers_in, "cookie"); if (cookiestr != NULL) { - log_error(APLOG_MARK,APLOG_DEBUG,r->server, + log_error(APLOG_MARK,APLOG_DEBUG, 0, r->server, "Cookie: [%s]", cookiestr); isvalid = strstr(cookiestr, a); if (isvalid != NULL) { @@ -216,7 +216,7 @@ static const char *extract_specific_cookie(request_rec *r, char *a) cookiestr = apr_table_get(r->headers_out, "set-cookie"); if (cookiestr != NULL) { - log_error(APLOG_MARK,APLOG_DEBUG,r->server, + log_error(APLOG_MARK,APLOG_DEBUG, 0, r->server, "Set-Cookie: [%s]", cookiestr); isvalid = strstr(cookiestr, a); if (isvalid != NULL) { diff --git a/mod_log_sql.c b/mod_log_sql.c index a247f30..3b4e6f4 100644 --- a/mod_log_sql.c +++ b/mod_log_sql.c @@ -164,7 +164,8 @@ static logsql_opendb_ret log_sql_opendb_link(server_rec* s) } return result; } else { - log_error(APLOG_MARK,APLOG_ERR,s,"mod_log_sql: insufficient configuration info to establish database link"); + log_error(APLOG_MARK, APLOG_ERR, 0, s, + "mod_log_sql: insufficient configuration info to establish database link"); return LOGSQL_OPENDB_FAIL; } } @@ -188,10 +189,11 @@ static void preserve_entry(request_rec *r, const char *query) FILE *fp; int result; fp = ap_pfopen(r->pool, cls->preserve_file, "a"); - result = (fp)?0:1; + result = (fp)?0:errno; #endif if (result != APR_SUCCESS) { - log_error(APLOG_MARK,APLOG_ERR,r->server,"attempted append of local preserve file '%s' but failed.",cls->preserve_file); + log_error(APLOG_MARK, APLOG_ERR, result, r->server, + "attempted append of local preserve file '%s' but failed.",cls->preserve_file); } else { #if defined(WITH_APACHE20) apr_file_printf(fp,"%s;\n", query); @@ -200,7 +202,8 @@ static void preserve_entry(request_rec *r, const char *query) fprintf(fp,"%s;\n", query); ap_pfclose(r->pool, fp); #endif - log_error(APLOG_MARK,APLOG_DEBUG,r->server,"mod_log_sql: entry preserved in %s", cls->preserve_file); + log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, + "mod_log_sql: entry preserved in %s", cls->preserve_file); } } @@ -403,14 +406,17 @@ static void log_sql_child_init(server_rec *s, apr_pool_t *p) retval = log_sql_opendb_link(s); switch (retval) { case LOGSQL_OPENDB_FAIL: - log_error(APLOG_MARK,APLOG_ERR,s,"mod_log_sql: child spawned but unable to open database link"); + log_error(APLOG_MARK, APLOG_ERR, 0, s, + "mod_log_sql: child spawned but unable to open database link"); break; case LOGSQL_OPENDB_SUCCESS: case LOGSQL_OPENDB_ALREADY: - log_error(APLOG_MARK,APLOG_DEBUG,s,"mod_log_sql: open_logdb_link successful"); + log_error(APLOG_MARK,APLOG_DEBUG,0, s, + "mod_log_sql: open_logdb_link successful"); break; case LOGSQL_OPENDB_PRESERVE: - log_error(APLOG_MARK,APLOG_DEBUG,s,"mod_log_sql: open_logdb_link said that preservation is forced"); + log_error(APLOG_MARK,APLOG_DEBUG, 0, s, + "mod_log_sql: open_logdb_link said that preservation is forced"); break; } } @@ -488,7 +494,7 @@ static logsql_query_ret safe_sql_insert(request_rec *r, logsql_tabletype table_t global_config.db.connected = 0; /* re-open the connection and try again */ if (log_sql_opendb_link(r->server) != LOGSQL_OPENDB_FAIL) { - log_error(APLOG_MARK,APLOG_ERR,r->server,"db reconnect successful"); + log_error(APLOG_MARK,APLOG_NOTICE,0, r->server,"db reconnect successful"); # if defined(WITH_APACHE20) apr_sleep(apr_time_from_sec(0.25)); /* pause for a quarter second */ # elif defined(WITH_APACHE13) @@ -499,7 +505,7 @@ static logsql_query_ret safe_sql_insert(request_rec *r, logsql_tabletype table_t delay.tv_nsec = 250000000; /* pause for a quarter second */ nanoret = nanosleep(&delay, &remainder); if (nanoret && errno != EINTR) { - log_error(APLOG_MARK,APLOG_ERR,r->server,"nanosleep unsuccessful"); + log_error(APLOG_MARK,APLOG_ERR, errno, r->server,"nanosleep unsuccessful"); } } # endif @@ -507,50 +513,52 @@ static logsql_query_ret safe_sql_insert(request_rec *r, logsql_tabletype table_t if (result == LOGSQL_QUERY_SUCCESS) { return LOGSQL_QUERY_SUCCESS; } else { - log_error(APLOG_MARK,APLOG_ERR,r->server,"second attempt failed"); + log_error(APLOG_MARK,APLOG_ERR,0,r->server,"second attempt failed"); preserve_entry(r, query); return LOGSQL_QUERY_PRESERVED; } } else { - log_error(APLOG_MARK,APLOG_ERR,r->server,"reconnect failed, unable to reach database. SQL logging stopped until child regains a db connection."); - log_error(APLOG_MARK,APLOG_ERR,r->server,"log entries are being preserved in %s",cls->preserve_file); + log_error(APLOG_MARK,APLOG_ERR,0,r->server, + "reconnect failed, unable to reach database. SQL logging stopped until child regains a db connection."); + log_error(APLOG_MARK,APLOG_ERR,0,r->server, + "log entries are being preserved in %s",cls->preserve_file); preserve_entry(r, query); return LOGSQL_QUERY_PRESERVED; } break; case LOGSQL_QUERY_NOTABLE: if (global_config.createtables) { - log_error(APLOG_MARK,APLOG_ERR,r->server, + log_error(APLOG_MARK,APLOG_ERR,0,r->server, "table doesn't exist...creating now"); if ((result = log_sql_mysql_create(r, &global_config.db, table_type, table_name))!=LOGSQL_TABLE_SUCCESS) { - log_error(APLOG_MARK,APLOG_ERR,r->server, + log_error(APLOG_MARK,APLOG_ERR,result,r->server, "child attempted but failed to create one or more tables for %s, preserving query", ap_get_server_name(r)); preserve_entry(r, query); return LOGSQL_QUERY_PRESERVED; } else { - log_error(APLOG_MARK,APLOG_ERR,r->server, + log_error(APLOG_MARK,APLOG_ERR,result, r->server, "tables successfully created - retrying query"); if ((result = log_sql_mysql_query(r,&global_config.db,query))!=LOGSQL_QUERY_SUCCESS) { - log_error(APLOG_MARK,APLOG_ERR,r->server, + log_error(APLOG_MARK,APLOG_ERR,result, r->server, "giving up, preserving query"); preserve_entry(r, query); return LOGSQL_QUERY_PRESERVED; } else { - log_error(APLOG_MARK,APLOG_ERR,r->server, + log_error(APLOG_MARK,APLOG_NOTICE,0, r->server, "query successful after table creation"); return LOGSQL_QUERY_SUCCESS; } } } else { - log_error(APLOG_MARK,APLOG_ERR,r->server, + log_error(APLOG_MARK,APLOG_ERR,0,r->server, "table doesn't exist, creation denied by configuration, preserving query"); preserve_entry(r, query); return LOGSQL_QUERY_PRESERVED; } break; default: - log_error(APLOG_MARK,APLOG_ERR,r->server, + log_error(APLOG_MARK,APLOG_ERR,0, r->server, "Invalid return code from mog_log_query"); return LOGSQL_QUERY_FAIL; break; @@ -773,7 +781,7 @@ static int log_sql_transaction(request_rec *orig) for (i = 0; iparsed_log_format[i]; if (item==NULL) { - log_error(APLOG_MARK, APLOG_ERR, orig->server, + log_error(APLOG_MARK, APLOG_ERR, 0, orig->server, "Log Format '%c' unknown",cls->transfer_log_format[i]); continue; } @@ -825,7 +833,7 @@ static int log_sql_transaction(request_rec *orig) note_query = apr_psprintf(r->pool, "insert %s into `%s` (id, item, val) values %s", /*global_config.insertdelayed?"delayed":*/"", notes_tablename, itemsets); - log_error(APLOG_MARK,APLOG_DEBUG,orig->server,"mod_log_sql: note string: %s", note_query); + log_error(APLOG_MARK,APLOG_DEBUG,0, orig->server,"mod_log_sql: note string: %s", note_query); } /* Work through the list of headers-out defined by LogSQLWhichHeadersOut*/ @@ -853,7 +861,7 @@ static int log_sql_transaction(request_rec *orig) hout_query = apr_psprintf(r->pool, "insert %s into `%s` (id, item, val) values %s", /*global_config.insertdelayed?"delayed":*/"", hout_tablename, itemsets); - log_error(APLOG_MARK,APLOG_DEBUG,orig->server,"mod_log_sql: header_out string: %s", hout_query); + log_error(APLOG_MARK,APLOG_DEBUG,0, orig->server,"mod_log_sql: header_out string: %s", hout_query); } @@ -882,7 +890,7 @@ static int log_sql_transaction(request_rec *orig) hin_query = apr_psprintf(r->pool, "insert %s into `%s` (id, item, val) values %s", /*global_config.insertdelayed?"delayed":*/"", hin_tablename, itemsets); - log_error(APLOG_MARK,APLOG_DEBUG,orig->server,"mod_log_sql: header_in string: %s", hin_query); + log_error(APLOG_MARK,APLOG_DEBUG,0, orig->server,"mod_log_sql: header_in string: %s", hin_query); } @@ -912,7 +920,7 @@ static int log_sql_transaction(request_rec *orig) cookie_query = apr_psprintf(r->pool, "insert %s into `%s` (id, item, val) values %s", /*global_config.insertdelayed?"delayed":*/"", cookie_tablename, itemsets); - log_error(APLOG_MARK,APLOG_DEBUG,orig->server,"mod_log_sql: cookie string: %s", cookie_query); + log_error(APLOG_MARK,APLOG_DEBUG,0, orig->server,"mod_log_sql: cookie string: %s", cookie_query); } @@ -920,13 +928,13 @@ static int log_sql_transaction(request_rec *orig) access_query = apr_psprintf(r->pool, "insert %s into `%s` (%s) values (%s)", /*global_config.insertdelayed?"delayed":*/"", transfer_tablename, fields, values); - log_error(APLOG_MARK,APLOG_DEBUG,r->server,"mod_log_sql: access string: %s", access_query); + log_error(APLOG_MARK,APLOG_DEBUG,0, r->server,"mod_log_sql: access string: %s", access_query); /* If the person activated force-preserve, go ahead and push all the entries * into the preserve file, then return. */ if (global_config.forcepreserve) { - log_error(APLOG_MARK,APLOG_DEBUG,orig->server,"mod_log_sql: preservation forced"); + log_error(APLOG_MARK,APLOG_DEBUG,0, orig->server,"mod_log_sql: preservation forced"); preserve_entry(orig, access_query); if ( note_query != NULL ) preserve_entry(orig, note_query); @@ -964,7 +972,7 @@ static int log_sql_transaction(request_rec *orig) return OK; } else { /* Whew, we got the DB link back */ - log_error(APLOG_MARK,APLOG_NOTICE,orig->server,"mod_log_sql: child established database connection"); + log_error(APLOG_MARK,APLOG_NOTICE,0, orig->server,"mod_log_sql: child established database connection"); } } diff --git a/mod_log_sql.prj b/mod_log_sql.prj index 9cd8fea..81050ce 100644 --- a/mod_log_sql.prj +++ b/mod_log_sql.prj @@ -101,7 +101,8 @@ module.doc.files=\ LICENSE\ AUTHORS\ TODO\ - Documentation/manual.xml + Documentation/manual.xml\ + TODO.in module.po.expanded=0 module.po.files= diff --git a/mod_log_sql_mysql.c b/mod_log_sql_mysql.c index edc0189..a3f8bbc 100644 --- a/mod_log_sql_mysql.c +++ b/mod_log_sql_mysql.c @@ -50,13 +50,13 @@ logsql_opendb_ret log_sql_mysql_connect(server_rec *s, logsql_dbconnection *db) if (mysql_real_connect(dblink, host, user, passwd, database, tcpport, socketfile, 0)) { - log_error(APLOG_MARK,APLOG_DEBUG,s,"HOST: '%s' PORT: '%d' DB: '%s' USER: '%s' SOCKET: '%s'", + log_error(APLOG_MARK,APLOG_DEBUG,0, s,"HOST: '%s' PORT: '%d' DB: '%s' USER: '%s' SOCKET: '%s'", host, tcpport, database, user, socketfile); return LOGSQL_OPENDB_SUCCESS; } else { - log_error(APLOG_MARK,APLOG_DEBUG,s,"mod_log_sql: database connection error: %s", + log_error(APLOG_MARK,APLOG_DEBUG,0, s,"mod_log_sql: database connection error: %s", MYSQL_ERROR(dblink)); - log_error(APLOG_MARK,APLOG_DEBUG,s,"HOST: '%s' PORT: '%d' DB: '%s' USER: '%s' SOCKET: '%s'", + log_error(APLOG_MARK,APLOG_DEBUG, 0, s,"HOST: '%s' PORT: '%d' DB: '%s' USER: '%s' SOCKET: '%s'", host, tcpport, database, user, socketfile); return LOGSQL_OPENDB_FAIL; } @@ -135,7 +135,7 @@ logsql_query_ret log_sql_mysql_query(request_rec *r,logsql_dbconnection *db, real_error = mysql_errno(dblink); if (real_error == ER_NO_SUCH_TABLE) { - log_error(APLOG_MARK,APLOG_ERR,r->server,"table does not exist, preserving query"); + log_error(APLOG_MARK,APLOG_ERR,0, r->server,"table does not exist, preserving query"); /* Restore SIGPIPE to its original handler function */ signal(SIGPIPE, handler); return LOGSQL_QUERY_NOTABLE; @@ -213,7 +213,7 @@ logsql_table_ret log_sql_mysql_create(request_rec *r, logsql_dbconnection *db, create_sql = apr_pstrcat(r->pool, create_prefix, table_name, create_suffix, type_suffix, NULL); - log_error(APLOG_MARK,APLOG_DEBUG,r->server,"create string: %s", create_sql); + log_error(APLOG_MARK,APLOG_DEBUG,0, r->server,"create string: %s", create_sql); if (!dblink) { return LOGSQL_QUERY_NOLINK; @@ -223,7 +223,7 @@ logsql_table_ret log_sql_mysql_create(request_rec *r, logsql_dbconnection *db, /* Run the create query */ if ((retval = mysql_query(dblink, create_sql))) { - log_error(APLOG_MARK,APLOG_ERR,r->server,"failed to create table: %s", + log_error(APLOG_MARK,APLOG_ERR,0, r->server,"failed to create table: %s", table_name); signal(SIGPIPE, handler); return LOGSQL_TABLE_FAIL; diff --git a/mod_log_sql_ssl.c b/mod_log_sql_ssl.c index d65ca79..5f3a16e 100644 --- a/mod_log_sql_ssl.c +++ b/mod_log_sql_ssl.c @@ -37,7 +37,7 @@ static const char *extract_ssl_keysize(request_rec *r, char *a) if (TEST_SSL(r) != NULL) { result = ssl_var_lookup(r->pool, r->server, r->connection, r, "SSL_CIPHER_USEKEYSIZE"); - log_error(APLOG_MARK,APLOG_DEBUG,r->server,"SSL_KEYSIZE: %s", result); + log_error(APLOG_MARK,APLOG_DEBUG,0, r->server,"SSL_KEYSIZE: %s", result); if (result != NULL && result[0] == '\0') result = NULL; return result; @@ -52,7 +52,7 @@ static const char *extract_ssl_maxkeysize(request_rec *r, char *a) if (TEST_SSL(r) != NULL) { result = ssl_var_lookup(r->pool, r->server, r->connection, r, "SSL_CIPHER_ALGKEYSIZE"); - log_error(APLOG_MARK,APLOG_DEBUG,r->server,"SSL_ALGKEYSIZE: %s", result); + log_error(APLOG_MARK,APLOG_DEBUG,0, r->server,"SSL_ALGKEYSIZE: %s", result); if (result != NULL && result[0] == '\0') result = NULL; return result; @@ -67,7 +67,7 @@ static const char *extract_ssl_cipher(request_rec *r, char *a) if (TEST_SSL(r) != NULL) { result = ssl_var_lookup(r->pool, r->server, r->connection, r, "SSL_CIPHER"); - log_error(APLOG_MARK,APLOG_DEBUG,r->server,"SSL_CIPHER: %s", result); + log_error(APLOG_MARK,APLOG_DEBUG,0, r->server,"SSL_CIPHER: %s", result); if (result != NULL && result[0] == '\0') result = NULL; return result; -- cgit