Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to "verify" your details, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Entire forum
➜ Programming
➜ General
➜ The ellipsis & defines
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Nick Cash
USA (626 posts) Bio
|
Date
| Sat 18 Jun 2005 05:50 AM (UTC) |
Message
| Alright, I've been messing around with more stuff and decided to make an XML-style log generator. It works perfectly, but I'm lazy and so I would like to know the answer to this. All of this is in C by the way.
I have this function:
void log_entry( char *source_file, char *function, int line, const char *message, ... );
It is the main basis of the log as all log entries go through it. Anyways, typing out all of those paramaters is kind of annoying but I want them to be there. So, I made a macro:
#define L( function, linetext ) \
log_entry( __FILE__, (function), __LINE__, (linetext) )
This is a great time saver, however, it doesnt support the ellipsis. So I guess the question is this, can I make the define use/emulate the ellipsis? Or should I just go change the parameters of the function?
Also, if I change the paramaters, won't I lose the actual file and line # that the function call is comming from?
Thanks in advance :) |
~Nick Cash
http://www.nick-cash.com | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #1 on Sat 18 Jun 2005 05:59 AM (UTC) |
Message
| According to this page,
http://docs.hp.com/en/B3901-90007/ch10s15.html
you can use varargs in your macros under GNU like so:#define foo(f, s...) printf(f, s)
|
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Nick Cash
USA (626 posts) Bio
|
Date
| Reply #2 on Sat 18 Jun 2005 06:27 AM (UTC) |
Message
| Awesome, that did the trick. It turned out like:
#define L( function, linetext, s... ) \
log_entry( __FILE__, (function), __LINE__, (linetext), s )
Works perfectly. Thanks :) |
~Nick Cash
http://www.nick-cash.com | Top |
|
Posted by
| Nick Cash
USA (626 posts) Bio
|
Date
| Reply #3 on Mon 20 Jun 2005 06:24 PM (UTC) Amended on Mon 20 Jun 2005 06:25 PM (UTC) by Nick Cash
|
Message
| I made a static library out of this so I don't really have to bother with it again. It currently is Win32 only, but I'll port it over to *nix eventually.
Let me know if you would be interested in it at all :P
EDIT: I found the original version of this post rather vague. What I meant to say is I combined my logging functions that I use for nearly all of my programs (including the new XML-style one) into a library. If you want to see the code, use the library, or something else just send me an e-mail or something. If there is interest I can post it here too :) |
~Nick Cash
http://www.nick-cash.com | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #4 on Mon 20 Jun 2005 07:14 PM (UTC) |
Message
| Hmm... what exactly does this do? What kind of functionality does your library provide? :) |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Nick Cash
USA (626 posts) Bio
|
Date
| Reply #5 on Wed 22 Jun 2005 12:14 AM (UTC) Amended on Wed 22 Jun 2005 03:04 AM (UTC) by Nick Cash
|
Message
| It is a very small but useful library. It contains the primary logging functions I've used in basically all of my programs that need logging (save my mud, it already had lots of logging stuff :P).
Here is a little synopsis, taken from the README file:
The library sports two different but useful ways of logging information. The first way is basic. It provides a
chronological output of logs by number in a text document. It will append, putting several spaces and dash's between
each "new" block every time the program is run. All of your logs will be in one file.
The second is a little more complicated, but a bit more useful, organized, and has potential for easier analysis. It will tell the line number, function, file and message for each log entry. It will also display when the log was created, and list the time when each log was entered. They will all be put in seperate files, with an increasing numerical prefix. It is all formated in XML format.
To avoid crashes, if you log directory doesnt happen to exist, it will create it for you. Each logging function uses an ellipsis (...) to accept a variable number of arguments and slap them into your message for you, taking out the trouble of printing your own strings.
-------------
The code may at least be worth looking at, but I'm sure you all have your own logging functions and wouldn't really want to look as such an amature's code. :P
In any event, you can view the code exported as html at:
http://ew.xidus.net/download/xlib
Or, you can download the code, readme, and compiled -WIN32- library at:
http://ew.xidus.net/download/xlib/xlib.zip
I already see a few things I want to change, but for the most part thats it. If someone would like to compile the library on a *nix system and send me the code/lib that would be fantastic, as I have no idea if what I have in there works or not. |
~Nick Cash
http://www.nick-cash.com | Top |
|
Posted by
| Nick Cash
USA (626 posts) Bio
|
Date
| Reply #6 on Thu 30 Jun 2005 01:46 AM (UTC) |
Message
| The project is now updated a bit and hosted on source forge. You can find it at www.sourceforge.net/projects/xlib |
~Nick Cash
http://www.nick-cash.com | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
16,526 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top