Changeset 1691 for trunk/oscam-log.c
- Timestamp:
- 02/25/10 21:46:37 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/oscam-log.c
r1617 r1691 36 36 rc=rename(file, prev_log); 37 37 if( rc!=0 ) { 38 fprintf(stderr, "rename(%s, %s) failed (errno=%d)\n", 38 fprintf(stderr, "rename(%s, %s) failed (errno=%d)\n", 39 39 file, prev_log, errno); 40 40 } 41 else if( pfinit(file)) 41 else if( pfinit(file)) 42 42 cs_exit(0); 43 43 44 44 45 45 } 46 46 } … … 50 50 { 51 51 #ifdef CS_ANTICASC 52 if( use_ac_log && fpa ) 53 { 54 switch_log(cfg->ac_logfile, &fpa, ac_init_log); 55 fprintf(fpa, "%s", txt); 56 fflush(fpa); 57 } 58 else 52 if( use_ac_log && fpa ) { 53 switch_log(cfg->ac_logfile, &fpa, ac_init_log); 54 fprintf(fpa, "%s", txt); 55 fflush(fpa); 56 } 57 else 59 58 #endif 60 if (fp || use_stdout) 61 { 62 if( !use_stdout && !use_syslog) switch_log(cfg->logfile, &fp, cs_init_log); 63 fprintf(fp, "%s", txt); 64 fflush(fp); 65 } 66 } 67 68 int cs_init_log(char *file) 69 { 70 static char *head = ">> OSCam << cardserver started version " CS_VERSION ", build #" CS_SVN_VERSION " (" CS_OSTYPE ")"; 71 72 if (!strcmp(file, "stdout")) 73 { 74 use_stdout=1; 75 fp=stdout; 76 cs_log(head); 77 cs_log_config(); 78 return(0); 79 } 80 if (strcmp(file, "syslog")) 81 { 82 if (!fp) 83 { 84 if ((fp=fopen(file, "a+"))<=(FILE *)0) 85 { 86 fp=(FILE *)0; 87 fprintf(stderr, "couldn't open logfile: %s (errno %d)\n", file, errno); 88 } 89 else 90 { 91 time_t t; 92 char line[80]; 93 memset(line, '-', sizeof(line)); 94 line[(sizeof(line)/sizeof(char))-1]='\0'; 95 time(&t); 96 fprintf(fp, "\n%s\n>> OSCam << cardserver started at %s%s\n", line, ctime(&t), line); 97 cs_log_config(); 98 } 99 } 100 return(fp<=(FILE *)0); 101 } 102 else 103 { 104 openlog("oscam", LOG_NDELAY, LOG_DAEMON); 105 use_syslog=1; 106 cs_log(head); 107 cs_log_config(); 108 return(0); 109 } 59 if (fp || use_stdout) { 60 if( !use_stdout && !use_syslog) 61 switch_log(cfg->logfile, &fp, cs_init_log); 62 if (!cfg->disablelog){ 63 fprintf(fp, "%s", txt); 64 fflush(fp); 65 } 66 } 67 } 68 69 int cs_init_log(char *file) 70 { 71 static char *head = ">> OSCam << cardserver started version " CS_VERSION ", build #" CS_SVN_VERSION " (" CS_OSTYPE ")"; 72 73 if (!strcmp(file, "stdout")) { 74 use_stdout = 1; 75 fp = stdout; 76 cs_log(head); 77 cs_log_config(); 78 return(0); 79 } 80 if (strcmp(file, "syslog")) { 81 if (!fp) { 82 if ((fp = fopen(file, "a+")) <= (FILE *)0) { 83 fp = (FILE *)0; 84 fprintf(stderr, "couldn't open logfile: %s (errno %d)\n", file, errno); 85 } else { 86 time_t t; 87 char line[80]; 88 memset(line, '-', sizeof(line)); 89 line[(sizeof(line)/sizeof(char)) - 1] = '\0'; 90 time(&t); 91 if (!cfg->disablelog) 92 fprintf(fp, "\n%s\n>> OSCam << cardserver started at %s%s\n", line, ctime(&t), line); 93 cs_log_config(); 94 } 95 } 96 return(fp <= (FILE *)0); 97 } else { 98 openlog("oscam", LOG_NDELAY, LOG_DAEMON); 99 use_syslog = 1; 100 cs_log(head); 101 cs_log_config(); 102 return(0); 103 } 110 104 } 111 105 112 106 static char *get_log_header(int m, char *txt) 113 107 { 114 if (m) 115 { 116 sprintf(txt, "%6d ", getpid()); 117 if (cs_idx) 118 switch (client[cs_idx].typ) 119 { 120 case 'r': 121 case 'p': sprintf(txt+7, "%c%02d ", client[cs_idx].typ, cs_idx-1); 122 break; 123 case 'm': 124 case 'c': sprintf(txt+7, "%c%02d ", client[cs_idx].typ, cs_idx-cdiff); 125 break; 108 if(m) { 109 sprintf(txt, "%6d ", getpid()); 110 if (cs_idx) { 111 switch (client[cs_idx].typ) { 112 case 'r': 113 case 'p': sprintf(txt+7, "%c%02d ", client[cs_idx].typ, cs_idx - 1); 114 break; 115 case 'm': 116 case 'c': sprintf(txt+7, "%c%02d ", client[cs_idx].typ, cs_idx - cdiff); 117 break; 126 118 #ifdef CS_ANTICASC 127 128 #endif 129 130 case 'n': sprintf(txt+7, "%c " , client[cs_idx].typ); 131 break;132 } 133 else 134 strcpy(txt+7, "s "); 135 } 136 else 137 138 139 140 119 case 'a': 120 #endif 121 case 'l': 122 case 'h': 123 case 'n': sprintf(txt+7, "%c " , client[cs_idx].typ); 124 break; 125 } 126 } else { 127 strcpy(txt+7, "s "); 128 } 129 } else { 130 sprintf(txt, "%-11.11s", ""); 131 } 132 return(txt); 141 133 } 142 134 … … 220 212 } 221 213 222 void cs_close_log(void) 214 void cs_close_log(void) 223 215 { 224 216 if (use_stdout || use_syslog || !fp) return;
Note:
See TracChangeset
for help on using the changeset viewer.