version 1.1.2.1, 2011/11/23 08:50:38
|
version 1.1.2.2, 2011/11/23 14:51:14
|
Line 1
|
Line 1
|
#include "global.h" |
#include "global.h" |
|
|
|
|
|
/* |
|
* mqtt_rtlm_log() Log message |
|
* |
|
* @fmt = format string |
|
* @... = argument list |
|
* return: none |
|
*/ |
|
static void |
|
mqtt_rtlm_log(const char *fmt, ...) |
|
{ |
|
va_list lst; |
|
|
|
va_start(lst, fmt); |
|
vsyslog(LOG_ERR, fmt, lst); |
|
va_end(lst); |
|
} |
|
#define MQTT_RTLM_LOG() (mqtt_rtlm_log("Error:: System #%d - %s", errno, strerror(errno))) |
|
|
|
|
|
/* |
|
* mqtt_rtlm_open() Open log file |
|
* |
|
* @cfg = loaded config |
|
* return: NULL error or SQL handle |
|
*/ |
|
FILE * |
|
mqtt_rtlm_open(sl_config *cfg) |
|
{ |
|
FILE *f = NULL; |
|
const char *str = NULL; |
|
|
|
if (!cfg) |
|
return NULL; |
|
|
|
str = (const char*) cfg_GetAttribute(cfg, CFG("mqtt_log"), CFG("name")); |
|
if (!str) { |
|
mqtt_rtlm_log("Error:: Unknown file name ...\n"); |
|
return NULL; |
|
} |
|
|
|
if (!(f = fopen(str, "a"))) { |
|
MQTT_RTLM_LOG(); |
|
return NULL; |
|
} |
|
|
|
return f; |
|
} |
|
|
|
/* |
|
* mqtt_rtlm_close() Close log file |
|
* |
|
* @f = File handle |
|
* return: none |
|
*/ |
|
void |
|
mqtt_rtlm_close(FILE *f) |
|
{ |
|
if (f) |
|
fclose(f); |
|
} |