how to open a log file?

T

teopeggy

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
 
S

surendran.d

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");
 
I

Ian

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
You'd be better of with unit tests for your functions, then you wouldn't
have to read log files.

Ian
 
P

peggy83

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
 
J

Jim Langston

peggy83 said:
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

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::eek:fstream 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;
}
 
M

Marcelo Pinto

(e-mail address removed) escreveu:
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");

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top