home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / lib / dial / d_log.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-10-02  |  4.6 KB  |  213 lines

  1. # include  "util.h"
  2. # include  "d_returns.h"
  3. # include  <stdio.h>
  4. # include  "d_proto.h"
  5. # include  "d_structs.h"
  6. # include  "ll_log.h"
  7.  
  8.  
  9. int  d_debug;           /*  set to non-zero if debug loggin should be done  */
  10.  
  11. static struct ll_struct *d_logptr;       /*  file pointer to logging file  */
  12.  
  13.  
  14. /*
  15.  *     D_OPNLOG
  16.  *
  17.  *     this routine is called to open the log file for appending.  the
  18.  *     date is written as the first entry.
  19.  *
  20.  *     filename -- path name of the logging file
  21.  */
  22.  
  23. d_opnlog(logptr)
  24.   struct ll_struct * logptr;
  25.     {
  26.  
  27.     d_logptr =(struct ll_struct *) (logptr);           /* save the pointer */
  28.  
  29.     if (d_logptr -> ll_level >= LLOGPTR)
  30.     d_debug = 1;
  31.     return(D_OK);
  32. }
  33.  
  34.  
  35. /*
  36.  *     D_CLSLOG
  37.  *
  38.  *     this routine is called to close the log file if one was open.
  39.  */
  40.  
  41. d_clslog()
  42.     {
  43.  
  44. #ifdef D_DBGLOG
  45.     d_dbglog("d_clslog", "closing log file");
  46. #endif D_DBGLOG
  47.  
  48.     if (d_logptr) {
  49.     ll_close(d_logptr);
  50.     d_logptr = (struct ll_struct *) 0;
  51.     }
  52.  
  53.     return(D_OK);
  54. }
  55.  
  56. /*
  57.  *     D_LOG
  58.  *
  59.  *     this routine writes entries on the log file.  its use is similar
  60.  *     to printf, and it accepts the same style format strings.
  61.  *
  62.  *     routine -- the name of the subroutine where the call to this function
  63.  *                is made.
  64.  *
  65.  *     format -- printf style format string
  66.  *
  67.  *     a, b, c, d, ... -- variables to be printed
  68.  */
  69.  
  70. /* VARARGS2 */
  71.  
  72. d_log(routine, format, a, b, c, d, e, f, g, h)
  73.   char  *routine, *format;
  74.   unsigned  a, b, c, d, e, f, g, h;
  75.     {
  76.  
  77. #ifdef D_LOG
  78. #ifdef D_DBGLOG
  79.     if (d_debug)        /*  print routine name if debugging  */
  80.     d_dbglog (routine, format, a, b, c, d, e, f, g, h);
  81.     else
  82. #endif D_DBGLOG
  83.     ll_log(d_logptr, LLOGGEN, format, a, b, c, d, e, f, g, h);
  84. #endif D_LOG
  85.  
  86.     return(D_OK);
  87. }
  88.  
  89. /*
  90.  *     D_DBGLOG
  91.  *
  92.  *     this routine is called to write debugging logging stuff on the log
  93.  *     file.  the entry is made only if the 'd_debug' variable is non-zero.
  94.  *
  95.  *     routine -- the name of the subroutine where the call to this function
  96.  *                is made.
  97.  *
  98.  *     format -- printf style format string
  99.  *
  100.  *     a, b, c, d, ... -- variables to be printed
  101.  */
  102.  
  103. /* VARARGS2 */
  104.  
  105. d_dbglog(routine, format, a, b, c, d, e, f, g, h)
  106.   char  *routine, *format;
  107.   unsigned  a, b, c, d, e, f, g, h;
  108.     {
  109. #ifdef D_DBGLOG
  110.     char fmtbuf[64];
  111.  
  112.     if (d_debug)
  113.     {
  114.     sprintf (fmtbuf, "%s%s", "%s: ", format);
  115.     ll_log(d_logptr, LLOGBTR, fmtbuf, routine, a, b, c, d, e, f, g, h);
  116.     }
  117. #endif D_DBGLOG
  118. }
  119.  
  120.  
  121.  
  122. /*
  123. /*
  124.  *     D_FILLOG
  125.  *
  126.  *     routine which is used to log messages concerning things found in
  127.  *     files.  the point of this routine is that there are a lot of messages
  128.  *     in this package that concern errors found on lines in files.  i got
  129.  *     tired of putting stuff in the format to 'd_log' calls to write out
  130.  *     the file name and line number, so i put that in this call.  all this
  131.  *     routine does is build a special format string containg fields for the
  132.  *     name and number, and then call 'd_log'.
  133.  *
  134.  *     filename -- name of the file to be put in entry
  135.  *
  136.  *     linenum -- line number in file to be put in entry
  137.  *
  138.  *     routine -- the name of the subroutine where the call to this function
  139.  *                is made.
  140.  *
  141.  *     format -- printf style format string
  142.  *
  143.  *     a, b, c, d, ... -- variables to be printed
  144.  */
  145.  
  146. /* VARARGS4 */
  147.  
  148. d_fillog(filename, linenum, routine, format, a, b, c, d, e, f, g, h)
  149.   char  *filename, *routine, *format;
  150.   unsigned  linenum, a, b, c, d, e, f, g, h;
  151.     {
  152. #ifdef D_LOG
  153.     char  tmpfmt[85];
  154.  
  155.     /*  if a filename is given, make a new format to include
  156.      *  it.  then call the log routine.
  157.      */
  158.  
  159.     if (filename)
  160.     {
  161.     sprintf (tmpfmt, "%s%s", "%s, line %d: ", format);
  162.     d_log(routine, tmpfmt, filename, linenum, a, b, c, d, e, f, g, h);
  163.     }
  164.     else
  165.     d_log(routine, format, a, b, c, d, e, f, g, h);
  166. #endif D_LOG
  167. }
  168.  
  169.  
  170.  
  171.  
  172. /*
  173.  *    D_PLOG
  174.  *
  175.  *    Log a message at a given priority.
  176.  *    It is necessary to have this here so as to access the
  177.  *    struct d_logptr.
  178.  *
  179.  *    priority - the priority level to log at.
  180.  *    format, a, b, ... - standard printf stuff
  181.  *
  182. */
  183.  
  184. d_plog (priority, format, a, b, c, d, e, f, g, h)
  185.   int priority;
  186.   char *format;
  187.   unsigned a, b, c, d, e, f, g, h;
  188.     {
  189.  
  190.     ll_log (d_logptr, priority, format, a, b, c, d, e, f, g, h);
  191. }
  192.  
  193. /*
  194.  *    D_PELOG
  195.  *
  196.  *    Log a message at a given priority and print ERRNO
  197.  *    It is necessary to have this here so as to access the
  198.  *    struct d_logptr.
  199.  *
  200.  *    priority - the priority level to log at.
  201.  *    format, a, b, ... - standard printf stuff
  202.  *
  203. */
  204.  
  205. d_pelog (priority, format, a, b, c, d, e, f, g, h)
  206.   int priority;
  207.   char *format;
  208.   unsigned a, b, c, d, e, f, g, h;
  209.     {
  210.  
  211.     ll_err (d_logptr, priority, format, a, b, c, d, e, f, g, h);
  212. }
  213.