/[LeafOK_CVS]/lbbs/src/log.c
ViewVC logotype

Diff of /lbbs/src/log.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.5 by sysadm, Thu Oct 21 17:28:46 2004 UTC Revision 1.10 by sysadm, Sat May 7 12:08:28 2005 UTC
# Line 15  Line 15 
15   *                                                                         *   *                                                                         *
16   ***************************************************************************/   ***************************************************************************/
17    
18  #include "common.h"  #include "io.h"
19    #include <stdio.h>
20    #include <stdarg.h>
21    #include <sys/types.h>
22    #include <time.h>
23    #include <unistd.h>
24    
25  FILE *fp_log_std;  FILE *fp_log_std;
26  FILE *fp_log_err;  FILE *fp_log_err;
# Line 52  log_head (char *buf) Line 57  log_head (char *buf)
57  {  {
58    time_t t;    time_t t;
59    char s_time[256];    char s_time[256];
60    t = time(0);    t = time (0);
61      
62    strftime(s_time,256,"%Y-%m-%d %H:%M:%S", localtime (&t));    strftime (s_time, 256, "%Y-%m-%d %H:%M:%S", localtime (&t));
63    sprintf(buf,"[%s] [%d] ", s_time, getpid());    sprintf (buf, "[%s] [%d] ", s_time, getpid ());
64      
65    return 0;    return 0;
66  }  }
67    
68  int  int
69  log_std (char *msg)  log_std (const char *format, ...)
70  {  {
71      va_list args;
72      int retval;
73    char buf[1024];    char buf[1024];
74    
75    if (fp_log_std == NULL)    log_head (buf);
76      {    strcat (buf, format);
       perror ("log_std failed\n");  
       return -1;  
     }  
77    
78    log_head(buf);    va_start (args, format);
79      retval = vfprintf (fp_log_std, buf, args);
80      va_end (args);
81    
82    strcat(buf,msg);    fflush (fp_log_std);
     
   if (fprintf (fp_log_std, buf)<0)  
     {  
       perror ("log_std failed\n");  
       return -2;  
     }  
83    
84    fflush(fp_log_std);    return retval;
     
   return 0;  
85  }  }
86    
87  int  int
88  log_error (char *error_msg)  log_error (const char *format, ...)
89  {  {
90      va_list args;
91      int retval;
92    char buf[1024];    char buf[1024];
     
   if (fp_log_err == NULL)  
     {  
       perror ("log_error failed\n");  
       return -1;  
     }  
93    
94    log_head(buf);    log_head (buf);
95      strcat (buf, format);
96    
97    strcat(buf,error_msg);    va_start (args, format);
98      retval = vfprintf (fp_log_err, buf, args);
99      va_end (args);
100    
101    if (fprintf (fp_log_err, buf)<0)    fflush (fp_log_err);
     {  
       perror ("log_error failed\n");  
       return -2;  
     }  
     
   fflush(fp_log_err);  
102    
103    return 0;    return retval;
104  }  }
105    
106  int  int
107  log_std_redirect(int fd)  log_std_redirect (int fd)
108  {  {
109    int ret;    int ret;
110    close (fileno(fp_log_std));    close (fileno (fp_log_std));
111    ret =  dup2(fd, fileno(fp_log_std));    ret = dup2 (fd, fileno (fp_log_std));
112    return ret;    return ret;
113  }  }
114    
115  int  int
116  log_err_redirect(int fd)  log_err_redirect (int fd)
117  {  {
118    int ret;    int ret;
119    close (fileno(fp_log_err));    close (fileno (fp_log_err));
120    ret =  dup2(fd, fileno(fp_log_err));    ret = dup2 (fd, fileno (fp_log_err));
121    return ret;    return ret;
122  }  }


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1