#include <stdio.h>
#include <string.h>
#include <stdbool.h>
+#include <stdlib.h>
+#include <sys/time.h>
#include "util.h"
#include "log.h"
static uint64_t loglevel = 0;
static bool verbose = true;
+static FILE *errorfile;
+char *errorfilename;
+
+/*
+ * Initializes logging by creating an error logfile in /tmp (or
+ * XDG_RUNTIME_DIR, see get_process_filename()).
+ *
+ */
+void init_logging() {
+ errorfilename = get_process_filename("errorlog");
+ if (errorfilename == NULL) {
+ ELOG("Could not initialize errorlog\n");
+ return;
+ }
+
+ errorfile = fopen(errorfilename, "w");
+}
/*
* Set verbosity of i3. If verbose is set to true, informative messages will
struct tm *tmp = localtime(&t);
/* Generate time prefix */
strftime(timebuf, sizeof(timebuf), "%x %X - ", tmp);
+#ifdef DEBUG_TIMING
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ printf("%s%d.%d - ", timebuf, tv.tv_sec, tv.tv_usec);
+#else
printf("%s", timebuf);
+#endif
vprintf(fmt, args);
}
va_start(args, fmt);
vlog(fmt, args);
va_end(args);
+
+ /* also log to the error logfile, if opened */
+ va_start(args, fmt);
+ vfprintf(errorfile, fmt, args);
+ fflush(errorfile);
+ va_end(args);
}
/*