+* v0.6.2.12
+** psensor: added -d option to enable debug log (written to $HOME/.psensor/log).
+** psensor: log sensor values in debug mode.
+
* v0.6.2.11
** psensor-server/web interface: use jqplot default css.
** psensor-server/web interface: added excanvas for ie < 9 support.
#include <libintl.h>
#define _(str) gettext(str)
+#include <stdarg.h>
#include <stdio.h>
+#include <sys/time.h>
#include "log.h"
static FILE *file;
-static int log_level = LOG_DEBUG;
+int log_level = LOG_INFO;
void log_open(const char *path, int lvl)
{
void log_puts(int lvl, const char *msg)
{
+ log_printf(lvl, msg);
+}
+
+void log_close()
+{
+ if (!file)
+ return ;
+
+ fclose(file);
+
+ file = NULL;
+}
+
+#define LOG_BUFFER 4096
+void log_printf(int lvl, const char *fmt, ...)
+{
+ struct timeval tv;
+ static char buffer[1 + LOG_BUFFER];
+ va_list ap;
+ char *lvl_str;
+
if (!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);
+
switch (lvl) {
case LOG_WARN:
- fputs("[WARN] ", file);
+ lvl_str = "[WARN]";
break;
case LOG_ERR:
- fputs("[ERR] ", file);
+ lvl_str = "[ERR]";
break;
case LOG_DEBUG:
- fputs("[DEBUG] ", file);
+ lvl_str = "[DEBUG]";
break;
case LOG_INFO:
- fputs("[INFO] ", file);
+ lvl_str = "[INFO]";
break;
default:
- fputs("[??] ", file);
+ lvl_str = "[??]";
}
- fputs(msg, file);
- fputc('\n', file);
-
+ fprintf(file, "[%ld] %s %s\n", tv.tv_sec, lvl_str, buffer);
fflush(file);
}
-void log_close()
-{
- if (!file)
- return ;
-
- fclose(file);
-
- file = NULL;
-}
-
void log_open(const char *path, int lvl);
+void log_printf(int lvl, const char *fmt, ...);
void log_puts(int lvl, const char *msg);
void log_close();
+extern int log_level;
+
#endif
}
}
+static void log_measures(struct psensor **sensors)
+{
+ if (log_level == LOG_DEBUG)
+ while (*sensors) {
+ log_printf(LOG_DEBUG, "%s %.2f",
+ (*sensors)->name,
+ psensor_get_current_value(*sensors));
+
+ sensors++;
+ }
+}
+
void update_psensor_measures(struct ui_psensor *ui)
{
struct psensor **sensors = ui->sensors;
#ifdef HAVE_LIBATIADL
amd_psensor_list_update(sensors);
#endif
+
+ log_measures(sensors);
+
g_mutex_unlock(ui->sensors_mutex);
sleep(cfg->sensor_update_interval);
{"version", no_argument, 0, 'v'},
{"help", no_argument, 0, 'h'},
{"url", required_argument, 0, 'u'},
+ {"debug", no_argument, 0, 'd'},
{0, 0, 0, 0}
};
textdomain(PACKAGE);
#endif
- while ((optc = getopt_long(argc, argv, "vhu:", long_options,
+ while ((optc = getopt_long(argc, argv, "vhdu:", long_options,
NULL)) != -1) {
switch (optc) {
case 'u':
case 'v':
print_version();
exit(EXIT_SUCCESS);
+ case 'd':
+ printf(_("Enables debug mode.\n"));
+ log_level = LOG_DEBUG;
+ break;
default:
cmdok = 0;
break;