65 |
*/ |
*/ |
66 |
|
|
67 |
|
|
68 |
/* ------------------------------------------------------- Private variables */ |
/* ------------------------------------------------------------- Definitions */ |
69 |
|
|
70 |
|
|
71 |
|
#define MESSAGE_SIZE 1024 |
72 |
static FILE *LOG= NULL; |
static FILE *LOG= NULL; |
73 |
static char time_str[STRLEN]; |
static char time_str[STRLEN]; |
74 |
|
|
111 |
|
|
112 |
|
|
113 |
/** |
/** |
114 |
* Log a message to monits logfile or syslog |
* Log a message to monits logfile or syslog. If a TTY exist the log |
115 |
|
* message is also sent to stderr. |
116 |
* @param format A formated (printf-style) string to log |
* @param format A formated (printf-style) string to log |
117 |
*/ |
*/ |
118 |
void log_log(const char *format, ...) { |
void log_log(const char *format, ...) { |
119 |
|
|
120 |
va_list ap; |
va_list ap; |
121 |
char msg[STRLEN]; |
char msg[MESSAGE_SIZE]; |
122 |
|
|
123 |
ASSERT(format); |
ASSERT(format); |
124 |
|
|
125 |
va_start(ap,format); |
va_start(ap,format); |
126 |
vsnprintf(msg, STRLEN, format, ap); |
vsnprintf(msg, MESSAGE_SIZE, format, ap); |
127 |
va_end(ap); |
va_end(ap); |
128 |
|
|
129 |
if(! Run.dolog) goto nolog; |
if(! Run.dolog) goto nolog; |
162 |
|
|
163 |
if(LOG && (0 != fclose(LOG))) { |
if(LOG && (0 != fclose(LOG))) { |
164 |
|
|
165 |
error("%s: Error closing the log file -- %s\n", |
log("%s: Error closing the log file -- %s\n", |
166 |
prog, STRERROR); |
prog, STRERROR); |
167 |
|
|
168 |
} |
} |
190 |
|
|
191 |
if((LOG= fopen(Run.logfile,"a+")) == (FILE *)NULL) { |
if((LOG= fopen(Run.logfile,"a+")) == (FILE *)NULL) { |
192 |
|
|
193 |
error("%s: Error opening the log file '%s' for writing -- %s\n", |
log("%s: Error opening the log file '%s' for writing -- %s\n", |
194 |
prog, Run.logfile, STRERROR); |
prog, Run.logfile, STRERROR); |
195 |
|
|
196 |
return(FALSE); |
return(FALSE); |