missing files
authorJean-Philippe Orsini <jeanfi@gmail.com>
Sun, 25 Sep 2011 21:50:52 +0000 (21:50 +0000)
committerJean-Philippe Orsini <jeanfi@gmail.com>
Sun, 25 Sep 2011 21:50:52 +0000 (21:50 +0000)
src/lib/log.c [new file with mode: 0644]
src/lib/log.h [new file with mode: 0644]

diff --git a/src/lib/log.c b/src/lib/log.c
new file mode 100644 (file)
index 0000000..fd7cf7a
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+    Copyright (C) 2010-2011 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 <stdio.h>
+
+#include "log.h"
+
+static FILE *file;
+static int log_level =  LOG_DEBUG;
+
+void log_open(const char *path, int lvl)
+{
+       file = fopen(path, "a");
+
+       if (file)
+               log_puts(LOG_INFO, "Start logging");
+       else
+               fprintf(stderr, _("Cannot open log file: %s\n"), path);
+}
+
+void log_puts(int lvl, const char *msg)
+{
+       if (!file || lvl > log_level)
+               return ;
+
+       switch (lvl) {
+       case LOG_WARN:
+               fputs("[WARN] ", file);
+               break;
+       case LOG_ERR:
+               fputs("[ERR] ", file);
+               break;
+       case LOG_DEBUG:
+               fputs("[DEBUG] ", file);
+               break;
+       case LOG_INFO:
+               fputs("[INFO] ", file);
+               break;
+       default:
+               fputs("[??] ", file);
+       }
+
+       fputs(msg, file);
+       fputc('\n', file);
+
+       fflush(file);
+}
+
+void log_close()
+{
+       if (!file)
+               return ;
+
+       fclose(file);
+
+       file = NULL;
+}
+
diff --git a/src/lib/log.h b/src/lib/log.h
new file mode 100644 (file)
index 0000000..20c6229
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+    Copyright (C) 2010-2011 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 _PSENSOR_LOG_H_
+#define _PSENSOR_LOG_H_
+
+enum log_level {
+       LOG_ERR ,
+       LOG_WARN,
+       LOG_INFO,
+       LOG_DEBUG
+};
+
+void log_open(const char *path, int lvl);
+
+void log_puts(int lvl, const char *msg);
+
+void log_close();
+
+#endif