Skip to content
This repository has been archived by the owner on Jul 13, 2021. It is now read-only.

Added request logging #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
19 changes: 19 additions & 0 deletions http.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
20 changes: 20 additions & 0 deletions log.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ THE SOFTWARE.
*/

#include "polipo.h"
#include <time.h>

#ifdef HAVE_SYSLOG
#include <syslog.h>
Expand Down Expand Up @@ -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)
{
Expand Down
6 changes: 6 additions & 0 deletions log.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)) \
Expand Down