home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 7 / FreshFishVol7.bin / bbs / comm / cyberpager-1.5.lha / CyberPager / source / library / log.c < prev    next >
Text File  |  1994-02-07  |  3KB  |  106 lines

  1. void __saveds __asm ULogA(register __a0 PagerHandle_t * ph, register __d0 LONG level, register __a1 STRPTR fmt, register __a2 LONG *args)
  2. {
  3.     BPTR loghandle = NULL;
  4.     struct DateTime dat;
  5.     UBYTE Date[LEN_DATSTRING + 1];
  6.     UBYTE Time[LEN_DATSTRING + 1];
  7.     BOOL didLock = FALSE;
  8.     STRPTR logFilename;
  9.  
  10.     if (level > ph->ph_LogLevel)
  11.         return;
  12.  
  13.     DateStamp(&dat.dat_Stamp);
  14.  
  15.     dat.dat_Format = FORMAT_DOS;
  16.     dat.dat_Flags = 0;
  17.     dat.dat_StrDay = NULL;
  18.     dat.dat_StrDate = Date;
  19.     dat.dat_StrTime = Time;
  20.  
  21.     memset(Date, 0, LEN_DATSTRING + 1);
  22.     memset(Time, 0, LEN_DATSTRING + 1);
  23.     DateToStr(&dat);
  24.  
  25.     ObtainSemaphore(&ph->ph_Sema);
  26.  
  27.     if (ph->ph_LogRetries++ == 0) {
  28.         if (LockFile(ph, "LOG-UPDATE")) {
  29.             didLock = TRUE;
  30.             if (logFilename = FindPagerConfig(ph, "LOGFILE")) {
  31.                 loghandle = Open(logFilename, MODE_READWRITE);
  32.  
  33.                 /*
  34.                  * we don't actually call
  35.                  * FreePagerConfig(logFilename) here.  this
  36.                  * way, the config entry will remain loaded
  37.                  * in memory and any subsequent calls the
  38.                  * client makes to ULog will not have to
  39.                  * re-read the config file to find out where
  40.                  * the log file is located.  when the client
  41.                  * calls FreePagerHandle() the config entry
  42.                  * for the logfile name will finally go away.
  43.                  */
  44.             }
  45.             else if (logFilename = NameInSpool(ph, "LOGFILE")) {
  46.                 loghandle = Open(logFilename, MODE_READWRITE);
  47.                 FreeNameInSpool(logFilename);
  48.             }
  49.         }
  50.     }
  51.  
  52.     if (loghandle) {
  53.         Seek(loghandle, 0, OFFSET_END);
  54.  
  55.         FPrintf(loghandle, "(%s %s) %s,%s,%s ", Date, Time, ph->ph_LogProgram, ph->ph_LogService, ph->ph_LogWho);
  56.         VFPrintf(loghandle, fmt, args);
  57.         FPutC(loghandle, '\n');
  58.     }
  59.  
  60.     if (--ph->ph_LogRetries == 0) {
  61.         if (loghandle)
  62.             Close(loghandle);
  63.  
  64.         if (didLock)
  65.             UnLockFile(ph, "LOG-UPDATE");
  66.     }
  67.  
  68.     ReleaseSemaphore(&ph->ph_Sema);
  69. }
  70.  
  71. void ULog(PagerHandle_t * ph, LONG level, STRPTR fmt,...)
  72. {
  73.     va_list args;
  74.  
  75.     va_start(args, fmt);
  76.     ULogA(ph, level, fmt, (LONG *)args);
  77.     va_end(args);
  78. }
  79.  
  80. void __saveds __asm SetLogLevel(register __a0 PagerHandle_t * ph, register __d0 LONG level)
  81. {
  82.     ObtainSemaphore(&ph->ph_Sema);
  83.  
  84.     ph->ph_LogLevel = level;
  85.  
  86.     ReleaseSemaphore(&ph->ph_Sema);
  87. }
  88.  
  89. void __saveds __asm SetLogService(register __a0 PagerHandle_t * ph, register __a1 STRPTR serviceName)
  90. {
  91.     ObtainSemaphore(&ph->ph_Sema);
  92.  
  93.     ph->ph_LogService = (serviceName ? serviceName : "-");
  94.  
  95.     ReleaseSemaphore(&ph->ph_Sema);
  96. }
  97.  
  98. void __saveds __asm SetLogWho(register __a0 PagerHandle_t * ph, register __a1 STRPTR whoName)
  99. {
  100.     ObtainSemaphore(&ph->ph_Sema);
  101.  
  102.     ph->ph_LogWho = (whoName ? whoName : "-");
  103.  
  104.     ReleaseSemaphore(&ph->ph_Sema);
  105. }
  106.