1 #ifndef DEBLOG_H 2 #define DEBLOG_H 3 4 /* 5 newsstar - advanced news fetcher 6 Copyright (C) 2001-2002 Tony Houghton <h@realh.co.uk> 7 8 This program is free software; you can redistribute it and/or modify 9 it under the terms of the GNU General Public License as published by 10 the Free Software Foundation; either version 2 of the License, or 11 (at your option) any later version. 12 13 This program is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with this program; if not, write to the Free Software 20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 */ 22 23 /* Logging for debugging */ 24 25 26 #include <stdarg.h> 27 28 #include "rw.h" 29 30 /* NB, avoid \r at end of line, and avoid \n anywhere else, because of the way 31 * messages may be piped from child to parent process */ 32 33 /* Logging levels are similar to glib's; Message goes to stdout; rest go to 34 * stderr */ 35 typedef enum { 36 deblog_Level_Error, /* Fatal error, causes exit */ 37 deblog_Level_Critical, /* Error, but can continue */ 38 deblog_Level_Warning, 39 deblog_Level_Brief, /* Special message used instead of Level_Message 40 in brief mode */ 41 deblog_Level_Message, 42 deblog_Level_Info, /* Mainly for debugging */ 43 deblog_Level_Debug, /* Verbose debugging */ 44 #ifdef ENABLE_KEYED_LOG 45 deblog_Level_Keyed /* First word of message is key; only printed 46 if key is enabled; key in message must be 47 followed by space (ASCII 0x20) */ 48 #endif 49 } deblog_level_t; 50 51 /* Whether we're in brief mode */ 52 extern BOOL deblog_be_brief; 53 54 /* These are the logging functions themselves, to be called printf-style */ 55 void deblog_printf(deblog_level_t, const char *, ...); 56 void deblog_error(const char *, ...); 57 void deblog_critical(const char *, ...); 58 void deblog_warning(const char *, ...); 59 void deblog_brief(const char *, ...); 60 void deblog_message(const char *, ...); 61 void deblog_info(const char *, ...); 62 void deblog_debug(const char *, ...); 63 64 /* As above, called vprintf-style */ 65 void deblog_vprintf(deblog_level_t, const char *, va_list); 66 void deblog_verror(const char *, va_list); 67 void deblog_vcritical(const char *, va_list); 68 void deblog_vwarning(const char *, va_list); 69 void deblog_vbrief(const char *, va_list); 70 void deblog_vmessage(const char *, va_list); 71 void deblog_vinfo(const char *, va_list); 72 void deblog_vdebug(const char *, va_list); 73 74 /* As above with a thread index */ 75 void deblog_printf_thread(int thread_idx, deblog_level_t, const char *, ...); 76 void deblog_error_thread(int thread_idx, const char *, ...); 77 void deblog_critical_thread(int thread_idx, const char *, ...); 78 void deblog_warning_thread(int thread_idx, const char *, ...); 79 void deblog_brief_thread(int thread_idx, const char *, ...); 80 void deblog_message_thread(int thread_idx, const char *, ...); 81 void deblog_info_thread(int thread_idx, const char *, ...); 82 void deblog_debug_thread(int thread_idx, const char *, ...); 83 84 void deblog_vprintf_thread(int thread_idx, deblog_level_t, const char *, 85 va_list); 86 void deblog_verror_thread(int thread_idx, const char *, va_list); 87 void deblog_vcritical_thread(int thread_idx, const char *, va_list); 88 void deblog_vwarning_thread(int thread_idx, const char *, va_list); 89 void deblog_vbrief_thread(int thread_idx, const char *, va_list); 90 void deblog_vmessage_thread(int thread_idx, const char *, va_list); 91 void deblog_vinfo_thread(int thread_idx, const char *, va_list); 92 void deblog_vdebug_thread(int thread_idx, const char *, va_list); 93 94 #ifdef ENABLE_KEYED_LOG 95 void deblog_keyed(const char *, ...); 96 void deblog_vkeyed(const char *, va_list); 97 void deblog_keyed_thread(int thread_idx, const char *, ...); 98 void deblog_vkeyed_thread(int thread_idx, const char *, va_list); 99 100 void deblog_enable_key(const char *key); 101 void deblog_disable_key(const char *key); 102 #endif 103 104 /* No printf-style formatting: this makes it safe to log messages without 105 * arguments, but which may have %'s in them */ 106 void deblog_print_thread(int thread_idx, deblog_level_t level, const char 107 *message); 108 109 /* This tells deblog that the last line written to the screen didn't end with a 110 * LF, so it must print one itself before the next message */ 111 void deblog_need_lf(void); 112 113 typedef enum { 114 deblog_Mask_Error = 1 << deblog_Level_Error, 115 deblog_Mask_Critical = 1 << deblog_Level_Critical, 116 deblog_Mask_Warning = 1 << deblog_Level_Warning, 117 deblog_Mask_Brief = 1 << deblog_Level_Brief, 118 deblog_Mask_Message = 1 << deblog_Level_Message, 119 deblog_Mask_Info = 1 << deblog_Level_Info, 120 deblog_Mask_Debug = 1 << deblog_Level_Debug, 121 #ifdef ENABLE_KEYED_LOG 122 deblog_Mask_Keyed = 1 << deblog_Level_Keyed, 123 #endif 124 125 deblog_Mask_Default = deblog_Mask_Error 126 | deblog_Mask_Critical 127 | deblog_Mask_Warning 128 | deblog_Mask_Brief 129 | deblog_Mask_Message, 130 deblog_Mask_All = deblog_Mask_Default 131 | deblog_Mask_Info 132 | deblog_Mask_Debug 133 #ifdef ENABLE_KEYED_LOG 134 | deblog_Mask_Keyed 135 #endif 136 } deblog_mask_t; 137 138 /* Sets mask to absolute value, OR'd from deblog_mask values. Default value is 139 * all except Info and Debug */ 140 void deblog_set_mask(deblog_mask_t); 141 142 /* Enables/disables an individual level */ 143 void deblog_enable_level(deblog_level_t); 144 void deblog_disable_level(deblog_level_t); 145 146 /* We're a subthread, so log via pipe */ 147 void deblog_use_pipe(rw_buf *, int thread_idx); 148 149 /* Allows deblog_vprintf to be called recursively under exceptional 150 * circumstances eg if interrupted by a signal causing shutdown */ 151 void deblog_allow_recursion(BOOL allowed); 152 153 /* Normally we assume that stdout/stderr are merged. This tells it they're 154 * separate. It makes a difference because of the way the stats output 155 * overwrites lines. */ 156 void deblog_separate_sinks(void); 157 158 /* Normally, stats are forced updated after each message, use this to turn it 159 * off at end of run */ 160 void deblog_disable_stats_update(void); 161 162 #endif /* ! DEBLOG_H */ 163