top_srcdir = ..
-prefix = /usr/local
+prefix = /tmp/r
exec_prefix = ${prefix}
datarootdir = ${prefix}/share
datadir = ${datarootdir}
{
file = fopen(path, "a");
- if (file)
- log_printf(LOG_INFO, "Start logging");
- else
+ if (!file)
log_printf(LOG_ERR, _("Cannot open log file: %s"), path);
}
file = NULL;
}
+
#define LOG_BUFFER 4096
-void log_printf(int lvl, const char *fmt, ...)
+static void vlogf(int lvl, const char *fmt, va_list ap)
{
struct timeval tv;
char buffer[1 + LOG_BUFFER];
- va_list ap;
char *lvl_str;
FILE *stdf;
if (lvl > LOG_INFO && (!file || lvl > log_level))
return ;
- va_start(ap, fmt);
vsnprintf(buffer, LOG_BUFFER, fmt, ap);
buffer[LOG_BUFFER] = '\0';
- va_end(ap);
if (gettimeofday(&tv, NULL) != 0)
timerclear(&tv);
fprintf(stdf, "[%ld] %s %s\n", tv.tv_sec, 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_open(const char *path);
void log_printf(int lvl, const char *fmt, ...);
+void log_debug(const char *fmt, ...);
void log_close();
{
if (log_level == LOG_DEBUG)
while (*sensors) {
- log_printf(LOG_DEBUG, "Measure: %s %.2f",
+ log_debug("Measure: %s %.2f",
(*sensors)->name,
psensor_get_current_value(*sensors));
{
struct ui_psensor *ui;
- log_printf(LOG_DEBUG, "initial_window_show()");
+ log_debug("initial_window_show()");
ui = (struct ui_psensor *)data;
- log_printf(LOG_DEBUG,
- "is_status_supported: %d", is_status_supported());
- log_printf(LOG_DEBUG,
- "is_appindicator_supported: %d", is_appindicator_supported());
- log_printf(LOG_DEBUG,
- "hide_on_startup: %d", ui->config->hide_on_startup);
+ log_debug("is_status_supported: %d", is_status_supported());
+ log_debug("is_appindicator_supported: %d",
+ is_appindicator_supported());
+ log_debug("hide_on_startup: %d", ui->config->hide_on_startup);
if (!ui->config->hide_on_startup
|| (!is_appindicator_supported() && !is_status_supported()))
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, cbk_curl);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
- log_printf(LOG_DEBUG, "HTTP request %s", url);
+ log_debug("HTTP request %s", url);
if (curl_easy_perform(curl) == CURLE_OK)
obj = json_tokener_parse(chunk.data);
else
struct config *cfg;
visible = gtk_widget_get_visible(ui->main_window);
- log_printf(LOG_DEBUG, "Window visible: %d", visible);
+ log_debug("Window visible: %d", visible);
if (visible == TRUE) {
cfg = ui->config;
win = GTK_WINDOW(ui->main_window);
gtk_window_get_position(win, &cfg->window_x, &cfg->window_y);
- log_printf(LOG_DEBUG,
- "Window position: %d %d",
- cfg->window_x,
- cfg->window_y);
+ log_debug("Window position: %d %d",
+ cfg->window_x,
+ cfg->window_y);
gtk_window_get_size(win,
&cfg->window_w,
&cfg->window_h);
- log_printf(LOG_DEBUG,
- "Window size: %d %d",
- cfg->window_w,
- cfg->window_h);
+ log_debug("Window size: %d %d", cfg->window_w, cfg->window_h);
cfg->window_divider_pos
= gtk_paned_get_position(GTK_PANED(ui->sensor_box));
save_window_pos(ui);
- log_printf(LOG_DEBUG,
- "is_status_supported: %d\n", is_status_supported());
+ log_debug("is_status_supported: %d\n", is_status_supported());
if (is_appindicator_supported() || is_status_supported())
gtk_widget_hide(ui->main_window);
{
save_window_pos(ui);
- log_printf(LOG_DEBUG, "Destroy main window");
+ log_debug("Destroy main window");
gtk_widget_destroy(ui->main_window);
gtk_main_quit();
}
void ui_window_show(struct ui_psensor *ui)
{
- log_printf(LOG_DEBUG, "ui_window_show()");
+ log_debug("ui_window_show()");
gtk_window_present(GTK_WINDOW(ui->main_window));
}
static GtkStatusIcon *unity_fallback(AppIndicator *indicator)
{
- log_printf(LOG_DEBUG, "ui_appindicator#unity_fallback");
+ log_debug("ui_appindicator#unity_fallback");
appindicator_supported = 0;
static void
unity_unfallback(AppIndicator *indicator, GtkStatusIcon *status_icon)
{
- log_printf(LOG_DEBUG, "ui_appindicator#unity_unfallback");
+ log_debug("ui_appindicator#unity_unfallback");
appindicator_supported = 1;
}
char *name;
NotifyNotification *notif;
- log_printf(LOG_DEBUG,
- "ui_notify() last_notification %d",
- last_notification_tv.tv_sec);
+ log_debug("last_notification %d", last_notification_tv.tv_sec);
if (gettimeofday(&t, NULL) != 0) {
log_printf(LOG_ERR, _("gettimeofday failed"));
NULL,
GTK_WIDGET(ui->main_window));
#endif
- log_printf(LOG_DEBUG,
- "ui_notify() notif_notification_new %s",
- sensor->name);
+ log_debug("notif_notification_new %s", sensor->name);
notify_notification_show(notif, NULL);
static void cb_activate(GtkStatusIcon *icon,
gpointer data)
{
- log_printf(LOG_DEBUG, "cb_activate()");
+ log_debug("cb_activate()");
ui_window_show((struct ui_psensor *)data);
}
guint activate_time,
gpointer data)
{
- log_printf(LOG_DEBUG, "cb_popup_menu()");
+ log_debug("cb_popup_menu()");
}
void ui_status_init(struct ui_psensor *ui)
if (status)
return ;
- log_printf(LOG_DEBUG, "ui_status_create()");
+ log_debug("ui_status_create()");
status = gtk_status_icon_new();
gtk_status_icon_set_from_icon_name(status, "psensor_normal");
void ui_status_cleanup()
{
- log_printf(LOG_DEBUG, "ui_status_cleanup()");
+ log_debug("ui_status_cleanup()");
g_object_unref(G_OBJECT(status));
}
void ui_status_update(struct ui_psensor *ui, unsigned int attention)
{
- log_printf(LOG_DEBUG, "ui_status_update()");
+ log_debug("ui_status_update()");
if (status_attention && !attention)
gtk_status_icon_set_from_icon_name(status, "psensor_normal");