From 685eb14be940f5001ffaa5b658e55419ffb47469 Mon Sep 17 00:00:00 2001 From: Heinrich Hartmann Date: Fri, 5 Sep 2014 22:44:05 +0200 Subject: [PATCH] Added request logging. --- client.c | 2 ++ http.c | 19 +++++++++++++++++++ log.c | 20 ++++++++++++++++++++ log.h | 6 ++++++ 4 files changed, 47 insertions(+) diff --git a/client.c b/client.c index b68282fc..d9ba1c5a 100644 --- a/client.c +++ b/client.c @@ -735,6 +735,8 @@ httpClientRequest(HTTPRequestPtr request, AtomPtr url) return 1; } + do_log_time(L_INFO, "%s - %s\n", method2str(request->method), url->string); + connection->reqbegin = i; if(body_len < 0) { diff --git a/http.c b/http.c index 31ee1216..2f05f545 100644 --- a/http.c +++ b/http.c @@ -1092,3 +1092,22 @@ httpHeaderMatch(AtomPtr header, AtomPtr headers1, AtomPtr headers2) return 1; } + +char * +method2str(int method){ + if (method == METHOD_GET) { + return "GET"; + } else if (method == METHOD_HEAD) { + return "GET"; + } else if (method == METHOD_CONDITIONAL_GET) { + return "CONDITIONAL_GET"; + } else if (method == METHOD_CONNECT) { + return "CONNECT"; + } else if (method == METHOD_POST) { + return "POST"; + } else if (method == METHOD_PUT) { + return "PUT"; + } else { + return "NONE"; + } +} diff --git a/log.c b/log.c index 1cf2eca7..5bb3dcd8 100644 --- a/log.c +++ b/log.c @@ -21,6 +21,7 @@ THE SOFTWARE. */ #include "polipo.h" +#include #ifdef HAVE_SYSLOG #include @@ -399,6 +400,25 @@ really_do_log(int type, const char *f, ...) va_end(args); } +void +really_do_log_time(int type, const char *f, ...) +{ + time_t rawtime; + struct tm * timeinfo; + time (&rawtime); + timeinfo = localtime (&rawtime); + + char out[19 + 3 + strlen(f) + 1]; + + strftime(out, sizeof(char) * 23, "%Y-%m-%d %H:%M:%S - ", timeinfo); + strcat(out, f); + + va_list args; + va_start(args, f); + really_do_log_v(type, out, args); + va_end(args); +} + void really_do_log_v(int type, const char *f, va_list args) { diff --git a/log.h b/log.h index 40d15fdd..84898558 100644 --- a/log.h +++ b/log.h @@ -57,6 +57,8 @@ int loggingToStderr(void); void really_do_log(int type, const char *f, ...) ATTRIBUTE ((format (printf, 2, 3))); +void really_do_log_time(int type, const char *f, ...) + ATTRIBUTE ((format (printf, 2, 3))); void really_do_log_v(int type, const char *f, va_list args) ATTRIBUTE ((format (printf, 2, 0))); void really_do_log_n(int type, const char *s, int n); @@ -100,6 +102,10 @@ const char *scrub(const char *message); do { \ if((_type) & (LOGGING_MAX)) really_do_log((_type), _args); \ } while(0) +#define do_log_time(_type, _args...) \ + do { \ + if((_type) & (LOGGING_MAX)) really_do_log_time((_type), _args); \ + } while(0) #define do_log_error(_type, _e, _args...) \ do { \ if((_type) & (LOGGING_MAX)) \