80 ELOG(
"Could not initialize errorlog\n");
83 if (fcntl(fileno(
errorfile), F_SETFD, FD_CLOEXEC)) {
84 ELOG(
"Could not set close-on-exec flag\n");
96 long long physical_mem_bytes = (
long long)sysconf(_SC_PHYS_PAGES) *
97 sysconf(_SC_PAGESIZE);
102 ELOG(
"Could not shm_open SHM segment for the i3 log: %s\n", strerror(errno));
108 shm_unlink(
"/i3-log-");
109 ELOG(
"Could not ftruncate SHM segment for the i3 log: %s\n", strerror(errno));
116 shm_unlink(
"/i3-log-");
117 ELOG(
"Could not mmap SHM segment for the i3 log: %s\n", strerror(errno));
143 if (strcasecmp(level,
"all") == 0) {
148 for (
int i = 0; i <
sizeof(
loglevels) /
sizeof(
char*); i++) {
149 if (strcasecmp(
loglevels[i], level) != 0)
167 static void vlog(
const bool print,
const char *fmt, va_list args) {
170 static char message[4096];
171 static struct tm result;
173 static struct tm *tmp;
179 tmp = localtime_r(&t, &result);
181 len = strftime(message,
sizeof(message),
"%x %X - ", tmp);
194 gettimeofday(&tv, NULL);
195 printf(
"%s%d.%d - ", message, tv.tv_sec, tv.tv_usec);
197 printf(
"%s", message);
201 len += vsnprintf(message + len,
sizeof(message) - len, fmt, args);
203 fprintf(stderr,
"BUG: something is overflowing here. Dropping the log entry\n");
207 if (len >=
sizeof(message)) {
208 fprintf(stderr,
"BUG: single log message > 4k\n");
221 strncpy(
logwalk, message, len);
228 fwrite(message, len, 1, stdout);
256 vlog(
true, fmt, args);