473,388 Members | 1,557 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

turn off the log file

Hello

I am writing a big project, where I generate a log file.
However, I wonder whether there is some easy way that I could turn off
the log file.
Do I need to specify in every fprintf line like this
if(DEBUG)
fprintf(...);
end

Thanks a lot!

Nov 15 '05 #1
3 2230
po***********@gmail.com writes:
I am writing a big project, where I generate a log file.
However, I wonder whether there is some easy way that I could turn off
the log file.
Do I need to specify in every fprintf line like this
if(DEBUG)
fprintf(...);
end


Write a function that does that for you, then call it in place of
fprintf(). If you need help wrapping fprintf(), refer to the C
FAQ.

15.5: How can I write a function that takes a format string and a
variable number of arguments, like printf(), and passes them to
printf() to do most of the work?

A: Use vprintf(), vfprintf(), or vsprintf().

Here is an error() function which prints an error message,
preceded by the string "error: " and terminated with a newline:

#include <stdio.h>
#include <stdarg.h>

void error(char *fmt, ...)
{
va_list argp;
fprintf(stderr, "error: ");
va_start(argp, fmt);
vfprintf(stderr, fmt, argp);
va_end(argp);
fprintf(stderr, "\n");
}

See also question 15.7.

References: K&R2 Sec. 8.3 p. 174, Sec. B1.2 p. 245; ISO
Secs. 7.9.6.7,7.9.6.8,7.9.6.9; H&S Sec. 15.12 pp. 379-80; PCS
Sec. 11 pp. 186-7.

--
"I don't have C&V for that handy, but I've got Dan Pop."
--E. Gibbons
Nov 15 '05 #2
po***********@gmail.com wrote
(in article
<11*********************@z14g2000cwz.googlegroups. com>):
Hello

I am writing a big project, where I generate a log file.
However, I wonder whether there is some easy way that I could turn off
the log file.
Do I need to specify in every fprintf line like this
if(DEBUG)
fprintf(...);
end

Thanks a lot!


That's a good place to use a wrapper function. Simply take all
the conditional code for your enable/disable option (or better
yet, you might find long term that having levels of logging,
i.e. verbosity might be useful), then every place that you have
the above code, simply replace it with a call to the wrapper
function, then the behavior can be modified in only one place by
changing the setting(s) for log output.

there are also quite a few existing libraries to handle error
logging in creative ways if you don't want to reinvent the
wheel. Sourceforge is a good place to look.

--
Randy Howard (2reply remove FOOBAR)

Nov 15 '05 #3
po***********@gmail.com wrote:

Hello

I am writing a big project, where I generate a log file.
However, I wonder whether there is some easy way that I could turn off
the log file.
Do I need to specify in every fprintf line like this
if(DEBUG)
fprintf(...);
end


If this is to be done at compile-time, you can use a macro:

#if DEBUG
#define dbgprintf(args) fprintf args
#else
#define dbgprintf(args)
#endif

And then call it with:

dbgprintf((logfile,format,arg1,arg2,and_so_on));

If it's to be determined at runtime, check out vfprintf() as others have
pointed out.

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>

Nov 15 '05 #4

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

Similar topics

1
by: Peter Rilling | last post by:
When creating an MSI through VS.NET, does the setup project allow me the ability to turn anonymous off. Basically, my web app uses Windows Authentication, but the MSI turns both that and anonymous...
13
by: Csaba Gabor | last post by:
I'm not talking javascript hara-kiri here. I've got a database of web pages or snippets I've created and I'd like to display them in a table. So on my server (in PHP) I take all the files, and...
12
by: aeldaly | last post by:
Hello all, My shared server provider has register_globals on. I checked by running php_info(); from within a file. I would like to turn this off, but asking them to turn it off just for me will...
17
by: peter | last post by:
I just took over the website at work. I am still learning PHP. Register_globals are on and the script appears to be coded to take advantage of this. I know how to recode the script, but am unsure...
2
by: deko | last post by:
I want to turn error handling off, then back on in a sub routine that backs up a select set of documents. For some reason, I can't seem to get this to work - Private Sub BackupDocs() On Error...
3
by: ilushn | last post by:
Help! I am having a very aggervating problem with Access. Call me lazy, but I like to copy and paste addresses from Access into microsoft work, like for sending letters where I only need about 3...
2
by: Steve Franks | last post by:
According to the docs you tell ASP.NET to use cookieless sessions by setting a value in the config.web file. However, what if I wanted to determine at run time whether or not I wanted to use...
3
by: DC | last post by:
Hi, (ASP.Net 1.1) is it possible to (programmatically and globally) deactivate page fragment caching? We have only two scenarios, development stage where we want caching off and testing where we...
4
by: no_spam_for_gman | last post by:
Hi, I can turn off autocommit within the command window but I cannot figure out how to turn it off when you are in the IBM DB2 Command Line Processor. Does anybody knows how? By the way I mean...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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...

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.