summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2022-01-12 01:12:01 +0800
committerꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2022-01-12 01:12:01 +0800
commitcc6eddd99abebd2501e901b98d40481aaba88e10 (patch)
tree39225f060f91cbf15bfb51ca563451c3bd6ea7c0
parent6974bf5dd6a200ea746eba15d363cea6026de179 (diff)
parent6dda605e56ab1c5c125e957c60607ad4fb128ae6 (diff)
Merge branch 'master' into sicepat
-rw-r--r--Makefile.PL9
-rw-r--r--pikul.c14
2 files changed, 16 insertions, 7 deletions
diff --git a/Makefile.PL b/Makefile.PL
index 2344c9c..bb441c3 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -1,7 +1,8 @@
use ExtUtils::MakeMaker;
WriteMakefile(
- NAME => 'Pikul',
- INC => '`pkg-config --cflags json-c`',
- LIBS => ['-lpikul -lcurl -ljson-c'],
- OBJECT => '$(O_FILES)'
+ NAME => 'Pikul',
+ INC => '`pkg-config --cflags json-c`',
+ LIBS => ['-lpikul -lcurl -ljson-c'],
+ OBJECT => '$(O_FILES)',
+ DEFINE => '-DLOG_PATH=\"/var/log/pikul.log\"'
);
diff --git a/pikul.c b/pikul.c
index 4cfe937..f3710f8 100644
--- a/pikul.c
+++ b/pikul.c
@@ -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>
@@ -41,9 +42,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;