version 1.1.2.2, 2011/11/23 14:51:14
|
version 1.1.2.3, 2011/11/24 00:08:56
|
Line 1
|
Line 1
|
#include "global.h" |
#include "global.h" |
|
|
|
|
|
extern char *__progname; |
|
|
|
|
/* |
/* |
* mqtt_rtlm_log() Log message |
* mqtt_rtlm_log() Log message |
* |
* |
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); |
|
|
|
return ret; |
} |
} |