$(DISTFILES.extra1) $(DISTFILES.extra2) $(DISTFILES.extra3)
POTFILES = \
+ ../src/log.c \
../src/main.c
CATALOGS = fr.gmo
+ ../src/log.c \
../src/main.c
msgstr ""
"Project-Id-Version: ptask\n"
"Report-Msgid-Bugs-To: jeanfi@gmail.com\n"
-"POT-Creation-Date: 2013-04-25 09:29+0200\n"
+"POT-Creation-Date: 2013-04-25 15:45+0200\n"
"PO-Revision-Date: 2012-05-13 18:15+0000\n"
"Last-Translator: jeanfi <Unknown>\n"
"Language-Team: French <>\n"
"X-Launchpad-Export-Date: 2012-07-02 08:28+0000\n"
"X-Generator: Launchpad (build 15520)\n"
+#: src/log.c:37
+#, c-format
+msgid "Cannot open log file: %s"
+msgstr ""
+
#: src/main.c:57
#, c-format
msgid ""
msgid "%s home page: <%s>\n"
msgstr ""
-#: src/main.c:391
+#: src/main.c:393
#, c-format
msgid "Try `%s --help' for more information.\n"
msgstr ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: jeanfi@gmail.com\n"
-"POT-Creation-Date: 2013-04-25 09:29+0200\n"
+"POT-Creation-Date: 2013-04-25 15:45+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
+#: src/log.c:37
+#, c-format
+msgid "Cannot open log file: %s"
+msgstr ""
+
#: src/main.c:57
#, c-format
msgid ""
msgid "%s home page: <%s>\n"
msgstr ""
-#: src/main.c:391
+#: src/main.c:393
#, c-format
msgid "Try `%s --help' for more information.\n"
msgstr ""
http.h \
io.c \
io.h \
+ log.c \
+ log.h \
ttrss.c \
ttrss.h \
ttrss_model.c \
am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man1dir)"
PROGRAMS = $(bin_PROGRAMS)
am_prss_OBJECTS = main.$(OBJEXT) http.$(OBJEXT) io.$(OBJEXT) \
- ttrss.$(OBJEXT) ttrss_model.$(OBJEXT) ttrss_ws.$(OBJEXT) \
- url.$(OBJEXT) webbrowser.$(OBJEXT)
+ log.$(OBJEXT) ttrss.$(OBJEXT) ttrss_model.$(OBJEXT) \
+ ttrss_ws.$(OBJEXT) url.$(OBJEXT) webbrowser.$(OBJEXT)
prss_OBJECTS = $(am_prss_OBJECTS)
prss_LDADD = $(LDADD)
DEFAULT_INCLUDES = -I.@am__isrc@
http.h \
io.c \
io.h \
+ log.c \
+ log.h \
ttrss.c \
ttrss.h \
ttrss_model.c \
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/http.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/io.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/log.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ttrss.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ttrss_model.Po@am__quote@
<object class="GtkEntry" id="password_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
+ <property name="visibility">False</property>
<property name="invisible_char">•</property>
</object>
<packing>
#include <curl/curl.h>
#include "http.h"
-
-static int debug;
+#include "log.h"
struct ucontent {
char *data;
return chunk.data;
free(chunk.data);
- fprintf(stderr, _("HTTP request fail url=%s"), url);
+ log_err(_("HTTP request fail url=%s"), url);
return NULL;
}
char *out;
struct json_object *result;
+ if (log_level >= LOG_DEBUG)
+ log_debug("HTTP request= %s",
+ json_object_to_json_string(j));
+
in = json_object_to_json_string(j);
out = http_get(url, in);
- if (debug)
- printf("HTTP request= %s\n",
- json_object_to_json_string(j));
-
if (out) {
result = json_tokener_parse(out);
- if (debug)
- printf("HTTP reply= %s\n", out);
+
+ if (log_level >= LOG_DEBUG)
+ log_debug("HTTP reply= %s", out);
+
free(out);
return result;
}
--- /dev/null
+/*
+ * Copyright (C) 2010-2013 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 128
+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_INFO && (!file || 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 && lvl <= log_level) {
+ fprintf(file,
+ "[%ld.%06ld] %s %s\n",
+ tv.tv_sec,
+ tv.tv_usec,
+ lvl_str,
+ buffer);
+ fflush(file);
+ }
+
+ if (lvl <= LOG_INFO) {
+ if (lvl == LOG_WARN || lvl == LOG_ERR)
+ stdf = stderr;
+ else
+ stdf = stdout;
+
+ fprintf(stdf,
+ "[%ld.%06ld] %s %s\n",
+ tv.tv_sec,
+ tv.tv_usec,
+ lvl_str,
+ buffer);
+ }
+}
+
+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-2013 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 _PRSS_LOG_H_
+#define _PRSS_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_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 <getopt.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
#include <json/json.h>
#include <webkit/webkit.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include "http.h"
+#include "log.h"
#include "ttrss.h"
+#include "ttrss_ws.h"
#include "webbrowser.h"
static const char *program_name;
static struct option long_options[] = {
{"version", no_argument, 0, 'v'},
{"help", no_argument, 0, 'h'},
+ {"debug", required_argument, 0, 'd'},
{0, 0, 0, 0}
};
puts(_("Options:"));
puts(_(" -h, --help display this help and exit\n"
" -v, --version display version information and exit"));
+ puts("");
+ puts(_(" -d, --debug=LEVEL "
+ "set the debug level, integer between 0 and 3"));
puts("");
model = gtk_tree_view_get_model(GTK_TREE_VIEW(w_feedtree));
- printf("update(): clear feed tree\n");
+ log_debug("update(): clear feed tree.");
model_state = 1;
gtk_list_store_clear(GTK_LIST_STORE(model));
headlinemodel = gtk_tree_view_get_model(w_headlinetree);
gtk_list_store_clear(GTK_LIST_STORE(headlinemodel));
- printf("update(): clear feed tree done\n");
+ log_debug("update(): clear feed tree done.");
feeds = ttrss_get_feeds();
while (feeds && *feeds) {
if ((*feeds)->unread)
}
model_state = 0;
- printf("refresh done\n");
+ log_debug("update() done");
}
void refresh_clicked_cbk(GtkWidget *btn, gpointer data)
{
- printf("refresh_clicked_cbk\n");
+ log_debug("refresh_clicked_cbk()");
update();
+ log_debug("refresh_clicked_cbk() done");
}
void settings_activate_cbk(GtkWidget *menu_item, gpointer data)
GtkBuilder *builder;
GtkEntry *login, *url, *pwd;
- printf("settings_activate_cbk\n");
+ log_debug("settings_activate_cbk()");
builder = gtk_builder_new();
"user",
gtk_entry_get_text(login));
+ ttrss_set_config(g_settings_get_string(settings, "url"),
+ g_settings_get_string(settings, "user"),
+ g_settings_get_string(settings, "password"));
+ ws_open_session();
+
update();
}
if (model_state)
return TRUE;
- printf("feed_cursor_changed_cbk\n");
+ log_debug("feed_cursor_changed_cbk()");
feed = get_selected_feed();
struct headline *headline;
char *str;
- printf("headline_cursor_changed_cbk\n");
+ log_debug("headline_cursor_changed_cbk()");
if (model_state)
return TRUE;
0, headline->title,
-1);
} else {
- printf("headline not found\n");
+ log_debug("headline not found");
}
return TRUE;
const char *url;
int id;
- printf("headline_row_activated_cbk\n");
+ printf("headline_row_activated_cbk()");
selection = gtk_tree_view_get_selection(w_headlinetree);
model = gtk_tree_view_get_model(w_headlinetree);
gboolean
window_delete_event_cbk(GtkWidget *widget, GdkEvent *event, gpointer data)
{
- printf("window_delete_event_cbk\n");
+ log_debug("window_delete_event_cbk");
gtk_main_quit();
return TRUE;
}
+static void log_init()
+{
+ char *home, *path, *dir;
+
+ home = getenv("HOME");
+
+ if (!home)
+ return ;
+
+ dir = malloc(strlen(home)+1+strlen(".prss")+1);
+ sprintf(dir, "%s/%s", home, ".prss");
+ mkdir(dir, 0777);
+
+ path = malloc(strlen(dir)+1+strlen("log")+1);
+ sprintf(path, "%s/%s", dir, "log");
+
+ log_open(path);
+
+ free(dir);
+ free(path);
+}
+
int main(int argc, char **argv)
{
GtkWidget *window, *panh;
#endif
cmdok = 1;
- while ((optc = getopt_long(argc, argv, "vh", long_options,
+ while ((optc = getopt_long(argc, argv, "vhd:", long_options,
&opti)) != -1) {
switch (optc) {
+ case 'd':
+ log_level = atoi(optarg);
+ log_info(_("Enables debug mode."));
+ break;
case 'h':
print_help();
exit(EXIT_SUCCESS);
exit(EXIT_FAILURE);
}
+ log_init();
+
http_init();
gtk_init(NULL, NULL);
#include "http.h"
#include "io.h"
+#include "log.h"
#include "ttrss_ws.h"
#include "url.h"
cache_dir = get_cache_dir();
if (cache_dir) {
path = g_strdup_printf("%s/%d", cache_dir, h->id);
-
+
content = file_get_content(path);
-
+
if (!content) {
content = ws_get_article_content(h->id);
file_set_content(path, content);
g_free(path);
return content;
- }
+ }
return NULL;
}
{
struct json_object *rp, *rq;
- printf("ttrss_set_article_unread %d %d\n", id, unread);
+ log_debug("ttrss_set_article_unread(%d,%d)", id, unread);
rq = ws_request_new("updateArticle");
json_object_object_add(rq, "article_ids", json_object_new_int(id));
struct headline *ttrss_get_headline(int id);
void ttrs_set_config(const char *url, const char *user, const char *pwd);
-int ws_open_session();
#endif
{
struct feed **cur;
- printf("%p\n", feeds);
-
if (feeds)
for (cur = feeds; *cur; cur++)
- if ((*cur)->id == id) {
- printf("match!\n");
+ if ((*cur)->id == id)
return *cur;
- }
return NULL;
}
#include <json/json.h>
#include "http.h"
+#include "log.h"
#include "ttrss_ws.h"
#include "url.h"
rp = ws_execute(rq);
json_object_put(rq);
+ str = NULL;
if (rp) {
j = json_object_object_get(rp, "session_id");
- str = strdup(json_object_get_string(j));
+
+ if (j)
+ str = strdup(json_object_get_string(j));
json_object_put(rp);
- } else {
- str = NULL;
- }
+ }
return str;
}
if (session_id) {
version = ws_get_api_version();
- printf("API version: %d\n", version);
+ log_debug("API version= %d", version);
if (version > 0) {
result = 1;
struct feed *feed, **tmp;
const char *title, *url;
- printf("ttrss_get_feeds\n");
+ log_debug("ttrss_get_feeds()");
rq = ws_request_new("getFeeds");
tmp = feeds_add(feeds, feed);
free(feeds);
feeds = tmp;
- } else {
- printf("found!\n");
}
j = json_object_object_get(jfeed, "unread");
json_object_put(rp);
- printf("ttrss_get_feeds ended\n");
+ log_debug("ttrss_get_feeds() done");
return feeds;
}
#include "ttrss.h"
void ws_init(const char *url, const char *user, const char *pwd);
+int ws_open_session();
struct json_object *ws_request_new(const char *op);
struct json_object *ws_execute(struct json_object *rq);