Autor
|
Tema: lectura de archivo log (Leído 2,194 veces)
|
falconez
Desconectado
Mensajes: 18
|
Saludos colegas, estamos trabajando con archivos log en la clase de estructura de datos I. Quisiera que me ayuden con lo siguiente o en la medida que me instruyan por donde iniciar:
a) Separar la siguiente información del archivo log y guardarlo con el tipo de dato corespondiente: - número de response (int) - número de error (int) - descripción de error (string) - duración (float) b) analizar la información de forma automatizada.
//Codigo..
// reading a text file
#include <iostream> #include <fstream> #include <string>
using namespace std;
int main () { int n; string line; string miString; ifstream myfile ("server.log"); int pos1,pos2; string keyWord="Response"; if (myfile.is_open()) { while ( getline (myfile,line) ) { pos1=keyWord.size()+1; pos2=line.find("is")-pos1; miString=line.substr(pos1,pos2); cout << miString<<endl; } myfile.close(); }
else cout << "Unable to open file"; cin>>n;
return 0; }
|
|
|
En línea
|
|
|
|
falconez
Desconectado
Mensajes: 18
|
Estos son los datos del archivo que se encuentra en un blog de notas con el nombre de server .
Response 1 is 404 Not Found 2.18215255113 Response 2 is 403 Forbidden 2.26763021468 Response 3 is 404 Not Found 2.33495629299 Response 4 is 500 Internal Server Error 2.36216646568 Response 5 is 404 Not Found 2.28467301475 Response 6 is 200 OK 2.51252629856 Response 7 is 403 Forbidden 2.53327963339 Response 8 is 404 Not Found 2.59052736148 Response 9 is 500 Internal Server Error 2.57947678727 Response 10 is 500 Internal Server Error 2.62752342443 Response 11 is 500 Internal Server Error 2.64897579748 Response 12 is 403 Forbidden 2.65486788506 Response 13 is 404 Not Found 2.65107549674 Response 14 is 403 Forbidden 2.74509725589 Response 15 is 404 Not Found 2.76358073552 Response 16 is 200 OK 2.80669946869 Response 17 is 404 Not Found 2.84176860831 Response 18 is 200 OK 2.88630060295 Response 19 is 500 Internal Server Error 2.90985599844 Response 20 is 500 Internal Server Error 2.9408316656 Response 21 is 404 Not Found 3.01666606941 Response 22 is 200 OK 3.00221646789 Response 23 is 200 OK 3.01853175258 Response 24 is 200 OK 2.91152911196 Response 25 is 404 Not Found 2.92699483994 Response 26 is 404 Not Found 2.9775314943 Response 27 is 404 Not Found 3.0996019781 Response 28 is 403 Forbidden 3.12478345427 Response 29 is 500 Internal Server Error 3.15060151962 Response 30 is 403 Forbidden 3.09040879164 Response 31 is 500 Internal Server Error 3.26880387837 Response 32 is 403 Forbidden 3.24752814016 Response 33 is 404 Not Found 3.37521310284 Response 34 is 200 OK 3.34696374722 Response 35 is 403 Forbidden 3.52306858089 Response 36 is 200 OK 3.43269316523 Response 37 is 404 Not Found 3.59172805672 Response 38 is 200 OK 3.58130454177 Response 39 is 200 OK 3.41331126685 Response 40 is 200 OK 3.59973513856 Response 41 is 404 Not Found 3.62253070824 Response 42 is 403 Forbidden 3.55266880468 Response 43 is 200 OK 3.70031318039 Response 44 is 403 Forbidden 3.60381866595 Response 45 is 200 OK 3.73013654113 Response 46 is 500 Internal Server Error 3.70903996368 Response 47 is 404 Not Found 3.72525006413 Response 48 is 404 Not Found 3.79505792731 Response 49 is 403 Forbidden 3.76930783134 Response 50 is 404 Not Found 3.58576235822 Response 51 is 200 OK 3.85826032645 Response 52 is 404 Not Found 3.79772524096 Response 53 is 404 Not Found 3.72015633191 Response 54 is 500 Internal Server Error 3.9423695011 Response 55 is 403 Forbidden 3.95291781091 Response 56 is 500 Internal Server Error 4.0034159531 Response 57 is 500 Internal Server Error 3.90237513202 Response 58 is 403 Forbidden 4.0572035682 Response 59 is 500 Internal Server Error 4.01729524064 Response 60 is 403 Forbidden 4.05338922819 Response 61 is 404 Not Found 4.05376535648 Response 62 is 403 Forbidden 4.07787274555 Response 63 is 200 OK 4.12324272842 Response 64 is 404 Not Found 4.15763801152 Response 65 is 500 Internal Server Error 4.03833874715 Response 66 is 403 Forbidden 4.15498245917 Response 67 is 200 OK 4.13095690656 Response 68 is 404 Not Found 4.15652964799 Response 69 is 403 Forbidden 4.22503672128 Response 70 is 200 OK 4.28022316231 Response 71 is 200 OK 4.2895415921 Response 72 is 500 Internal Server Error 4.32488536515 Response 73 is 200 OK 4.22187453171 Response 74 is 500 Internal Server Error 4.391903894 Response 75 is 200 OK 4.47607788055 Response 76 is 403 Forbidden 4.30543895266 Response 77 is 200 OK 4.31199745078 Response 78 is 404 Not Found 4.36488453104 Response 79 is 200 OK 4.46471195531 Response 80 is 403 Forbidden 4.50806163202 Response 81 is 403 Forbidden 4.51641471534 Response 82 is 404 Not Found 4.51922084838 Response 83 is 200 OK 4.44710070556 Response 84 is 403 Forbidden 4.38802000513 Response 85 is 403 Forbidden 4.57591973771 Response 86 is 500 Internal Server Error 4.56086299655 Response 87 is 200 OK 4.39997349446 Response 88 is 500 Internal Server Error 4.63538869629 Response 89 is 500 Internal Server Error 4.53786882767 Response 90 is 200 OK 4.60711212603 Response 91 is 500 Internal Server Error 4.50191246421 Response 92 is 403 Forbidden 4.53951792 Response 93 is 404 Not Found 4.71621255561 Response 94 is 403 Forbidden 4.63630409715 Response 95 is 200 OK 4.62253416646 Response 96 is 500 Internal Server Error 4.77026889961 Response 97 is 500 Internal Server Error 4.59704293806 Response 98 is 403 Forbidden 4.82036201944 Response 99 is 404 Not Found 4.72658365918 Response 100 is 404 Not Found 4.70105790343 Response 101 is 200 OK 4.72844680611 Response 102 is 200 OK 4.9248681917 Response 103 is 500 Internal Server Error 4.96596199497 Response 104 is 200 OK 4.97202651675 Response 105 is 403 Forbidden 4.87009250921 Response 106 is 404 Not Found 5.03543703617 Response 107 is 403 Forbidden 4.93077538882 Response 108 is 200 OK 4.90175222061 Response 109 is 403 Forbidden 5.02320719418 Response 110 is 404 Not Found 4.86466163497 Response 111 is 200 OK 5.0099545142 Response 112 is 403 Forbidden 4.90250389105 Response 113 is 403 Forbidden 4.94187908115 Response 114 is 403 Forbidden 4.94418674207 Response 115 is 404 Not Found 4.98927589831 Response 116 is 200 OK 5.015974504 Response 117 is 404 Not Found 5.12586574538 Response 118 is 200 OK 5.16414567155 Response 119 is 200 OK 5.16098879506 Response 120 is 500 Internal Server Error 5.26775957961 Response 121 is 403 Forbidden 5.15255988271 Response 122 is 500 Internal Server Error 5.13485178425 Response 123 is 404 Not Found 5.12900015656 Response 124 is 200 OK 5.19342789485 Response 125 is 403 Forbidden 5.29236887691 Response 126 is 404 Not Found 5.34631404723 Response 127 is 500 Internal Server Error 5.47691136209 Response 128 is 500 Internal Server Error 5.40820309084 Response 129 is 403 Forbidden 5.31099839074 Response 130 is 200 OK 5.48930210784 Response 131 is 500 Internal Server Error 5.4020563667 Response 132 is 500 Internal Server Error 5.4532232201 Response 133 is 403 Forbidden 5.56283660482 Response 134 is 403 Forbidden 5.42059227775 Response 135 is 404 Not Found 5.59566196313 Response 136 is 404 Not Found 5.39384112271 Response 137 is 403 Forbidden 5.6763370235 Response 138 is 200 OK 5.65820652312 Response 139 is 404 Not Found 5.7170268225 Response 140 is 404 Not Found 5.65347751877 Response 141 is 500 Internal Server Error 5.58035891828 Response 142 is 500 Internal Server Error 5.69242542966 Response 143 is 403 Forbidden 5.81294216822 Response 144 is 500 Internal Server Error 5.697196129 Response 145 is 403 Forbidden 5.69473690467 Response 146 is 200 OK 5.89358310753 Response 147 is 200 OK 5.83633760758 Response 148 is 200 OK 5.79453188172 Response 149 is 403 Forbidden 5.84867766826 Response 150 is 200 OK 5.78563671391 Response 151 is 200 OK 5.80839804165 Response 152 is 200 OK 5.91438862818 Response 153 is 404 Not Found 5.87257960155 Response 154 is 403 Forbidden 6.39677777676 Response 155 is 403 Forbidden 6.13773543282 Response 156 is 200 OK 6.08321711684 Response 157 is 404 Not Found 6.2053273258 Response 158 is 500 Internal Server Error 6.17810959214 Response 159 is 500 Internal Server Error 6.10754107641 Response 160 is 500 Internal Server Error 6.13849349162 Response 161 is 404 Not Found 6.23015273276 Response 162 is 404 Not Found 6.1744651153 Response 163 is 500 Internal Server Error 6.1589040252 Response 164 is 500 Internal Server Error 6.28303482337 Response 165 is 403 Forbidden 6.3539270056 Response 166 is 404 Not Found 6.39187358615 Response 167 is 404 Not Found 6.31995143338 Response 168 is 404 Not Found 6.35607466793 Response 169 is 403 Forbidden 6.50213061065 Response 170 is 403 Forbidden 6.47797388984 Response 171 is 404 Not Found 6.45094930432 Response 172 is 500 Internal Server Error 6.44425333807 Response 173 is 403 Forbidden 6.5802806677 Response 174 is 500 Internal Server Error 6.66404474751 Response 175 is 200 OK 6.645834027 Response 176 is 403 Forbidden 6.62449694542 Response 177 is 200 OK 6.72168805442 Response 178 is 403 Forbidden 6.85379446431 Response 179 is 404 Not Found 6.79413104466 Response 180 is 404 Not Found 6.83641675713 Response 181 is 403 Forbidden 6.90013833702 Response 182 is 403 Forbidden 6.85987752438 Response 183 is 403 Forbidden 6.94343457217 Response 184 is 404 Not Found 6.84696653055 Response 185 is 200 OK 6.91044051592 Response 186 is 404 Not Found 6.91581205703 Response 187 is 404 Not Found 6.97728132756 Response 188 is 500 Internal Server Error 7.04124412126 Response 189 is 404 Not Found 7.0108581909 Response 190 is 404 Not Found 7.00839057592 Response 191 is 404 Not Found 7.01514156291 Response 192 is 404 Not Found 7.10264873733 Response 193 is 403 Forbidden 7.10091132287 Response 194 is 500 Internal Server Error 7.10105206671 Response 195 is 404 Not Found 7.22345838225 Response 196 is 200 OK 7.26092373578 Response 197 is 500 Internal Server Error 7.22499923812 Response 198 is 404 Not Found 7.24524086088 Response 199 is 200 OK 7.45339890171 Response 200 is 500 Internal Server Error 7.57587571846
|
|
|
En línea
|
|
|
|
flony
Desconectado
Mensajes: 584
|
haber si entiendo, en el server.log se encuentra esta información a) Separar la siguiente información del archivo log y guardarlo con el tipo de dato correspondiente: - número de response (int) - número de error (int) - descripción de error (string) - duración (float) lo cual de leer el modelo de .log es así. ahora la parte que no entiendo b) analizar la información de forma automatizada. ¿que quieres decir con eso?, ¿que resultado debería dar ?, ¿como debería quedar? lo compile en visual c++ y funciona, la macana que lo único que sale por pantalla es 1 2 3 4 5 6 7....200 pero descendiendo Saludos colegas, estamos trabajando con archivos log en la clase de estructura de datos I ¿necesitas incluirlo en una estructura?, ¿una clase?, ¿debe generar otro archivo .log?
|
|
« Última modificación: 14 Enero 2014, 06:56 am por flony »
|
En línea
|
si un problema no tiene solucion entonces no es un problema...es algo inevitable
|
|
|
falconez
Desconectado
Mensajes: 18
|
Muchas gracias por interesarse en el tema. Ya solucione la lectura de archivo.log por medio de una lista doble. Les adjunto el codigo .. y cualquier duda seguir comentado que estamos para aportar en el grupo. Muchas Gracias y bendiciones.
#include <iostream> #include <fstream> #include <string> #include <cstdlib> using namespace std; struct datos { //Variables para mi archivo log, en la funcion abrir hago las respectivas conversiones de datos. int num; int error; int descrip; int tiempo; }; struct node { datos data; node *left; node *right; }; //FUNCIONES DE MI LISTA DOBLE node * newList(); node * insert_right(node *list, node data); //Trabajando con mi archivo log int getPosition(string linea,int opcion,int ini); void abrir(); void analisis(); //FUNCION PRINCIPAL int main(void) { node *head = newList(); node *current = head; cout<<endl<<"\t\t\t\t"<<"ARCHIVO LOG"<<endl<<endl<<endl; abrir(); //Abriendo y leyendo mi archivo log cout<<endl<<endl; cout<<endl<<"Ingrese el numero de respuesta a analizar: "; analisis(); //Realizando el analisis respectivo de mi N.Response return 0; } node * newList() { node *nuevo; nuevo = new node; nuevo->data.num = -1; nuevo->right = nuevo; nuevo->left = nuevo; return nuevo; } node * insert_right(node *list, node data) { node *nuevo; nuevo = new node; nuevo->data = data.data; nuevo->left = list; nuevo->right = list->right; list->right = nuevo; nuevo->right->left = nuevo; return nuevo; } //Obteniendo la posicion de los datos del .log int getPosition(string linea,int opcion,int ini){ int r;
switch(opcion) { case 1: r = linea.find("is") + 2;break; case 2: r=linea.find(" ",ini);break; case 3: for(int i=linea.length();1;--i) { if(linea==' ') { r=i; return r; } } } return r; } void abrir() { node *current; ifstream myfile ("server.log"); string line; string word1 = "Response"; int n_error; string error; string descrip; string numero; string tiempo;
//Posiciones de los Datos de mi .log int p1, p2,p3,p4,p5; //En cada uno de mis node guardo los datos correspondientes a mi archivo .log node myData1; node myData2; node myData3; node myData4; if (myfile.is_open()) { while ( !myfile.eof() ) { getline(myfile, line); //Encontrar los numeros p1 = word1.size()+1; p2 =getPosition(line,1,0); // equivalente a -----> line.find("is") - p1; p3=p2+2; p4=getPosition(line,2,p3); p5=getPosition(line,3,0); numero=line.substr(p1,p2-p1); error=line.substr(p3,p4-p3); descrip=line.substr(p4,p5-p4); tiempo=line.substr(p5,100); if( (myData1.data.num = atoi(line.c_str())) && (myData1.data.error = atoi(line.c_str())) ){ numero = myData1.data.num; current = insert_right(current, myData1); error= myData2.data.error; current = insert_right(current, myData2); } if( (myData3.data.descrip = atoi(line.c_str())) && (myData4.data.tiempo = atoi(line.c_str())) ){ descrip=myData3.data.descrip; current = insert_right(current, myData3); tiempo= myData4.data.tiempo; current = insert_right(current, myData4); } cout<<word1<<" "<<numero<<" "<<error<<" "<<descrip<<" "<<tiempo<<endl; } myfile.close(); } else cout << "Unable to open file"; } void analisis() { node *current; ifstream myfile ("server.log"); string line; //constante "response" string word1 = "Response"; //Datos del archivo log int n_response; string error; string descrip; string numero; string tiempo; //posiciones respectivamente de cada Dato int p1, p2,p3,p4,p5; if (myfile.is_open()) { cin>>n_response; //ingresar el numero de response para mostrar el analisis completo de la linea cout<<endl; while ( !myfile.eof() ) { getline(myfile, line);
//Encontrar los numeros p1 = word1.size(); //p1 = word1.size()+1; p2 =getPosition(line,1,0); p3=p2+2; p4=getPosition(line,2,p3); p5=getPosition(line,3,0); numero=line.substr(p1,p2-p1); error=line.substr(p3,p4-p3); descrip=line.substr(p4,p5-p4); tiempo=line.substr(p5,100); //BUSCAR POR RESPONSE if(atoi(numero.c_str())== n_response) { //cout<<word1<<" "<<numero<<" "<<error<<" "<<descrip<<" "<<tiempo<<endl; cout<<"\t"<<word1<<" "<<numero<<":"<<endl<<endl; cout<<"\tError: "<<error<<endl; cout<<"\tTipo de error: "<<descrip<<endl; cout<<"\tTiempo de respuesta: "<<tiempo<<endl<<endl<<endl; } } myfile.close(); } else cout << "Unable to open file"; }
//PD. No se olviden que este codigo lee el archivo .log que coleque antes en referencia. Y tambien realizo un analisis de la linea del archivo.
|
|
|
En línea
|
|
|
|
|
Mensajes similares |
|
Asunto |
Iniciado por |
Respuestas |
Vistas |
Último mensaje |
|
|
foto lectura, y lectura veloz, scanning y otros metodos de lectura rapida....
Foro Libre
|
Kase
|
3
|
13,004
|
4 Febrero 2014, 08:47 am
por camilo_
|
|
|
Lectura y modificacion de archivo
Programación C/C++
|
m@o_614
|
9
|
3,962
|
12 Septiembre 2013, 15:40 pm
por rir3760
|
|
|
Lectura de una matriz en un archivo
Programación C/C++
|
deibenK
|
1
|
1,603
|
13 Mayo 2014, 23:00 pm
por MeCraniDOS
|
|
|
Lectura de archivo log, error al eliminar IPs duplicadas!
Programación C/C++
|
falconez
|
0
|
1,705
|
8 Junio 2015, 04:31 am
por falconez
|
|
|
consulta lectura desde archivo
Programación C/C++
|
oskrg55
|
4
|
2,666
|
12 Agosto 2015, 23:14 pm
por oskrg55
|
|