Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old January 12th, 2006, 07:35 AM
teopeggy@gmail.com
Guest
 
Posts: n/a
Default how to open a log file?

hi,
i want to check whether each of my function in my system works or not.
I was told that i need to open a log file and fprintf in each function
to check whether each of my function works or not.
i don't know how to do that.
please guide me

thank you

regards
peggy

  #2  
Old January 12th, 2006, 07:45 AM
surendran.d@gmail.com
Guest
 
Posts: n/a
Default Re: how to open a log file?

i did get exactly what you are asking, your requirement may be like
this...

if( yourfuncttion() == RETURN_STATUS_FAIL)
fprintf(_log_file_ptr,"your function failed");
else
fprintf(_log_file_ptr,"keep going");

  #3  
Old January 12th, 2006, 08:15 AM
Ian
Guest
 
Posts: n/a
Default Re: how to open a log file?

teopeggy@gmail.com wrote:[color=blue]
> hi,
> i want to check whether each of my function in my system works or not.
> I was told that i need to open a log file and fprintf in each function
> to check whether each of my function works or not.
> i don't know how to do that.
> please guide me
>[/color]
You'd be better of with unit tests for your functions, then you wouldn't
have to read log files.

Ian
  #4  
Old January 12th, 2006, 09:15 AM
peggy83
Guest
 
Posts: n/a
Default Re: how to open a log file?

sorry i didnt define my question properly. I'm doing a directshow
transform filter (encoder and decoder) using directshow app filter
wizard and integrated with g729 speech codec for my final year project.
i need to check function by function to make sure each function works
well. so what should i do?
the application cannot use fprintf and string (it was shown
undeclared). any ways to solve?
i need to open a log file.

regards
peggy

  #5  
Old January 12th, 2006, 10:15 AM
Jim Langston
Guest
 
Posts: n/a
Default Re: how to open a log file?

"peggy83" <teopeggy@gmail.com> wrote in message
news:1137056445.410339.132820@z14g2000cwz.googlegr oups.com...[color=blue]
> sorry i didnt define my question properly. I'm doing a directshow
> transform filter (encoder and decoder) using directshow app filter
> wizard and integrated with g729 speech codec for my final year project.
> i need to check function by function to make sure each function works
> well. so what should i do?
> the application cannot use fprintf and string (it was shown
> undeclared). any ways to solve?
> i need to open a log file.
>
> regards
> peggy[/color]

if it's undeclared, you need to include the headers. std::string is
#include <string>
fprintf I'm not postive where it would be. Check your docs.

Why do you *need* to use fprintf? why can't you use iostreams? This is how
I do logging:

#include <string>
#include <fstream>

void LogMessage( const std::string& Message )
{
static std::ofstream LogFile("AbyssalLog.log");
if (LogFile.is_open())
{
LogFile << Message << std::endl;
}
}

Then when I want to send a log entry to my log I build it in a std::string
or use a constant.

std::string Temp = "Finished function: ThisFunc with return value: ";
Temp = Temp + StrmConvert<std::string>( ReturnVal );
LogMessage( Temp );

Or for simple entries:

LogMessage( "Finished function normally" );

The StrmConvert I use is like this:

#include <sstream>
template<typename T, typename F > T StrmConvert( F from )
{
std::stringstream temp;
temp << from;
T to = T();
temp >> to;
return to;
}


  #6  
Old January 12th, 2006, 12:45 PM
Marcelo Pinto
Guest
 
Posts: n/a
Default Re: how to open a log file?


surendran.d@gmail.com escreveu:
[color=blue]
> i did get exactly what you are asking, your requirement may be like
> this...
>
> if( yourfuncttion() == RETURN_STATUS_FAIL)
> fprintf(_log_file_ptr,"your function failed");
> else
> fprintf(_log_file_ptr,"keep going");[/color]

Note that error codes returned from functions may be ignored. I believe
the best way to treat errors in applications is using exceptions.

As other poster has pointed out, the best way to assure a function
works is to unit test it.

"Beware of bugs in the above code; I have only proved it correct, not
tried it" (Knuth)

HTH,

Marcelo Pinto

  #7  
Old January 12th, 2006, 02:15 PM
JustBoo
Guest
 
Posts: n/a
Default Re: how to open a log file?

On 11 Jan 2006 23:19:43 -0800, teopeggy@gmail.com wrote:
[color=blue]
>I was told that i need to open a log file and fprintf in each function[/color]

It is a good idea to ditch fprintf as soon as you can. :-)

A tutorial on iostreams that pretty much shows a simple log file:

http://www.cs.helsinki.fi/u/vihavain...iostreams.html

You'll have to think about how to modify it for you own use.

Good Luck
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles