diff options
author | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2022-01-12 01:11:46 +0800 |
---|---|---|
committer | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2022-01-12 01:11:46 +0800 |
commit | 6dda605e56ab1c5c125e957c60607ad4fb128ae6 (patch) | |
tree | 8880ea2f9950d8f8158793dee04d204475270821 /pikul.c | |
parent | d63004317fa73c1a9cf25958c42b73d4b16f16b0 (diff) |
Perl version can log to a file
Diffstat (limited to 'pikul.c')
-rw-r--r-- | pikul.c | 14 |
1 files changed, 11 insertions, 3 deletions
@@ -1,5 +1,6 @@ -#ifdef DEBUG +#if defined DEBUG || defined LOG_PATH #include <stdio.h> +#include <time.h> #endif #include <string.h> #include <stdbool.h> @@ -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); |