From efd5d206b65673d751c0aefe540f456fd9d06811 Mon Sep 17 00:00:00 2001 From: me_desk Date: Sun, 1 Jul 2012 19:01:46 +0000 Subject: log functions added and implemented git-svn-id: svn://localhost/project_picapica/trunk@136 fb96df88-216d-11de-830c-f3023f12d8ac --- PICA_log.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ PICA_log.h | 25 ++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 PICA_log.c create mode 100644 PICA_log.h diff --git a/PICA_log.c b/PICA_log.c new file mode 100644 index 0000000..81ea39c --- /dev/null +++ b/PICA_log.c @@ -0,0 +1,99 @@ +#include "PICA_log.h" + +#include +#include + +static int PICA_loglevel = PICA_LOG_INFO; + +void PICA_fatal(const char *fmt,...) +{ +va_list args; + +va_start(args, fmt); +PICA_log_entry(PICA_LOG_FATAL, fmt, args); +va_end(args); +exit(-1); +} + +void PICA_error(const char *fmt,...) +{ +va_list args; + +va_start(args, fmt); +PICA_log_entry(PICA_LOG_ERROR, fmt, args); +va_end(args); +} + +void PICA_warn(const char *fmt,...) +{ +va_list args; + +va_start(args, fmt); +PICA_log_entry(PICA_LOG_WARN, fmt, args); +va_end(args); +} + +void PICA_info(const char *fmt,...) +{ +va_list args; + +va_start(args, fmt); +PICA_log_entry(PICA_LOG_INFO, fmt, args); +va_end(args); +} + +void PICA_debug1(const char *fmt,...) +{ +if (PICA_loglevel >= PICA_LOG_DBG1) + { + va_list args; + + va_start(args, fmt); + PICA_log_entry(PICA_LOG_DBG1, fmt, args); + va_end(args); + } +} + +void PICA_debug2(const char *fmt,...) +{ +if (PICA_loglevel >= PICA_LOG_DBG2) + { + va_list args; + + va_start(args, fmt); + PICA_log_entry(PICA_LOG_DBG2, fmt, args); + va_end(args); + } +} + +void PICA_debug3(const char *fmt,...) +{ +if (PICA_loglevel >= PICA_LOG_DBG3) + { + va_list args; + + va_start(args, fmt); + PICA_log_entry(PICA_LOG_DBG3, fmt, args); + va_end(args); + } +} + +void PICA_log_entry(int loglevel, const char *fmt, va_list args) +{ +static char buf[1024]; +static const char *loglevel_txt[] = {"fatal", "error", "warning", "info", "debug1", "debug2", "debug3"}; +FILE *log_file = stdout; + +if (loglevel <= PICA_LOG_WARN) + log_file = stderr; + +sprintf(buf, "%s: %.1000s\n", loglevel_txt[loglevel - PICA_LOG_FATAL], fmt); + +vfprintf(log_file, buf, args); +} + +void PICA_set_loglevel(int loglevel) +{ +if (loglevel >= PICA_LOG_FATAL && loglevel <= PICA_LOG_DBG3) + PICA_loglevel = loglevel; +} \ No newline at end of file diff --git a/PICA_log.h b/PICA_log.h new file mode 100644 index 0000000..46c80a4 --- /dev/null +++ b/PICA_log.h @@ -0,0 +1,25 @@ +#ifndef PICA_LOG_H +#define PICA_LOG_H + +#include + +#define PICA_LOG_FATAL 31337 +#define PICA_LOG_ERROR 31338 +#define PICA_LOG_WARN 31339 +#define PICA_LOG_INFO 31340 +#define PICA_LOG_DBG1 31341 +#define PICA_LOG_DBG2 31342 +#define PICA_LOG_DBG3 31343 + +void PICA_fatal(const char *fmt,...); +void PICA_error(const char *fmt,...); +void PICA_warn(const char *fmt,...); +void PICA_info(const char *fmt,...); +void PICA_debug1(const char *fmt,...); +void PICA_debug2(const char *fmt,...); +void PICA_debug3(const char *fmt,...); + +void PICA_log_entry(int loglevel, const char *fmt, va_list args); + +void PICA_set_loglevel(int loglevel); +#endif -- cgit v1.2.1