home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume9 / pc-mail-nfs / syslog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-26  |  2.6 KB  |  134 lines

  1. /*++
  2. /* NAME
  3. /*    syslog 3
  4. /* SUMMARY
  5. /*    surrogate BSD4.3 syslog facility
  6. /* PROJECT
  7. /*    pc-mail
  8. /* PACKAGE
  9. /*    nfs
  10. /* SYNOPSIS
  11. /*    include "syslog.h"
  12. /*
  13. /*    openlog(name, logopt, facility)
  14. /*    char *name;
  15. /*    int logopt;
  16. /*    int facility;
  17. /*
  18. /*    syslog(priority, format, arguments)
  19. /*    int priority;
  20. /*    char *format;
  21. /*
  22. /*    closelog()
  23. /* DESCRIPTION
  24. /*    These functions emulate the BSD4.3 syslog(3) facility. Output is
  25. /*    written to a system logfile (default /usr/spool/mqueue/syslog).
  26. /*    That file should have mode 666 (i.e. read/write access permitted
  27. /*    for everyone).
  28. /*
  29. /*    syslog() tries to output the log entry as one big chunk.
  30. /* FILES
  31. /*    /usr/spool/mqueue/syslog, system logfile
  32. /* SEE ALSO
  33. /*    percentm(3), interprets "%m" sequences in syslog format strings.
  34. /* BUGS
  35. /*    The functions use the stdio package. This may cause the program to
  36. /*    grow unexpectedly.
  37. /* AUTHOR(S)
  38. /*    Wietse Z. Venema
  39. /*    Eindhoven University of Technology
  40. /*    Department of Mathematics and Computer Science
  41. /*    Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
  42. /* CREATION DATE
  43. /*    Sun Oct 29 15:12:57 MET 1989
  44. /* LAST MODIFICATION
  45. /*    10/29/89 22:58:33
  46. /* VERSION/RELEASE
  47. /*    1.2
  48. /*--*/
  49.  
  50. #ifndef SYSLOG
  51.  
  52. #ifndef lint
  53. static char sccsid[] = "@(#) syslog.c 1.2 10/29/89 22:58:33";
  54.  
  55. #endif
  56.  
  57. #include <stdio.h>
  58. #include <varargs.h>
  59. #include <time.h>
  60. #include "percentm.h"
  61.  
  62. extern struct tm *localtime();
  63. extern char *asctime();
  64. extern long time();
  65. extern int errno;
  66.  
  67. #ifndef SYSLOGFILE
  68. #define    SYSLOGFILE    "/usr/spool/mqueue/syslog"
  69. #endif
  70.  
  71. static char *logname;
  72.  
  73. /* openlog - initialize syslog facility; ignores all but the "name" argument */
  74.  
  75. /* ARGSUSED */
  76.  
  77. openlog(name, logopt, facility)
  78. char   *name;
  79. int     logopt;
  80. int     facility;
  81. {
  82.     logname = name;                /* ignore rest */
  83. }
  84.  
  85. /* syslog - append entry to system log */
  86.  
  87. /* VARARGS */
  88.  
  89. syslog(va_alist)
  90. va_dcl
  91. {
  92.     va_list ap;
  93.     char   *fmt;
  94.     char   *percentm();
  95.     long    secs;
  96.     char   *date;
  97.     FILE   *fp;
  98.     int     err = errno;
  99.     static char buf[BUFSIZ];
  100.  
  101.     if (fp = fopen(SYSLOGFILE, "a")) {
  102.  
  103.     /* Format the time stamp */
  104.  
  105.     secs = time((long *) 0);
  106.     date = asctime(localtime(&secs));
  107.     (void) sprintf(buf, "%2.2s-%3.3s-%2.2s %8.8s %s: ",
  108.                date + 8, date + 4, date + 22, date + 11, logname);
  109.  
  110.     /* Format the actual message */
  111.  
  112.     va_start(ap);
  113.     (void) va_arg(ap, int);            /* skip priority */
  114.     fmt = va_arg(ap, char *);
  115.     (void) vsprintf(buf + strlen(buf), percentm(fmt, err), ap);
  116.     va_end(ap);
  117.  
  118.     /* Try to ouput the log entry as one big chunk */
  119.  
  120.     (void) fprintf(fp, "%s\n", buf);
  121.     (void) fclose(fp);
  122.     }
  123. }
  124.  
  125. /* closelog - a real dummy */
  126.  
  127. closelog()
  128. {
  129.     /* no-op */
  130. }
  131.  
  132. #endif                    /* SYSLOG */
  133.  
  134.