Changeset 5065 for trunk/oscam-log.c
- Timestamp:
- 04/20/11 23:16:55 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/oscam-log.c
r5026 r5065 8 8 9 9 pthread_mutex_t switching_log; 10 #ifdef CS_LOGHISTORY11 10 pthread_mutex_t loghistory_lock; 12 #endif13 11 14 12 #ifdef CS_ANTICASC … … 125 123 if(logStarted == 0){ 126 124 pthread_mutex_init(&switching_log, NULL); 127 #ifdef CS_LOGHISTORY128 125 pthread_mutex_init(&loghistory_lock, NULL); 129 #endif130 126 } 131 127 int32_t rc = cs_open_logfiles(); … … 144 140 } 145 141 146 static void write_to_log( int32_t flag,char *txt)142 static void write_to_log(char *txt) 147 143 { 148 144 //flag = -1 is old behaviour, before implementation of debug_nolf (=debug no line feed) … … 167 163 localtime_r(&t, <); 168 164 169 switch(flag) { 170 case -1: 171 snprintf(log_buf, sizeof(log_buf), "[LOG000]%4d/%02d/%02d %2d:%02d:%02d %s\n", 172 lt.tm_year+1900, lt.tm_mon+1, lt.tm_mday, 173 lt.tm_hour, lt.tm_min, lt.tm_sec, txt); 174 break; 175 case 1: 176 snprintf(log_buf, sizeof(log_buf), "[LOG000]%4d/%02d/%02d %2d:%02d:%02d %s", 177 lt.tm_year+1900, lt.tm_mon+1, lt.tm_mday, 178 lt.tm_hour, lt.tm_min, lt.tm_sec, txt); 179 break; 180 default: 181 snprintf(log_buf, sizeof(log_buf), "[LOG000]%s", txt); 182 } 165 snprintf(log_buf, sizeof(log_buf), "[LOG000]%4d/%02d/%02d %2d:%02d:%02d %s\n", 166 lt.tm_year+1900, lt.tm_mon+1, lt.tm_mday, lt.tm_hour, lt.tm_min, lt.tm_sec, txt); 183 167 184 168 cs_write_log(log_buf + 8); 185 #ifdef CS_LOGHISTORY 186 pthread_mutex_lock(&loghistory_lock); 187 char *ptr=(char *)(loghist+(loghistidx*CS_LOGHISTSIZE)); 188 loghistidx=(++loghistidx < CS_MAXLOGHIST)?loghistidx:0; 189 pthread_mutex_unlock(&loghistory_lock); 190 191 ptr[0]='\1'; // make username unusable 192 ptr[1]='\0'; 193 194 if (!cur_cl) 195 cs_strncpy(ptr, "undef", 63); 196 else if ((cur_cl->typ=='c') || (cur_cl->typ=='m')) 197 cs_strncpy(ptr, cur_cl->account?cur_cl->account->usr:"", 63); 198 else if ((cur_cl->typ=='p') || (cur_cl->typ=='r')) 199 cs_strncpy(ptr, cur_cl->reader?cur_cl->reader->label:"", 63); 200 else 201 cs_strncpy(ptr, "server", 63); 202 203 cs_strncpy(ptr+32, log_buf, CS_LOGHISTSIZE-33); 204 205 #endif 169 170 if (loghist) { 171 char *usrtxt = NULL; 172 173 if (!cur_cl) 174 usrtxt = "undef"; 175 else { 176 switch(cur_cl->typ) { 177 case 'c': 178 case 'm': 179 usrtxt = cur_cl->account ? cur_cl->account->usr : ""; 180 break; 181 case 'p': 182 case 'r': 183 usrtxt = cur_cl->reader ? cur_cl->reader->label : ""; 184 break; 185 default: 186 usrtxt = "server"; 187 break; 188 } 189 } 190 191 char *target_ptr = NULL; 192 int target_len = strlen(usrtxt) + (strlen(log_buf) - 8) + 1; 193 char *lastpos = loghist + (cfg.loghistorysize) - 1; 194 195 pthread_mutex_lock(&loghistory_lock); 196 if (!loghistptr) 197 loghistptr = loghist; 198 199 if (loghistptr+target_len > lastpos - 1) { 200 *loghistptr='\0'; 201 loghistptr=loghist + target_len + 1; 202 *loghistptr='\0'; 203 target_ptr=loghist; 204 } else { 205 target_ptr = loghistptr; 206 loghistptr=loghistptr + target_len + 1; 207 *loghistptr='\0'; 208 } 209 pthread_mutex_unlock(&loghistory_lock); 210 211 snprintf(target_ptr, target_len + 1, "%s\t%s", usrtxt, log_buf + 8); 212 } 213 206 214 struct s_client *cl; 207 for (cl=first_client; cl ; cl=cl->next) 208 { 209 if ((cl->typ == 'm') && (cl->monlvl>0)) 210 if (cl->log) //this variable is only initialized for cl->typ = 'm' 215 for (cl=first_client; cl ; cl=cl->next) { 216 if ((cl->typ == 'm') && (cl->monlvl>0) && cl->log) //this variable is only initialized for cl->typ = 'm' 211 217 { 212 218 if (cl->monlvl<2) { … … 232 238 vsnprintf(log_txt+11, sizeof(log_txt) - 11, fmt, params); 233 239 va_end(params); 234 write_to_log( -1,log_txt);240 write_to_log(log_txt); 235 241 } 236 242 … … 252 258 vsnprintf(log_txt+11, sizeof(log_txt) - 11, fmt, params); 253 259 va_end(params); 254 write_to_log( -1,log_txt);260 write_to_log(log_txt); 255 261 } 256 262 } … … 268 274 vsnprintf(log_txt+11, sizeof(log_txt) - 11, fmt, params); 269 275 va_end(params); 270 write_to_log( -1,log_txt);276 write_to_log(log_txt); 271 277 //printf("LOG: %s\n", txt); fflush(stdout); 272 278 } … … 276 282 get_log_header(0, log_txt); 277 283 snprintf(log_txt+11, sizeof(log_txt) - 11, "%s", cs_hexdump(1, buf+i, (n-i>16) ? 16 : n-i)); 278 write_to_log( -1,log_txt);284 write_to_log(log_txt); 279 285 } 280 286 } … … 292 298 vsnprintf(log_txt+11, sizeof(log_txt) - 11, fmt, params); 293 299 va_end(params); 294 write_to_log( -1,log_txt);300 write_to_log(log_txt); 295 301 //printf("LOG: %s\n", txt); fflush(stdout); 296 302 } … … 301 307 get_log_header(0, log_txt); 302 308 snprintf(log_txt+11, sizeof(log_txt) - 11, "%s", cs_hexdump(1, buf+i, (n-i>16) ? 16 : n-i)); 303 write_to_log( -1,log_txt);309 write_to_log(log_txt); 304 310 } 305 311 }
Note:
See TracChangeset
for help on using the changeset viewer.