From 6dda605e56ab1c5c125e957c60607ad4fb128ae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=EA=A6=AB=EA=A6=B6=EA=A6=8F=EA=A7=80=EA=A6=A6?= =?UTF-8?q?=EA=A6=BF=EA=A6=A7=EA=A6=AE=EA=A6=91=EA=A6=A9=EA=A6=AD=EA=A7=80?= Date: Wed, 12 Jan 2022 01:11:46 +0800 Subject: Perl version can log to a file --- pikul.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'pikul.c') diff --git a/pikul.c b/pikul.c index c967c90..00d1284 100644 --- a/pikul.c +++ b/pikul.c @@ -1,5 +1,6 @@ -#ifdef DEBUG +#if defined DEBUG || defined LOG_PATH #include +#include #endif #include #include @@ -36,9 +37,16 @@ static void recurse(struct json_object *outer, const char *trail[], struct json_ static size_t handle(char *contents, size_t size, size_t nmemb, struct shipping *shipping) { size_t realsize = size * nmemb; -#ifdef DEBUG +#if defined DEBUG || defined LOG_PATH contents[realsize] = '\0'; - fprintf(stderr, "%s\n", contents); + time_t now = time(NULL); +#ifdef LOG_PATH + FILE *log = fopen(LOG_PATH, "a"); + fprintf(log, "%s%s\n", ctime(&now), contents); + fclose(log); +#else + fprintf(stderr, "%s%s\n", ctime(&now), contents); +#endif #endif json_tokener *tokener = shipping->tokener; json_object *response = json_tokener_parse_ex(tokener, contents, realsize); -- cgit v1.2.3