473,396 Members | 1,998 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,396 software developers and data experts.

Regarding log file

23
Hi All,
Could u please help to create a log file for my c++ file read/write operation.
In my project i have written a file main.cpp and file.cpp.
file .cpp implements read/write opeartion for a file. How to create alog file for this which will be display all debuging information during debugging.

suppose there is file named file1.cpp
my question is this log file will take the same file1.cpp file to display the login implementation or it will create another file to store login implementation.

Please reply me as soon as possible with the code itself...
please give me some code on log file.


Advance Thanks to All.
Oct 31 '08 #1
4 1511
donbock
2,426 Expert 2GB
Are you talking about sprinkling calls to some log-write function throughout your code; or are you talking about some built-in log feature available in your run-time environment (such as a debugger)?

If you're using your own log-write function then you can be confident that the log information will only be written to the file you explicitly open. However, you may elect to use one of the built-in files: stdin, stdout, or stderr. You don't have to open or close these standard files; and most shells allow you to redirect to a file.

You should consider whether built-in macros __LINE__, __FILE__, __TIME__, or __DATE__ have a place in your log messages.

After you're done debugging don't go back and delete all your log calls. Instead, find an easily reversible way to convert them into no-ops. The log invocations document something about what your code isn't supposed to do; maintenance programmers may find that insight helpful. Besides, you may want to debug later changes to this program sometime in the future. It would be nice if you could change one line and turn all the logging back on.

Have you considered using assert instead of a roll-your-own log utility?

If you're ambitious, you might consider a printf-style variable argument list for your write-log function. If so, then you should take a look at <stdarg.h> and vfprintf. On the other hand, if you're having trouble with the basic log capability then don't stir in variable arguments until after you've figured out the basic capability. You don't want to have too many balls in the air.

Do you have a multi-tasking or multi-threaded application? If so, then logging can become much trickier because you can get the log message for a higher priority thread appearing in the middle of the log message for a lower priority thread. In this case you may want to put the code that writes to the log file in a separate task and queue log messages to it from the other tasks. This is more of a client-server model.

This is not meant to be a site that merely does your coding for you. Besides, you haven't specified your needs well enough -- we would have to guess what is most important for you in a debugging message. Better for you to work this through yourself -- nobody knows what information is most helpful for debugging than you.
Oct 31 '08 #2
AmeL
15
In the log file, there should be included :
- date of logging
- file : in what file that produces the log ?
- function : in what function ?
- line : the line number
- debug level : in which level is this log ?
- status : success... failed, ... error code ...etc
- desc : the error description.
This is the incomplete sample code to log something:
Expand|Select|Wrap|Line Numbers
  1. Full code removed, please read posting guidelines
  2.  
We need to have debug level because each level could state something about the bug clearer and clearer.
the function entry and exit is the good habit of programming, because it will facilitate the task of debugging through the code.

Thanks
/AmeL
Nov 1 '08 #3
donbock
2,426 Expert 2GB
What follows illustrates one way to remove all logging from production code while keeping the ability to quickly reinstall the logging facility during development. This is a compile-time mechanism; you may prefer a run-time mechanism that leaves the debug code present.
Expand|Select|Wrap|Line Numbers
  1. full code removed, please read posting guidelines
Nov 1 '08 #4
mamul
23
Thanks to All, Now I have got some Idea about log file. Thank u.
Nov 3 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Robert M | last post by:
Hello, I actually have a couple of questions regarding this project. First, I have a pretty good understanding of SQL code. I use to work with dBase III and IV. I now work with Access 97 and...
0
by: Milsnips | last post by:
Hi there, i've created an ASP.NEt (VB) website application and had a few questions regarding the DLL file it creates. 1. Firstly, on occasions when i switch from debug to release, i have...
1
by: Terrance | last post by:
I was wondering if someone can help me with my question regarding the configuration system functionality in the .NET Framework 2.0 for VB. My question is, if I have a application configuration...
5
by: archana | last post by:
Hi all, I am having confusion regarding localization in .net. I have one form on which i have some labels and button. After designing that form what i did is set localization property of form...
9
by: KarlM | last post by:
After reading some articles regarding confuguration data I'm a bit confused. Where is the right place for storing configuration data? - XML-files? - registry? - INI-files? (from a users point...
10
by: sam_cit | last post by:
Hi Everyone, I had a doubt regarding extern decleration, i tried this is one source file, extern int sample; extern int sample; int main() {
1
by: archana | last post by:
Hi all, I am new to asp.net. I am having one confusion regarding application_onstart event. Let me explain what i am doing:- Say i have one xml file whose setting i am reading on...
1
by: archana | last post by:
Hi all, I am new to asp.net. I have one question regarding code- behind model. I have written page_load event in code behind as well as in aspx page. Means i am doing mixing of code-behind...
1
by: njames | last post by:
i have some doubts regarding bash scripting , 1) i need to display permission of a given file in the following format : Owner : Read Write Group :
4
by: mpatharkar | last post by:
Hi all, I wrote a script to search a pattern in input file and if pattern does not found in input file ,print that pattern in to output file. The input file is...
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
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.