- Timestamp:
- 2015-02-20T22:50:54Z (8 years ago)
- Branches:
- master
- Children:
- 0b9daac, 3d45471, 7733b8c
- Parents:
- af359b4
- git-author:
- Indent <please@…> (19-02-15 05:47:20)
- git-committer:
- dequis <dx@…> (20-02-15 22:50:54)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
log.c
raf359b4 r5ebff60 1 1 /********************************************************************\ 2 2 * BitlBee -- An IRC to other IM-networks gateway * 3 3 * * … … 5 5 \********************************************************************/ 6 6 7 /* Logging services for the bee 7 /* Logging services for the bee */ 8 8 9 9 /* … … 35 35 static void log_console(int level, const char *logmessage); 36 36 37 void log_init(void) { 38 openlog("bitlbee", LOG_PID, LOG_DAEMON); 37 void log_init(void) 38 { 39 openlog("bitlbee", LOG_PID, LOG_DAEMON); 39 40 40 41 logoutput.informational = &log_null; … … 48 49 } 49 50 50 void log_link(int level, int output) { 51 void log_link(int level, int output) 52 { 51 53 /* I know it's ugly, but it works and I didn't feel like messing with pointer to function pointers */ 52 54 53 if (level == LOGLVL_INFO) {54 if (output == LOGOUTPUT_NULL)55 logoutput.informational = &log_null; 56 else if(output == LOGOUTPUT_IRC)57 logoutput.informational = &log_irc; 58 else if(output == LOGOUTPUT_SYSLOG)59 logoutput.informational = &log_syslog; 60 else if(output == LOGOUTPUT_CONSOLE)61 logoutput.informational = &log_console; 62 }63 else if(level == LOGLVL_WARNING) {64 if (output == LOGOUTPUT_NULL)55 if (level == LOGLVL_INFO) { 56 if (output == LOGOUTPUT_NULL) { 57 logoutput.informational = &log_null; 58 } else if (output == LOGOUTPUT_IRC) { 59 logoutput.informational = &log_irc; 60 } else if (output == LOGOUTPUT_SYSLOG) { 61 logoutput.informational = &log_syslog; 62 } else if (output == LOGOUTPUT_CONSOLE) { 63 logoutput.informational = &log_console; 64 } 65 } else if (level == LOGLVL_WARNING) { 66 if (output == LOGOUTPUT_NULL) { 65 67 logoutput.warning = &log_null; 66 else if(output == LOGOUTPUT_IRC)68 } else if (output == LOGOUTPUT_IRC) { 67 69 logoutput.warning = &log_irc; 68 else if(output == LOGOUTPUT_SYSLOG)70 } else if (output == LOGOUTPUT_SYSLOG) { 69 71 logoutput.warning = &log_syslog; 70 else if(output == LOGOUTPUT_CONSOLE)72 } else if (output == LOGOUTPUT_CONSOLE) { 71 73 logoutput.warning = &log_console; 72 }73 else if(level == LOGLVL_ERROR) {74 if (output == LOGOUTPUT_NULL)74 } 75 } else if (level == LOGLVL_ERROR) { 76 if (output == LOGOUTPUT_NULL) { 75 77 logoutput.error = &log_null; 76 else if(output == LOGOUTPUT_IRC)78 } else if (output == LOGOUTPUT_IRC) { 77 79 logoutput.error = &log_irc; 78 else if(output == LOGOUTPUT_SYSLOG)80 } else if (output == LOGOUTPUT_SYSLOG) { 79 81 logoutput.error = &log_syslog; 80 else if(output == LOGOUTPUT_CONSOLE)82 } else if (output == LOGOUTPUT_CONSOLE) { 81 83 logoutput.error = &log_console; 82 } 83 #ifdef DEBUG 84 else if(level == LOGLVL_DEBUG) { 85 if(output == LOGOUTPUT_NULL) 84 } 85 } 86 #ifdef DEBUG 87 else if (level == LOGLVL_DEBUG) { 88 if (output == LOGOUTPUT_NULL) { 86 89 logoutput.debug = &log_null; 87 else if(output == LOGOUTPUT_IRC)90 } else if (output == LOGOUTPUT_IRC) { 88 91 logoutput.debug = &log_irc; 89 else if(output == LOGOUTPUT_SYSLOG)92 } else if (output == LOGOUTPUT_SYSLOG) { 90 93 logoutput.debug = &log_syslog; 91 else if(output == LOGOUTPUT_CONSOLE)94 } else if (output == LOGOUTPUT_CONSOLE) { 92 95 logoutput.debug = &log_console; 93 } 94 #endif 95 return; 96 97 } 98 99 void log_message(int level, const char *message, ... ) { 96 } 97 } 98 #endif 99 return; 100 101 } 102 103 void log_message(int level, const char *message, ...) 104 { 100 105 101 106 va_list ap; … … 106 111 va_end(ap); 107 112 108 if (level == LOGLVL_INFO)113 if (level == LOGLVL_INFO) { 109 114 (*(logoutput.informational))(level, msgstring); 110 if(level == LOGLVL_WARNING) 115 } 116 if (level == LOGLVL_WARNING) { 111 117 (*(logoutput.warning))(level, msgstring); 112 if(level == LOGLVL_ERROR) 118 } 119 if (level == LOGLVL_ERROR) { 113 120 (*(logoutput.error))(level, msgstring); 114 #ifdef DEBUG 115 if(level == LOGLVL_DEBUG) 121 } 122 #ifdef DEBUG 123 if (level == LOGLVL_DEBUG) { 116 124 (*(logoutput.debug))(level, msgstring); 125 } 117 126 #endif 118 127 119 128 g_free(msgstring); 120 121 return; 122 } 123 124 void log_error(const char *functionname) { 129 130 return; 131 } 132 133 void log_error(const char *functionname) 134 { 125 135 log_message(LOGLVL_ERROR, "%s: %s", functionname, strerror(errno)); 126 127 return; 128 } 129 130 static void log_null(int level, const char *message) { 131 return; 132 } 133 134 static void log_irc(int level, const char *message) { 135 if(level == LOGLVL_ERROR) 136 137 return; 138 } 139 140 static void log_null(int level, const char *message) 141 { 142 return; 143 } 144 145 static void log_irc(int level, const char *message) 146 { 147 if (level == LOGLVL_ERROR) { 136 148 irc_write_all(1, "ERROR :Error: %s", message); 137 if(level == LOGLVL_WARNING) 149 } 150 if (level == LOGLVL_WARNING) { 138 151 irc_write_all(0, "ERROR :Warning: %s", message); 139 if(level == LOGLVL_INFO) 140 irc_write_all(0, "ERROR :Informational: %s", message); 141 #ifdef DEBUG 142 if(level == LOGLVL_DEBUG) 143 irc_write_all(0, "ERROR :Debug: %s", message); 144 #endif 145 146 return; 147 } 148 149 static void log_syslog(int level, const char *message) { 150 if(level == LOGLVL_ERROR) 152 } 153 if (level == LOGLVL_INFO) { 154 irc_write_all(0, "ERROR :Informational: %s", message); 155 } 156 #ifdef DEBUG 157 if (level == LOGLVL_DEBUG) { 158 irc_write_all(0, "ERROR :Debug: %s", message); 159 } 160 #endif 161 162 return; 163 } 164 165 static void log_syslog(int level, const char *message) 166 { 167 if (level == LOGLVL_ERROR) { 151 168 syslog(LOG_ERR, "%s", message); 152 if(level == LOGLVL_WARNING) 169 } 170 if (level == LOGLVL_WARNING) { 153 171 syslog(LOG_WARNING, "%s", message); 154 if(level == LOGLVL_INFO) 172 } 173 if (level == LOGLVL_INFO) { 155 174 syslog(LOG_INFO, "%s", message); 156 #ifdef DEBUG 157 if(level == LOGLVL_DEBUG) 175 } 176 #ifdef DEBUG 177 if (level == LOGLVL_DEBUG) { 158 178 syslog(LOG_DEBUG, "%s", message); 159 #endif 160 return; 161 } 162 163 static void log_console(int level, const char *message) { 164 if(level == LOGLVL_ERROR) 179 } 180 #endif 181 return; 182 } 183 184 static void log_console(int level, const char *message) 185 { 186 if (level == LOGLVL_ERROR) { 165 187 fprintf(stderr, "Error: %s\n", message); 166 if(level == LOGLVL_WARNING) 188 } 189 if (level == LOGLVL_WARNING) { 167 190 fprintf(stderr, "Warning: %s\n", message); 168 if(level == LOGLVL_INFO) 191 } 192 if (level == LOGLVL_INFO) { 169 193 fprintf(stdout, "Informational: %s\n", message); 170 #ifdef DEBUG 171 if(level == LOGLVL_DEBUG) 194 } 195 #ifdef DEBUG 196 if (level == LOGLVL_DEBUG) { 172 197 fprintf(stdout, "Debug: %s\n", message); 198 } 173 199 #endif 174 200 /* Always log stuff in syslogs too. */
Note: See TracChangeset
for help on using the changeset viewer.