home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-01-15 | 3.2 KB | 99 lines | [TEXT/KAHL] |
-
- LogLib 1.0
-
- C routines to simplify the use of program logs.
-
- ©1994 by Dave Nebinger (dnebing@andy.bgsu.edu)
- All Rights Reserved.
-
- Feel free to use this where ever you wish, just drop me some email
- stating what you are doing with it.
-
-
-
- ==========
- Introduction
- ==========
-
- I don't know about the rest of ya, but I know that I for some things a log file comes in really handy.
- I mean, for testing background only apps, inits, etc., it is hard to come up with an alternative (besides
- dropping into MacsBug ;-) solution that will allow a programmer to see what's going on with the project.
-
- I am currently working on a project that runs in the background and uses mactcp. That's when I
- realized that I could really use a log file to track what was going on with the app. So I created this one.
-
- It is simply a set of routines to open and write to a log file in the system folder. Actually, the
- routine is set up to store the log in one of two places-the Preferences folder, or a folder of your
- desire within the Preferences folder.
-
- ==========
- Function Description
- ==========
-
- The functions are pretty simple, although you are required to include at least the "ansi-small"
- library.
-
- Boolean InitLog(Str255 fold,short* vref,long* pid,long* fid);
-
- InitLog should be called pretty early (I do it where after initializing the toolbox). It locates the
- Preferences folder in the system folder. If you also give a name to 'fold', then the function will also
- find the directory id for that folder (InitLog will create the folder if it doesn't already exist).
-
- short OpenLog(Str255 name,short vref,long did);
-
- OpenLog opens the log file with name 'name' and returns the file reference number. This is the
- number that is used in the rest of the functions. A -1 is returned if there is an error.
-
- Boolean Log(short,const char* fmt,...);
- Boolean LogTime(short,const char* fmt,...);
-
- These two functions work like fprintf. LogTime precedes the string that is going to print with
- the current date and time.
-
- void CloseLog(short);
-
- This function closes the log file.
-
- ==========
- Usage
- ==========
-
- The following is a very simple program which demonstrates how to use the log routines for two
- different log files.
-
- void main(){
- short vref; /* vol ref num */
- long pdir,fdir; /* preferences folder id, and my folder id */
- short fref1,fref2; /* file reference number */
-
- InitMacintosh(); /* init the mac toolbox */
- if (InitLog("\pTest Log ƒ",&vref,&pdir,&fdir)){ /* then we are set to continue... */
-
- fref1=OpenLog("\pLog File #1",vref,pdir); /* open a log file in the prefs folder */
- fref2=OpenLog("\pLog File #2",vref,fdir); /* open a log file in our created folder */
-
- if ((fref1!=-1)&&(fref2!=-1)){ /* then we can start logging */
-
- LogTime(fref1,"Demo Log Program Open. %c",kNewLine); /* \n is not good for some editors... */
- Log(fref1,"Welcome. %c%c",kNewLine,kNewLine);
-
- LogTime(fref2,"Shutting down now... %c",kNewLine);
-
- CloseLog(fref1);
- CloseLog(fref2);
- }
- }
- }
-
-
- ==========
- Finalè
- ==========
-
- Last but not least is the stuff the lawyers just love: use this at your own risk, I am not responsible,
- no warrantee is implied, etc. However, I am more than happy to discuss any problems that you might
- have with this source.
-
-
-
-