version 1.1.2.2, 2011/11/23 14:51:14
|
version 1.3, 2012/07/03 09:02:50
|
Line 1
|
Line 1
|
#include "global.h" |
#include "global.h" |
|
|
|
|
|
extern char *__progname; |
|
|
|
|
/* |
/* |
* mqtt_rtlm_log() Log message |
* mqtt_rtlm_log() Log message |
* |
* |
Line 27 mqtt_rtlm_log(const char *fmt, ...)
|
Line 30 mqtt_rtlm_log(const char *fmt, ...)
|
* return: NULL error or SQL handle |
* return: NULL error or SQL handle |
*/ |
*/ |
FILE * |
FILE * |
mqtt_rtlm_open(sl_config *cfg) | mqtt_rtlm_open(cfg_root_t *cfg) |
{ |
{ |
FILE *f = NULL; |
FILE *f = NULL; |
const char *str = NULL; |
const char *str = NULL; |
Line 35 mqtt_rtlm_open(sl_config *cfg)
|
Line 38 mqtt_rtlm_open(sl_config *cfg)
|
if (!cfg) |
if (!cfg) |
return NULL; |
return NULL; |
|
|
str = (const char*) cfg_GetAttribute(cfg, CFG("mqtt_log"), CFG("name")); | str = cfg_getAttribute(cfg, "mqtt_log", "name"); |
if (!str) { |
if (!str) { |
mqtt_rtlm_log("Error:: Unknown file name ...\n"); |
mqtt_rtlm_log("Error:: Unknown file name ...\n"); |
return NULL; |
return NULL; |
Line 60 mqtt_rtlm_close(FILE *f)
|
Line 63 mqtt_rtlm_close(FILE *f)
|
{ |
{ |
if (f) |
if (f) |
fclose(f); |
fclose(f); |
|
} |
|
|
|
/* |
|
* mqtt_rtlm_logger() Logger to file |
|
* |
|
* @f = File handle |
|
* @fmt = Message format |
|
* @... = argument list |
|
* return: -1 error or >-1 logged successful |
|
*/ |
|
int |
|
mqtt_rtlm_logger(FILE *f, const char *fmt, ...) |
|
{ |
|
va_list lst; |
|
int ret = 0; |
|
char szStr[STRSIZ] = { 0 }, szFmt[BUFSIZ] = { 0 }; |
|
struct tm *tm; |
|
time_t tim; |
|
|
|
if (!f || !fmt) |
|
return -1; |
|
|
|
tim = time(NULL); |
|
tm = localtime(&tim); |
|
strftime(szFmt, sizeof szFmt, "[%Y-%m-%d %H:%M:%S] ", tm); |
|
snprintf(szStr, sizeof szStr, "%s (%d):: ", __progname, getpid()); |
|
strlcat(szFmt, szStr, sizeof szFmt); |
|
strlcat(szFmt, fmt, sizeof szFmt); |
|
|
|
va_start(lst, fmt); |
|
ret = vfprintf(f, szFmt, lst); |
|
va_end(lst); |
|
|
|
fflush(f); |
|
return ret; |
} |
} |