int log_data(unsigned id, void *buf, unsigned size) { int fd; if (!log_level) return 0; if ((fd = get_log_fd(id)) > 0) return write(fd, buf, size); return 0; }
void write_log (int whichlog, char *fmt, ...) { char buf[BUFSIZE]; va_list ap; char *logtime; mythread_t *mt = thread_check_created (); int fd = get_log_fd (whichlog); va_start(ap, fmt); vsnprintf(buf, BUFSIZE, fmt, ap); if (!mt) fprintf (stderr, "WARNING: No mt while outputting [%s]", buf); logtime = get_log_time(); if (strstr (buf, "%s") != NULL) { fprintf (stderr, "WARNING, write_log () called with '%%s' formatted string [%s]!", buf); free (logtime); return; } if (mt && fd != -1) { if ((whichlog != ANDROID_LOG_VERBOSE) || (info.logfiledebuglevel > -1)) { fd_write (fd, "[%s] [%d:%s] %s\n", logtime, mt->id, nullcheck_string (mt->name), buf); } } if (whichlog != ANDROID_LOG_VERBOSE) { free (logtime); va_end (ap); return; } if (running == SERVER_RUNNING) { printf("\r[%s] %s\n", logtime, buf); fflush(stdout); } else fprintf (stderr, "[%s] %s\n", logtime, buf); if (logtime) free(logtime); va_end (ap); }
void log_no_thread (int whichlog, char *fmt, ...) { char buf[BUFSIZE]; va_list ap; char *logtime; int fd = get_log_fd (whichlog); va_start(ap, fmt); vsnprintf(buf, BUFSIZE, fmt, ap); logtime = get_log_time(); if (strstr (buf, "%s") != NULL) { fprintf (stderr, "WARNING, write_log () called with '%%s' formatted string [%s]!", buf); logtime = get_log_time(); return; } if (fd != -1) { if ((whichlog != ANDROID_LOG_VERBOSE) || (info.logfiledebuglevel > -1)) { fd_write (fd, "[%s] %s\n", logtime, buf); } } if (whichlog != ANDROID_LOG_VERBOSE) { free (logtime); va_end (ap); return; } if (running == SERVER_RUNNING) { printf("\r[%s] %s\n", logtime, buf); fflush(stdout); } else fprintf (stderr, "[%s] %s\n", logtime, buf); if (logtime) free(logtime); va_end (ap); }