1 /* 2 3 File: log.h 4 5 Copyright (C) 2007-2009 Christophe GRENIER <grenier@cgsecurity.org> 6 7 This software is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 2 of the License, or 10 (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License along 18 with this program; if not, write the Free Software Foundation, Inc., 51 19 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 21 */ 22 #ifndef _LOG_H 23 #define _LOG_H 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 int log_set_levels(const unsigned int levels); 29 FILE *log_open(const char*default_filename, const int mode, int *errsv); 30 FILE *log_open_default(const char*default_filename, const int mode, int *errsv); 31 int log_flush(void); 32 int log_close(void); 33 int log_redirect(unsigned int level, const char *format, ...) __attribute__((format(printf, 2, 3))); 34 void dump_log(const void *nom_dump,unsigned int lng); 35 void dump2_log(const void *dump_1, const void *dump_2,const unsigned int lng); 36 37 #define TD_LOG_NONE 0 38 #define TD_LOG_CREATE 1 39 #define TD_LOG_APPEND 2 40 #define TD_LOG_DONE 3 41 42 #define LOG_LEVEL_DEBUG (1 << 0) /* x = 42 */ 43 #define LOG_LEVEL_TRACE (1 << 1) /* Entering function x() */ 44 #define LOG_LEVEL_QUIET (1 << 2) /* Quietable output */ 45 #define LOG_LEVEL_INFO (1 << 3) /* Volume needs defragmenting */ 46 #define LOG_LEVEL_VERBOSE (1 << 4) /* Forced to continue */ 47 #define LOG_LEVEL_PROGRESS (1 << 5) /* 54% complete */ 48 #define LOG_LEVEL_WARNING (1 << 6) /* You should backup before starting */ 49 #define LOG_LEVEL_ERROR (1 << 7) /* Operation failed, no damage done */ 50 #define LOG_LEVEL_PERROR (1 << 8) /* Message : standard error description */ 51 #define LOG_LEVEL_CRITICAL (1 << 9) /* Operation failed,damage may have occurred */ 52 53 #define log_debug(FORMAT, ARGS...) log_redirect(LOG_LEVEL_DEBUG,FORMAT,##ARGS) 54 #define log_trace(FORMAT, ARGS...) log_redirect(LOG_LEVEL_TRACE,FORMAT,##ARGS) 55 #define log_quiet(FORMAT, ARGS...) log_redirect(LOG_LEVEL_QUIET,FORMAT,##ARGS) 56 #define log_info(FORMAT, ARGS...) log_redirect(LOG_LEVEL_INFO,FORMAT,##ARGS) 57 #define log_verbose(FORMAT, ARGS...) log_redirect(LOG_LEVEL_VERBOSE,FORMAT,##ARGS) 58 #define log_progress(FORMAT, ARGS...) log_redirect(LOG_LEVEL_PROGRESS,FORMAT,##ARGS) 59 #define log_warning(FORMAT, ARGS...) log_redirect(LOG_LEVEL_WARNING,FORMAT,##ARGS) 60 #define log_error(FORMAT, ARGS...) log_redirect(LOG_LEVEL_ERROR,FORMAT,##ARGS) 61 #define log_perror(FORMAT, ARGS...) log_redirect(LOG_LEVEL_PERROR,FORMAT,##ARGS) 62 #define log_critical(FORMAT, ARGS...) log_redirect(LOG_LEVEL_CRITICAL,FORMAT,##ARGS) 63 64 #ifdef __cplusplus 65 } /* closing brace for extern "C" */ 66 #endif 67 #endif 68