From a3c398a8e90d87ee203a7d7fd4a0216315364a34 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Sun, 25 Sep 2011 21:50:52 +0000 Subject: [PATCH] missing files --- src/lib/log.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/lib/log.h | 36 +++++++++++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 src/lib/log.c create mode 100644 src/lib/log.h diff --git a/src/lib/log.c b/src/lib/log.c new file mode 100644 index 0000000..fd7cf7a --- /dev/null +++ b/src/lib/log.c @@ -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 +#include +#define _(str) gettext(str) + +#include + +#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 index 0000000..20c6229 --- /dev/null +++ b/src/lib/log.h @@ -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 -- 2.7.4