html.h html.c\
http.h http.c\
list.h list.c\
- log.h log.c\
lp.h lp.c\
lp_json.h lp_json.c\
lp_ws.h lp_ws.c\
main.c\
+ plog.h plog.c\
ppastats.h ppastats.c\
pio.h pio.c\
- pstr.h pstr.c
+ pstr.h pstr.c\
+ ptime.h ptime.c
dist_man_MANS = ppastats.1
am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man1dir)"
PROGRAMS = $(bin_PROGRAMS)
am_ppastats_OBJECTS = cache.$(OBJEXT) fcache.$(OBJEXT) html.$(OBJEXT) \
- http.$(OBJEXT) list.$(OBJEXT) log.$(OBJEXT) lp.$(OBJEXT) \
- lp_json.$(OBJEXT) lp_ws.$(OBJEXT) main.$(OBJEXT) \
- ppastats.$(OBJEXT) pio.$(OBJEXT) pstr.$(OBJEXT)
+ http.$(OBJEXT) list.$(OBJEXT) lp.$(OBJEXT) lp_json.$(OBJEXT) \
+ lp_ws.$(OBJEXT) main.$(OBJEXT) plog.$(OBJEXT) \
+ ppastats.$(OBJEXT) pio.$(OBJEXT) pstr.$(OBJEXT) \
+ ptime.$(OBJEXT)
ppastats_OBJECTS = $(am_ppastats_OBJECTS)
ppastats_LDADD = $(LDADD)
AM_V_P = $(am__v_P_@AM_V@)
html.h html.c\
http.h http.c\
list.h list.c\
- log.h log.c\
lp.h lp.c\
lp_json.h lp_json.c\
lp_ws.h lp_ws.c\
main.c\
+ plog.h plog.c\
ppastats.h ppastats.c\
pio.h pio.c\
- pstr.h pstr.c
+ pstr.h pstr.c\
+ ptime.h ptime.c
dist_man_MANS = ppastats.1
all: all-am
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/html.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/http.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/list.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/log.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lp.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lp_json.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lp_ws.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pio.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plog.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ppastats.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pstr.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ptime.Po@am__quote@
.c.o:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
#include <string.h>
#include "cache.h"
-#include "log.h"
+#include <plog.h>
#include "ppastats.h"
#include <string.h>
#include "fcache.h"
-#include "log.h"
+#include <plog.h>
#include <pio.h>
static const char *cache_dir;
#include <json.h>
#include "html.h"
-#include "log.h"
#include "lp.h"
#include <lp_json.h>
#include "lp_ws.h"
#include "ppastats.h"
#include <pio.h>
+#include <plog.h>
#include <pstr.h>
static const char *footer;
#include "fcache.h"
#include "http.h"
-#include "log.h"
+#include <plog.h>
static const int DEFAULT_FETCH_RETRIES = 10;
+++ /dev/null
-/*
- * Copyright (C) 2010-2014 jeanfi@gmail.com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA
- */
-#include <locale.h>
-#include <libintl.h>
-#define _(str) gettext(str)
-
-#include <stdarg.h>
-#include <stdio.h>
-#include <sys/time.h>
-
-#include "log.h"
-
-static FILE *file;
-int log_level = LOG_WARN;
-
-void log_open(const char *path)
-{
- file = fopen(path, "a");
-
- if (!file)
- log_printf(LOG_ERR, _("Cannot open log file: %s"), path);
-}
-
-void log_close()
-{
- if (!file)
- return ;
-
- fclose(file);
-
- file = NULL;
-}
-
-
-#define LOG_BUFFER 4096
-static void vlogf(int lvl, const char *fmt, va_list ap)
-{
- struct timeval tv;
- char buffer[1 + LOG_BUFFER];
- char *lvl_str;
- FILE *stdf;
-
- if (lvl > log_level)
- return ;
-
- vsnprintf(buffer, LOG_BUFFER, fmt, ap);
- buffer[LOG_BUFFER] = '\0';
-
- if (gettimeofday(&tv, NULL) != 0)
- timerclear(&tv);
-
- switch (lvl) {
- case LOG_WARN:
- lvl_str = "[WARN]";
- break;
- case LOG_ERR:
- lvl_str = "[ERR]";
- break;
- case LOG_DEBUG:
- lvl_str = "[DEBUG]";
- break;
- case LOG_INFO:
- lvl_str = "[INFO]";
- break;
- default:
- lvl_str = "[??]";
- }
-
- if (file) {
- fprintf(file, "[%ld] %s %s\n", tv.tv_sec, lvl_str, buffer);
- fflush(file);
- }
-
- if (lvl == LOG_WARN || lvl == LOG_ERR)
- stdf = stderr;
- else
- stdf = stdout;
-
- fprintf(stdf, "[%ld] %s %s\n", tv.tv_sec, lvl_str, buffer);
- fflush(stdf);
-}
-
-void log_printf(int lvl, const char *fmt, ...)
-{
- va_list ap;
-
- va_start(ap, fmt);
- vlogf(lvl, fmt, ap);
- va_end(ap);
-}
-
-void log_debug(const char *fmt, ...)
-{
- va_list ap;
-
- if (log_level < LOG_DEBUG)
- return ;
-
- va_start(ap, fmt);
- vlogf(LOG_DEBUG, fmt, ap);
- va_end(ap);
-}
-
-void log_err(const char *fmt, ...)
-{
- va_list ap;
-
- va_start(ap, fmt);
- vlogf(LOG_ERR, fmt, ap);
- va_end(ap);
-}
-
-void log_warn(const char *fmt, ...)
-{
- va_list ap;
-
- va_start(ap, fmt);
- vlogf(LOG_WARN, fmt, ap);
- va_end(ap);
-}
+++ /dev/null
-/*
- * Copyright (C) 2010-2014 jeanfi@gmail.com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA
- */
-#ifndef _PPASTATS_LOG_H_
-#define _PPASTATS_LOG_H_
-
-enum log_level {
- LOG_ERR ,
- LOG_WARN,
- LOG_INFO,
- LOG_DEBUG
-};
-
-void log_open(const char *path);
-
-void log_printf(int lvl, const char *fmt, ...);
-void log_debug(const char *fmt, ...);
-void log_err(const char *fmt, ...);
-void log_warn(const char *fmt, ...);
-
-void log_close();
-
-/* level of the log file. */
-extern int log_level;
-
-#endif
#include "list.h"
#include "lp.h"
-
-char *time_to_str(time_t t)
-{
- char *str;
- struct tm *tm;
- size_t ret;
-
- tm = localtime(&t);
-
- if (!tm)
- return NULL;
-
- str = malloc(strlen("YYYY-MM-DDThh:mm:ss") + 1);
- ret = strftime(str, strlen("YYYY-MM-DDThh:mm:ss") + 1, "%FT%T", tm);
-
- if (ret)
- return str;
-
- free(str);
- return NULL;
-}
+#include <ptime.h>
struct distro_series *distro_series_new(const char *name,
const char *version,
char *get_archive_url(const char *owner, const char *ppa);
-char *time_to_str(time_t t);
-
time_t ddts_get_last_date(struct daily_download_total **);
struct daily_download_total **
#include "lp_json.h"
#include "lp_ws.h"
+#include <ptime.h>
static time_t json_to_time(json_object *json)
{
{
char *str;
- str = time_to_str(t);
+ str = time_to_str(&t);
if (str)
return json_object_new_string(str);
#include "fcache.h"
#include "http.h"
#include "list.h"
-#include "log.h"
#include "lp_ws.h"
#include "lp_json.h"
+#include <plog.h>
#include "ppastats.h"
+#include <ptime.h>
/** Default ws.size value for the getPublishedBinaries request. */
static const int DEFAULT_WS_SIZE = 150;
}
if (last)
- return time_to_str(last);
+ return time_to_str(&last);
else
return NULL;
}
#include "cache.h"
#include "html.h"
#include "http.h"
-#include "log.h"
#include "lp_ws.h"
#include "config.h"
+#include <plog.h>
#include "ppastats.h"
static const char *program_name;
exit(EXIT_FAILURE);
}
+ log_open("ppastats.log");
+
owner = argv[optind];
ppa = argv[optind+1];
--- /dev/null
+/*
+ * Copyright (C) 2010-2014 jeanfi@gmail.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+#define _LARGEFILE_SOURCE 1
+#include "config.h"
+
+#include <locale.h>
+#include <libintl.h>
+#define _(str) gettext(str)
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <time.h>
+
+#include <plog.h>
+#include <ptime.h>
+
+static FILE *file;
+int log_level = LOG_WARN;
+
+void log_open(const char *path)
+{
+ file = fopen(path, "a");
+
+ if (!file)
+ log_printf(LOG_ERR, _("Cannot open log file: %s"), path);
+}
+
+void log_close()
+{
+ if (!file)
+ return ;
+
+ fclose(file);
+
+ file = NULL;
+}
+
+
+#define LOG_BUFFER 4096
+static void vlogf(int lvl, const char *fmt, va_list ap)
+{
+ char buffer[1 + LOG_BUFFER];
+ char *lvl_str, *t;
+ FILE *stdf;
+
+ if (lvl > LOG_INFO && (!file || lvl > log_level))
+ return ;
+
+ vsnprintf(buffer, LOG_BUFFER, fmt, ap);
+ buffer[LOG_BUFFER] = '\0';
+
+ switch (lvl) {
+ case LOG_WARN:
+ lvl_str = "[WARN]";
+ break;
+ case LOG_ERR:
+ lvl_str = "[ERR]";
+ break;
+ case LOG_DEBUG:
+ lvl_str = "[DEBUG]";
+ break;
+ case LOG_INFO:
+ lvl_str = "[INFO]";
+ break;
+ default:
+ lvl_str = "[??]";
+ }
+
+ t = get_current_time_str();
+ if (!t)
+ return ;
+
+ if (file && lvl <= log_level) {
+ fprintf(file, "[%s] %s %s\n", t, lvl_str, buffer);
+ fflush(file);
+ } else {
+ t = NULL;
+ }
+
+ if (lvl <= LOG_INFO) {
+ if (lvl == LOG_WARN || lvl == LOG_ERR)
+ stdf = stderr;
+ else
+ stdf = stdout;
+
+
+ fprintf(stdf, "[%s] %s %s\n", t, lvl_str, buffer);
+ }
+
+ free(t);
+}
+
+void log_printf(int lvl, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ vlogf(lvl, fmt, ap);
+ va_end(ap);
+}
+
+void log_debug(const char *fmt, ...)
+{
+ va_list ap;
+
+ if (log_level < LOG_DEBUG)
+ return ;
+
+ va_start(ap, fmt);
+ vlogf(LOG_DEBUG, fmt, ap);
+ va_end(ap);
+}
+
+void log_err(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ vlogf(LOG_ERR, fmt, ap);
+ va_end(ap);
+}
+
+void log_warn(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ vlogf(LOG_WARN, fmt, ap);
+ va_end(ap);
+}
+
+void log_info(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ vlogf(LOG_INFO, fmt, ap);
+ va_end(ap);
+}
--- /dev/null
+/*
+ Copyright (C) 2010-2014 jeanfi@gmail.com
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301 USA
+ */
+#ifndef _P_LOG_H_
+#define _P_LOG_H_
+
+#define P_LOG_VER 1
+
+enum log_level {
+ LOG_ERR ,
+ LOG_WARN,
+ LOG_INFO,
+ LOG_DEBUG
+};
+
+void log_open(const char *path);
+
+void log_printf(int lvl, const char *fmt, ...);
+void log_debug(const char *fmt, ...);
+void log_err(const char *fmt, ...);
+void log_info(const char *fmt, ...);
+void log_warn(const char *fmt, ...);
+
+void log_close();
+
+/* level of the log file. */
+extern int log_level;
+
+#endif
#include <string.h>
#include "list.h"
-#include "log.h"
#include "lp_ws.h"
+#include <plog.h>
#include "ppastats.h"
static struct package_stats *get_package_stats(struct ppa_stats *stats,
--- /dev/null
+/*
+ * Copyright (C) 2010-2014 jeanfi@gmail.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+#include <stdlib.h>
+#include <string.h>
+
+#include <ptime.h>
+
+static int ISO8601_TIME_LENGTH = 219; /* YYYY-MM-DDThh:mm:ss */
+
+char *time_to_str(time_t *t)
+{
+ struct tm lt;
+ char *str;
+
+ memset(<, 0, sizeof(struct tm));
+ if (!localtime_r(t, <))
+ return NULL;
+
+ str = malloc(ISO8601_TIME_LENGTH);
+
+ if (strftime(str, ISO8601_TIME_LENGTH, "%FT%T", <)) {
+ return str;
+ } else {
+ free(str);
+ return NULL;
+ }
+}
+
+char *get_current_time_str()
+{
+ time_t t;
+
+ t = time(NULL);
+ return time_to_str(&t);
+}
--- /dev/null
+/*
+ * Copyright (C) 2010-2014 jeanfi@gmail.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+#ifndef _P_TIME_H
+#define _P_TIME_H
+
+#define P_TIME_VER 1
+
+#include <time.h>
+
+char *get_current_time_str();
+char *time_to_str(time_t *t);
+
+#endif