Please Help me!! please!!!!

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2009
Posts: 3
Reputation: alka123456 is an unknown quantity at this point 
Solved Threads: 0
alka123456 alka123456 is offline Offline
Newbie Poster

Please Help me!! please!!!!

 
0
  #1
Jun 8th, 2009
I have got a log file as follows

The log file has the following format : Date/Time, Severity, Module(the number after the process name is the process id) and finally the diagnostic message as an example :
 
dd/mm/yyyy HH:mm:ss.mmm  Severity               Module                                             Message
=======================   ========           ======                                              =======
17-11-2008 17:01:17.590                SUCCESS              wmlumberjack.exe:940 System Information.     CPU speed

17-11-2008 17:01:22.090                INFORMATION                winword.exe:3656 CWSWordAddIn::OnConnection.\WSWordAddIn.cpp(131) :  -> VDEtart

I need to write a code in C++ that is able to filter and display the results based on the severity selected by the user. As an example if the user selects to see only WARNINGS, the application should only display the lines in the log file that contain the WARNING attribute.
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 251
Reputation: dwks has a spectacular aura about dwks has a spectacular aura about 
Solved Threads: 25
dwks's Avatar
dwks dwks is offline Offline
Posting Whiz in Training

Re: Please Help me!! please!!!!

 
0
  #2
Jun 8th, 2009
Well, that's not too difficult. You could open the file, read it line-by-line, and print only those lines which contain the word "WARNING", for example. If you wanted to be more robust, you could separate out the column and compare that.

Some code that may help:
  1. std::string text = "A message of some sort.";
  2. if(text.find("message")) {
  3. std::cout << "The string contains the word 'message'\n";
  4. }
And for columns, you could use stringstreams.
  1. #include <sstream> // for stringstreams
  2.  
  3. std::string line; // this is read from a file
  4. std::istringstream stream(line);
  5. std::string col1, col2, col3;
  6. stream >> col1 >> col2 >> col3;
  7. if(col3 == "WARNING") /* ... */

[edit] By the way, don't say "URGENT HELP NEEDED IMMEDIATELY PLZ!!!!!111" in the title. It's not going to make people read it any faster. [/edit]
Last edited by dwks; Jun 8th, 2009 at 6:23 pm.
dwk

Seek and ye shall find.

"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.

"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison

"The only real mistake is the one from which we learn nothing."
-- John Powell
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 3
Reputation: alka123456 is an unknown quantity at this point 
Solved Threads: 0
alka123456 alka123456 is offline Offline
Newbie Poster

Re: Please Help me!! please!!!!

 
0
  #3
Jun 8th, 2009
Thanks for your reply!! I am just a beginner....Can I know more in detail about the answer......
Last edited by alka123456; Jun 8th, 2009 at 6:43 pm.
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 251
Reputation: dwks has a spectacular aura about dwks has a spectacular aura about 
Solved Threads: 25
dwks's Avatar
dwks dwks is offline Offline
Posting Whiz in Training

Re: Please Help me!! please!!!!

 
1
  #4
Jun 8th, 2009
I've really told you all you need to know. I'll give you some more details, but you'll have to do some searching . . . .

Three steps.
  1. Open the file. You use ifstream to do this, it's not hard. http://www.cplusplus.com/reference/i...ream/ifstream/
  2. Read lines from the file, one at a time. Use getline() for this.
  3. If the line has "WARNING", print it. I showed you how to do this in the previous post.
dwk

Seek and ye shall find.

"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.

"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison

"The only real mistake is the one from which we learn nothing."
-- John Powell
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 3
Reputation: alka123456 is an unknown quantity at this point 
Solved Threads: 0
alka123456 alka123456 is offline Offline
Newbie Poster

Re: Please Help me!! please!!!!

 
0
  #5
Jun 8th, 2009
But how do I capture input from the user to select the severity???

the log file looks somewhat like below!!


dd/mm/yyyy HH:mm:ss.mmm  Severity               Module                                             Message
=======================   ========           ======                                              =======
17-11-2008 17:01:17.590                SUCCESS              wmlumberjack.exe:940 System Information.     CPU speed

17-11-2008 17:01:22.090                INFORMATION                winword.exe:3656 CWSWordAddIn::OnConnection.\WSWordAddIn.cpp(131) :  -> VDEtart

17-11-2008 17:01:23.996                WARNING           winword.exe:3656 Workshare Failed to query Installation Validation value!

17-11-2008 17:01:45.903                ERROR                  winword.exe:664 WordCustomProperty      .\WordCustomProperty.cpp(81) :  -> GetCustomProperty
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 219
Reputation: NathanOliver is an unknown quantity at this point 
Solved Threads: 37
NathanOliver's Avatar
NathanOliver NathanOliver is offline Offline
Posting Whiz in Training

Re: Please Help me!! please!!!!

 
0
  #6
Jun 8th, 2009
use a cout statement asking the user what type of severity they want like
  1. //...
  2. std::string choice;
  3. cout << "Please enter the severity you want.\n";
  4. cout << "Your choices are: warning, success, information, and error: ";
  5. cin >> choice
  6. //...
  7. }
if you write using namespace std; you do not need to write std::something in your program.
If your thread is solved please mark it as solved
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC