943,902 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 426
  • C++ RSS
Jun 8th, 2009
0

Please Help me!! please!!!!

Expand Post »
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
alka123456 is offline Offline
3 posts
since Jun 2009
Jun 8th, 2009
0

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

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:
C++ Syntax (Toggle Plain Text)
  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.
C++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 185
Solved Threads: 28
Posting Whiz in Training
dwks is offline Offline
269 posts
since Nov 2005
Jun 8th, 2009
0

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

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
alka123456 is offline Offline
3 posts
since Jun 2009
Jun 8th, 2009
1

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

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.
Reputation Points: 185
Solved Threads: 28
Posting Whiz in Training
dwks is offline Offline
269 posts
since Nov 2005
Jun 8th, 2009
0

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

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
alka123456 is offline Offline
3 posts
since Jun 2009
Jun 8th, 2009
0

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

use a cout statement asking the user what type of severity they want like
c++ Syntax (Toggle Plain Text)
  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. }
Reputation Points: 215
Solved Threads: 186
Veteran Poster
NathanOliver is offline Offline
1,066 posts
since Apr 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Inserting unicode into console
Next Thread in C++ Forum Timeline: encrypting text speed





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC