380 TPtrC8 SearchBuf; |
380 TPtrC8 SearchBuf; |
381 TInt aCount[8]; |
381 TInt aCount[8]; |
382 aCount[0]=0; |
382 aCount[0]=0; |
383 TInt posI(0); |
383 TInt posI(0); |
384 |
384 |
385 // retrive log message: |
385 // retrive log message: |
386 // Retrive common part of log message: |
386 // Retrive common part of log message: |
387 for(TInt i = 1; i<6; i++) |
387 TInt i=0; |
|
388 for(i=1; i<6; i++) |
388 { |
389 { |
389 SearchBuf.Set(aPtr.Mid(posI)); |
390 SearchBuf.Set(aPtr.Mid(posI)); |
390 aCount[i]=SearchBuf.Find(KSeperation8)+posI; |
391 aCount[i]=SearchBuf.Find(KSeperation8)+posI; |
391 posI=aCount[i]+3; |
392 posI=aCount[i]+3; |
392 if(aCount[i]<aCount[i-1]) |
393 if(aCount[i]<aCount[i-1]) |
393 { |
394 { |
394 delete pBuf1; |
395 delete pBuf1; |
395 return; // wrong format string from client |
396 return; // wrong format string from client |
396 } |
397 } |
397 } |
398 } |
398 // seperating common log message and extra log fields will be easy for future maintaince. |
399 // seperating common log message and extra log fields will be easy for future maintaince. |
399 TLogField8* alogField = new TLogField8[6]; // the common part of log message for both |
400 TLogField8* alogField = new TLogField8[6]; // the common part of log message for both |
400 // with and without extra log fields |
401 // with and without extra log fields |
401 if(!alogField) |
402 if(!alogField) |
402 { |
403 { |
403 delete pBuf1; |
404 delete pBuf1; |
404 return; // no memory |
405 return; // no memory |
405 } |
406 } |
406 |
407 |
407 TLogField8* extralogField=NULL; // only applied to extra log fields |
408 TLogField8* extralogField=NULL; // only applied to extra log fields |
408 |
409 |
409 TInt alength=0; // a length of array of extra log fields |
410 TInt alength=0; // a length of array of extra log fields |
410 |
411 |
426 if(aCount[6]<posI) // no addtional fields. Find return value is KErrNotFound or >0 |
427 if(aCount[6]<posI) // no addtional fields. Find return value is KErrNotFound or >0 |
427 { |
428 { |
428 alogField[5].iLogValue8.Copy(aPtr.Mid(aCount[5]+3,aDes.Length()-aCount[5]-5)); |
429 alogField[5].iLogValue8.Copy(aPtr.Mid(aCount[5]+3,aDes.Length()-aCount[5]-5)); |
429 } |
430 } |
430 else |
431 else |
431 { |
432 { |
432 alogField[5].iLogValue8.Copy(aPtr.Mid(aCount[5]+3,aCount[6]-aCount[5]-5)); |
433 alogField[5].iLogValue8.Copy(aPtr.Mid(aCount[5]+3,aCount[6]-aCount[5]-5)); |
433 posI=aCount[6]+45; //45 is from the length of long string and a tab |
434 posI=aCount[6]+45; //45 is from the length of long string and a tab |
434 SearchBuf.Set(aPtr.Mid(posI)); |
435 SearchBuf.Set(aPtr.Mid(posI)); |
435 aCount[7]=SearchBuf.Find(_L8("\r\n"))+posI; |
436 aCount[7]=SearchBuf.Find(_L8("\r\n"))+posI; |
436 TLex8 lex(aPtr.Mid(posI,aCount[7]-posI)); // get the length |
437 TLex8 lex(aPtr.Mid(posI,aCount[7]-posI)); // get the length |
437 TInt err=lex.Val(alength); |
438 TInt err=lex.Val(alength); |
438 if (err) alength=0; // ignor the extra log fields. Let the log go |
439 if (err) |
|
440 alength=0; // ignor the extra log fields. Let the log go |
439 |
441 |
440 // Retrive the extra log fields |
442 // Retrive the extra log fields |
441 extralogField = new TLogField8[alength]; |
443 extralogField = new TLogField8[alength]; |
442 if(!extralogField) |
444 if(!extralogField) |
443 { |
445 { |
444 delete pBuf1; |
446 delete pBuf1; |
445 return; // no memory |
447 return; // no memory |
446 } |
448 } |
447 for(TInt i=0; i<alength; i++) |
449 for(TInt i=0; i<alength; i++) |
448 { |
450 { |
449 aCount[6]=aCount[7]+2; |
451 aCount[6]=aCount[7]+2; |
450 SearchBuf.Set(aPtr.Mid(aCount[6])); |
452 SearchBuf.Set(aPtr.Mid(aCount[6])); |
451 aCount[7]=SearchBuf.Find(_L8("\t"))+aCount[6]; |
453 aCount[7]=SearchBuf.Find(_L8("\t"))+aCount[6]; |
453 aCount[6]=aCount[7]+1; |
455 aCount[6]=aCount[7]+1; |
454 SearchBuf.Set(aPtr.Mid(aCount[6])); |
456 SearchBuf.Set(aPtr.Mid(aCount[6])); |
455 aCount[7]=SearchBuf.Find(_L8("\r\n"))+aCount[6]; |
457 aCount[7]=SearchBuf.Find(_L8("\r\n"))+aCount[6]; |
456 extralogField[i].iLogValue8.Copy(aPtr.Mid(aCount[6],aCount[7]-aCount[6])); |
458 extralogField[i].iLogValue8.Copy(aPtr.Mid(aCount[6],aCount[7]-aCount[6])); |
457 } |
459 } |
458 } |
460 } |
459 |
461 // Start to organize an XML format: |
460 // Start to organize an XML format: |
462 TInt afileSize; |
461 TInt afileSize; |
463 _LIT(KLogMutex, "LoggingServerMutex"); |
462 _LIT(KLogMutex, "LoggingServerMutex"); |
464 RMutex mutex; |
463 RMutex mutex; |
465 TInt r = mutex.CreateGlobal(KLogMutex); |
464 TInt r = mutex.CreateGlobal(KLogMutex); |
466 if(r==KErrAlreadyExists) |
465 if(r==KErrAlreadyExists) |
467 r = mutex.OpenGlobal(KLogMutex); |
466 r = mutex.OpenGlobal(KLogMutex); |
468 |
467 |
469 if(!r) |
468 if(!r) mutex.Wait(); // if still failed, let logging go |
470 mutex.Wait(); // If still failed, let logging go without bother the mutex. |
469 //without bother the mutex |
471 iLogFile.Size(afileSize); |
470 |
472 if(afileSize<12) // 12 is from charters of "\r\n</LOGFILE>" |
471 iLogFile.Size(afileSize); |
473 //It shoud happened once at the beginning of the file |
472 if(afileSize<12) // 12 is from charters of "\r\n</LOGFILE>" |
474 // such as overwrite mode |
473 //It shoud happened once at the beginning of the file |
475 { |
474 // such as overwrite mode |
476 afileSize=12; // used for lock position |
475 { |
477 alogbuf.Copy(KxmlHeader); |
476 afileSize=12; // used for lock position |
478 } |
477 alogbuf.Copy(KxmlHeader); |
479 alogbuf.Append(_L8("\r\n<MESSAGE>\r\n")); |
478 } |
480 for(TInt i=0; i<6; i++) |
479 alogbuf.Append(_L8("\r\n<MESSAGE>\r\n")); |
481 { |
480 for(TInt i=0; i<6; i++) |
482 alogbuf.Append(_L8(" <")); |
481 { |
483 alogbuf.Append(alogField[i].iLogTag8); |
482 alogbuf.Append(_L8(" <")); |
484 alogbuf.Append(_L8(">")); |
483 alogbuf.Append(alogField[i].iLogTag8); |
485 alogbuf.Append(alogField[i].iLogValue8); |
484 alogbuf.Append(_L8(">")); |
486 alogbuf.Append(_L8("</")); |
485 alogbuf.Append(alogField[i].iLogValue8); |
487 alogbuf.Append(alogField[i].iLogTag8); |
486 alogbuf.Append(_L8("</")); |
488 alogbuf.Append(_L8(">\r\n")); |
487 alogbuf.Append(alogField[i].iLogTag8); |
489 } |
488 alogbuf.Append(_L8(">\r\n")); |
490 for(TInt i=0; i<alength; i++) |
489 } |
491 { |
490 for(TInt i=0; i<alength; i++) |
492 alogbuf.Append(_L8(" <")); |
491 { |
493 alogbuf.Append(extralogField[i].iLogTag8); |
492 alogbuf.Append(_L8(" <")); |
494 alogbuf.Append(_L8(">")); |
493 alogbuf.Append(extralogField[i].iLogTag8); |
495 alogbuf.Append(extralogField[i].iLogValue8); |
494 alogbuf.Append(_L8(">")); |
496 alogbuf.Append(_L8("</")); |
495 alogbuf.Append(extralogField[i].iLogValue8); |
497 alogbuf.Append(extralogField[i].iLogTag8); |
496 alogbuf.Append(_L8("</")); |
498 alogbuf.Append(_L8(">\r\n")); |
497 alogbuf.Append(extralogField[i].iLogTag8); |
499 } |
498 alogbuf.Append(_L8(">\r\n")); |
500 |
499 } |
501 alogbuf.Append(_L8("</MESSAGE>")); |
500 |
502 alogbuf.Append(_L8("\r\n</LOGFILE>")); |
501 alogbuf.Append(_L8("</MESSAGE>")); |
503 |
502 alogbuf.Append(_L8("\r\n</LOGFILE>")); |
504 iLogFile.Write(afileSize-12, alogbuf,iStatus); |
503 |
505 |
504 iLogFile.Write(afileSize-12, alogbuf,iStatus); |
506 if(!r) |
505 |
507 { |
506 |
508 mutex.Signal(); |
507 if(!r) |
509 mutex.Close(); |
508 { |
510 } |
509 mutex.Signal(); |
511 |
510 mutex.Close(); |
512 if(extralogField) |
511 } |
513 delete[] extralogField; |
512 |
514 |
513 if(extralogField) delete[] extralogField; |
|
514 delete[] alogField; |
515 delete[] alogField; |
515 delete pBuf1; |
516 delete pBuf1; |
516 |
|
517 } |
517 } |
518 |
518 |
519 void CLogFileControl::WriteTxt(const TDesC8 &aDes) |
519 void CLogFileControl::WriteTxt(const TDesC8 &aDes) |
520 /** |
520 /** |
521 * @param aDes - send a aDes string in xml format to a log file |
521 * @param aDes - send a aDes string in xml format to a log file |