Skip to content

Commit

Permalink
Even more debugging information
Browse files Browse the repository at this point in the history
  • Loading branch information
CurlyMoo committed Jun 12, 2019
1 parent 2ec270e commit a624dcc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 25 deletions.
48 changes: 24 additions & 24 deletions libs/pilight/core/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,22 +178,22 @@ void logprintf1(int prio, char *file, int line, const char *format_str, ...) {
FREE(a);
}

void logprintf(int prio, const char *format_str, ...) {
void _logprintf(int prio, char *file, int line, const char *str, ...) {
struct timeval tv;
struct tm tm;
va_list ap, apcpy;
char fmt[64], buf[64], *line = MALLOC(128);
char fmt[64], buf[64], *buffer = MALLOC(128);
int save_errno = -1, pos = 0, bytes = 0;

memset(&tm, '\0', sizeof(struct tm));

if(line == NULL) {
if(buffer == NULL) {
fprintf(stderr, "out of memory\n");
exit(EXIT_FAILURE);
}
save_errno = errno;

memset(line, '\0', 128);
memset(buffer, '\0', 128);
memset(buf, '\0', 64);

if(loglevel >= prio) {
Expand All @@ -208,59 +208,59 @@ void logprintf(int prio, const char *format_str, ...) {
strftime(fmt, sizeof(fmt), "%b %d %H:%M:%S", &tm);
snprintf(buf, sizeof(buf), "%s:%03u", fmt, (unsigned int)tv.tv_usec);
}
pos += sprintf(line, "[%22.22s] %s: ", buf, progname);
pos += sprintf(buffer, "(%s #%d) [%s:%03u] ", file, line, fmt, (unsigned int)tv.tv_usec);

switch(prio) {
case LOG_WARNING:
pos += sprintf(&line[pos], "WARNING: ");
pos += sprintf(&buffer[pos], "WARNING: ");
break;
case LOG_ERR:
pos += sprintf(&line[pos], "ERROR: ");
pos += sprintf(&buffer[pos], "ERROR: ");
break;
case LOG_INFO:
pos += sprintf(&line[pos], "INFO: ");
pos += sprintf(&buffer[pos], "INFO: ");
break;
case LOG_NOTICE:
pos += sprintf(&line[pos], "NOTICE: ");
pos += sprintf(&buffer[pos], "NOTICE: ");
break;
case LOG_DEBUG:
pos += sprintf(&line[pos], "DEBUG: ");
pos += sprintf(&buffer[pos], "DEBUG: ");
break;
case LOG_STACK:
pos += sprintf(&line[pos], "STACK: ");
pos += sprintf(&buffer[pos], "STACK: ");
break;
default:
break;
}

va_copy(apcpy, ap);
va_start(apcpy, format_str);
va_start(apcpy, str);
#ifdef _WIN32
bytes = _vscprintf(format_str, apcpy);
bytes = _vscprintf(str, apcpy);
#else
bytes = vsnprintf(NULL, 0, format_str, apcpy);
bytes = vsnprintf(NULL, 0, str, apcpy);
#endif
if(bytes == -1) {
fprintf(stderr, "ERROR: unproperly formatted logprintf message %s\n", format_str);
fprintf(stderr, "ERROR: unproperly formatted logprintf message %s\n", str);
} else {
va_end(apcpy);
if((line = REALLOC(line, (size_t)bytes+(size_t)pos+3)) == NULL) {
if((buffer = REALLOC(buffer, (size_t)bytes+(size_t)pos+3)) == NULL) {
fprintf(stderr, "out of memory\n");
exit(EXIT_FAILURE);
}
va_start(ap, format_str);
pos += vsprintf(&line[pos], format_str, ap);
va_start(ap, str);
pos += vsprintf(&buffer[pos], str, ap);
va_end(ap);
}
line[pos++]='\n';
line[pos++]='\0';
buffer[pos++]='\n';
buffer[pos++]='\0';
}
if(shelllog == 1) {
fprintf(stderr, "%s", line);
fprintf(stderr, "%s", buffer);
}
#ifdef _WIN32
if(prio == LOG_ERR && strstr(progname, "daemon") != NULL && pilight.running == 0) {
MessageBox(NULL, line, "pilight :: error", MB_OK);
MessageBox(NULL, buffer, "pilight :: error", MB_OK);
}
#endif
if(stop == 0 && pos > 0) {
Expand All @@ -279,7 +279,7 @@ void logprintf(int prio, const char *format_str, ...) {
exit(EXIT_FAILURE);
}
memset(node->line, '\0', (size_t)pos+1);
strcpy(node->line, line);
strcpy(node->line, buffer);
node->next = NULL;

if(logqueue_number == 0) {
Expand All @@ -300,7 +300,7 @@ void logprintf(int prio, const char *format_str, ...) {
}
}
}
FREE(line);
FREE(buffer);
errno = save_errno;
}

Expand Down
5 changes: 4 additions & 1 deletion libs/pilight/core/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@

#define LOG_STACK 255

#define logprintf(a, b, ...) _logprintf(a, __FILE__, __LINE__, b, ##__VA_ARGS__)

void _logprintf(int prio, char *file, int line, const char *str, ...);
void logprintf1(int prio, char *file, int line, const char *format_str, ...);
void logprintf(int prio, const char *format_str, ...);
// void logprintf(int prio, const char *format_str, ...);
void logperror(int prio, const char *s);
void *logloop(void *param);
void log_file_enable(void);
Expand Down
1 change: 1 addition & 0 deletions libs/pilight/lua_c/lua.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ typedef struct lua_state_t {
lua_State *L;
uv_mutex_t lock;
struct plua_module_t *module;
struct plua_module_t *oldmod;
struct plua_metatable_t *table;
int idx;

Expand Down

0 comments on commit a624dcc

Please sign in to comment.