13 #include <sys/types.h>
17 #define MAX_LOGFILES 128
21 static char buff[1024] ;
22 static struct stat statb ;
24 static char level_str[] =
"dummy string";
26 static char logfiles[MAX_LOGFILES][128] = {
28 "/RTS/log/trigger.log",
33 static FILE *files[MAX_LOGFILES] ;
35 static int oldsizes[MAX_LOGFILES] ;
51 init_pair(1,COLOR_BLACK,COLOR_WHITE);
52 init_pair(2,COLOR_CYAN,COLOR_WHITE);
53 init_pair(3,COLOR_MAGENTA,COLOR_WHITE);
54 init_pair(4,COLOR_MAGENTA,COLOR_YELLOW);
55 init_pair(5,COLOR_RED,COLOR_BLACK);
57 attron(COLOR_PAIR(1));
61 int main(
int argc,
char *argv[])
68 for (i=2; i<=argc; i++) {
69 if (strncmp(argv[i-1],
"-h",2)==0) {
71 printw(
"usage: logBrowser [-n ALARM_LEVEL] [file1 [,file2....]]\n\n\
72 ALARM_LEVEL={DEBug,NOTice,WARNing,ERRor,OPERator,CRITical,TERR}\n\
73 specifies the lowest level to be printed.\n\
74 Values of ALARM_LEVEL are not case sensitive.\n\
75 Values may be abbreviated as indicated in upper case.\n\
76 If no alarm level specified all messages will be displayed.\n\n\
77 Log files specified by filename[s] will be displayed.\n\
78 If none are specified, all log files will be shown.\n");
83 for (j=0,i=2; i<=argc; i++) {
84 if (strncasecmp(argv[i-1],
"-n",2)==0) {
85 strcpy(level_str,argv[i++]);
86 if (strncasecmp(level_str,
"DEB",3)==0) level = 0;
87 else if (strncasecmp(level_str,
"NOT",3)==0) level = 1;
88 else if (strncasecmp(level_str,
"WARN",4)==0) level = 2;
89 else if (strncasecmp(level_str,
"ERR",3)==0) level = 3;
90 else if (strncasecmp(level_str,
"OPER",4)==0) level = 4;
91 else if (strncasecmp(level_str,
"CRIT",4)==0) level = 5;
92 else if (strncasecmp(level_str,
"TERR",4)==0) level = 5;
96 strcpy(logfiles[j++],argv[i-1]);
101 if (j>0) logfiles[j][0] = 0;
103 printf(
"level=%d\n",level);
105 while (logfiles[j][0] != 0) {
106 printf(
"filename[%d]: %s\n",j,logfiles[j++]);
113 while(logfiles[i][0] != 0) {
115 files[i] = fopen(logfiles[i],
"r") ;
117 if(files[i] == NULL) {
118 perror(logfiles[i]) ;
126 if(has_colors() == FALSE) {
128 printf(
"This terminal does not support color: \n\
129 use /usr/dt/bin/dtterm -background white\n");
133 scrollok(stdscr,TRUE);
136 intrflush(stdscr,TRUE);
143 for(i=0;i<MAX_LOGFILES;i++) {
145 if(logfiles[i][0]==0) continue ;
148 fret = fgets(buff,
sizeof(buff),files[i]) ;
151 perror(logfiles[i]) ;
156 ret = stat(logfiles[i],&statb) ;
158 perror(logfiles[i]) ;
163 if(statb.st_size < oldsizes[i]) {
165 files[i] = fopen(logfiles[i],
"r") ;
170 oldsizes[i] = statb.st_size ;
177 if(strstr(buff,
": DEBUG:") != NULL) inlevel=0;
178 else if(strstr(buff,
": NOTICE:") != NULL) inlevel = 1;
179 else if(strstr(buff,
": WARNING:") != NULL) inlevel = 2;
180 else if(strstr(buff,
": ERROR:") != NULL) inlevel = 3;
181 else if(strstr(buff,
": OPERATOR:") != NULL) inlevel = 4;
182 else if(strstr(buff,
": TERR:") != NULL) inlevel = 5;
183 else if(strstr(buff,
": CRITICAL:") != NULL) inlevel = 5;
185 if (inlevel<level)
continue;
189 attron(COLOR_PAIR(1));
192 attron(COLOR_PAIR(1));
195 attron(COLOR_PAIR(2));
198 attron(COLOR_PAIR(3));
202 attron(COLOR_PAIR(4));
206 attron(COLOR_PAIR(5));
214 attron(COLOR_PAIR(1));
219 if(!data_in) sleep(1) ;