/[monit]/monit/log.c
ViewVC logotype

Diff of /monit/log.c

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

revision 1.8 by martinp, Tue Feb 11 21:27:39 2003 UTC revision 1.9 by hauk, Tue Apr 29 21:28:53 2003 UTC
# Line 52  Line 52 
52  #include "monitor.h"  #include "monitor.h"
53    
54    
 /* Private variables */  
 static FILE *LOG= NULL;  
 static char time_str[STRLEN];  
   
 /* Private prototypes */  
 static int  open_log();  
 static char *timestr(void);  
   
   
55  /**  /**
56   *  Implementation of a logger that appends log messages to a file   *  Implementation of a logger that appends log messages to a file
57   *  with a preceding timestamp. Methods support both syslog or own   *  with a preceding timestamp. Methods support both syslog or own
# Line 74  static char *timestr(void); Line 65  static char *timestr(void);
65   */   */
66    
67    
68    /* ------------------------------------------------------- Private variables */
69    
70    
71    static FILE *LOG= NULL;
72    static char time_str[STRLEN];
73    
74    
75    /* -------------------------------------------------------------- Prototypes */
76    
77    
78    static int  open_log();
79    static char *timestr(void);
80    
81    
82  /* ------------------------------------------------------------------ Public */  /* ------------------------------------------------------------------ Public */
83    
84    
# Line 110  int log_init() { Line 115  int log_init() {
115   */   */
116  void log(const char *format, ...) {  void log(const char *format, ...) {
117        
   char msg[STRLEN];  
118    va_list ap;    va_list ap;
119      char msg[STRLEN];
120    
121    ASSERT(format);    ASSERT(format);
122        
# Line 126  void log(const char *format, ...) { Line 131  void log(const char *format, ...) {
131      syslog(LOG_ERR|LOG_USER, "%s", msg);      syslog(LOG_ERR|LOG_USER, "%s", msg);
132            
133    } else if(LOG) {    } else if(LOG) {
134        
135      fprintf(LOG,"[%s] %s", timestr(), msg);      fprintf(LOG,"[%s] %s", timestr(), msg);
     fflush(LOG);  
136            
137    }    }
138    
# Line 166  void log_close() { Line 170  void log_close() {
170  }  }
171    
172    
 /**  
  * @return the log filedescriptor or -1 if it's not open, i.e. syslog  
  * is used or logging is not activated  
  */  
 int get_log_fd() {  
   
   return (LOG!=NULL?fileno(LOG):-1);  
   
 }  
   
   
173  /* ----------------------------------------------------------------- Private */  /* ----------------------------------------------------------------- Private */
174    
175    
# Line 201  static int open_log() { Line 194  static int open_log() {
194        return(FALSE);        return(FALSE);
195                
196      }      }
197        
198        /* Set logger in unbuffered mode */
199        setvbuf(LOG, NULL, _IONBF, 0);
200    
201    }    }
202    
203    return TRUE;    return TRUE;
# Line 216  static int open_log() { Line 212  static int open_log() {
212  static char *timestr() {  static char *timestr() {
213    
214    time_t now;    time_t now;
215      struct tm tm;
216        
217    time(&now);    time(&now);
218    if(!strftime(time_str, STRLEN, TIMEFORMAT, localtime(&now))) {    if(!strftime(time_str, STRLEN, TIMEFORMAT, localtime_r(&now, &tm))) {
219            
220      memset(time_str, 0, STRLEN);      memset(time_str, 0, STRLEN);
221    

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26