473,491 Members | 2,008 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

Jan 12 '06 #1
6 2391
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");

Jan 12 '06 #2
Ian
te******@gmail.com wrote:
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
Jan 12 '06 #3
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

Jan 12 '06 #4
"peggy83" <te******@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
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::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;
}
Jan 12 '06 #5

su*********@gmail.com 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

Jan 12 '06 #6
On 11 Jan 2006 23:19:43 -0800, te******@gmail.com wrote:
I was told that i need to open a log file and fprintf in each function


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
Jan 12 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4103
by: yanivmad | last post by:
hi I like to ask if there any option to control the html files?!? I have some HTML files at my web site that use one "Help.htm" file for all the pages {I use the "window.open(.... " option at...
9
13400
by: Charles F McDevitt | last post by:
I'm trying to upgrade some old code that used old iostreams. At one place in the code, I have a path/filename in a wchar_t string (unicode utf-16). I need to open an ifstream to that file. ...
6
55933
by: Dino Buljubasic | last post by:
My application creates some temporary files that are deleted when my application terminates. However, if a temp file is open, it will not be deleted and application will crash. How can I...
2
6099
by: Mattbooty | last post by:
Hello, Not sure if anyone else has seen this bug, but I have a form where the entire form is covered with a picturebox. The picturebox has a mouseup event. I also have an open file dialog for...
6
10016
by: qysbc | last post by:
I have a web page and there is a link to open a TIFF file. The way I do it is to have the server code open a binary stream, set the content type to "image/tiff" and call Response.BinaryWrite. On...
2
4383
by: OutdoorGuy | last post by:
Greetings, I have a "newbie" question in relation to opening files from C#. I have a Windows form where I allow the user to type in a file extension in a text box (e.g., "xls"). I then take...
6
3083
by: Moumen VB.NET 2003/2005 Developer | last post by:
How can I detect if a file sitting on a network drive is still open by another application? This application resides on another machine on the network? I am using VB.NET 2003 Your help is...
5
11162
by: Ryan Liu | last post by:
Hi, Both way works, I'd just ask some experts which way is better? My application creates a log file daily. Now each time when I write a log, I will open the file and append to the end....
6
34617
by: Ros | last post by:
There are 10 files in the folder. I wish to process all the files one by one. But if the files are open or some processing is going on them then I do not want to disturb that process. In that case...
0
2637
by: Ofelia | last post by:
Hi, I'm new to this forum and to Perl language but I would like to ask for your help. I'm working in Linux and the files I need to process are in the format “file.gz”. I created a script which...
0
7115
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7154
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7190
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6858
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4881
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4578
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3086
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1392
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
280
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.