diff options
| author | me_desk <me_desk@fb96df88-216d-11de-830c-f3023f12d8ac> | 2012-07-01 19:01:46 +0000 |
|---|---|---|
| committer | me_desk <me_desk@fb96df88-216d-11de-830c-f3023f12d8ac> | 2012-07-01 19:01:46 +0000 |
| commit | efd5d206b65673d751c0aefe540f456fd9d06811 (patch) | |
| tree | 0a5afacee0edf2216046a65e109c4fdff15fe7e5 | |
| parent | 21124ba5a7d75ebb9856233b37e09476b4872280 (diff) | |
| download | pica-pica-efd5d206b65673d751c0aefe540f456fd9d06811.tar.gz pica-pica-efd5d206b65673d751c0aefe540f456fd9d06811.zip | |
log functions added and implemented
git-svn-id: svn://localhost/project_picapica/trunk@136 fb96df88-216d-11de-830c-f3023f12d8ac
| -rw-r--r-- | PICA_log.c | 99 | ||||
| -rw-r--r-- | PICA_log.h | 25 |
2 files changed, 124 insertions, 0 deletions
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 <stdio.h> +#include <stdlib.h> + +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 <stdarg.h> + +#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 |
