log.h (5626B)
1 /* 2 * kbgwm, a sucklessy floating window manager 3 * Copyright (c) 2020-2021, Kebigon <git@kebigon.xyz> 4 * 5 * Permission to use, copy, modify, and/or distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18 #pragma once 19 20 #include <stdio.h> 21 #include <xcb/xcb.h> 22 23 /* 24 * Logging level: 25 * - 1: ERROR 26 * - 2: WARN 27 * - 3: INFO 28 * - 4: DEBUG 29 */ 30 #define LOG_LEVEL 4 31 32 #if LOG_LEVEL >= 4 33 34 #define LOG_DEBUG(message) \ 35 do \ 36 { \ 37 printf("[%s:%d] DEBUG: " message "\n", __FILE__, __LINE__); \ 38 fflush(stdout); \ 39 } while (0) 40 #define LOG_DEBUG_VA(message, ...) \ 41 do \ 42 { \ 43 printf("[%s:%d] DEBUG: " message "\n", __FILE__, __LINE__, __VA_ARGS__); \ 44 fflush(stdout); \ 45 } while (0) 46 47 #else 48 49 #define LOG_DEBUG(message) 50 #define LOG_DEBUG_VA(message, ...) 51 52 #endif 53 54 #if LOG_LEVEL >= 3 55 56 #define LOG_INFO(message) \ 57 do \ 58 { \ 59 printf("[%s:%d] INFO: " message "\n", __FILE__, __LINE__); \ 60 fflush(stdout); \ 61 } while (0) 62 #define LOG_INFO_VA(message, ...) \ 63 do \ 64 { \ 65 printf("[%s:%d] INFO: " message "\n", __FILE__, __LINE__, __VA_ARGS__); \ 66 fflush(stdout); \ 67 } while (0) 68 69 #else 70 71 #define LOG_INFO(message) 72 #define LOG_INFO_VA(message, ...) 73 74 #endif 75 76 #if LOG_LEVEL >= 2 77 78 #define LOG_WARN(message) \ 79 do \ 80 { \ 81 printf("[%s:%d] WARN: " message "\n", __FILE__, __LINE__); \ 82 fflush(stdout); \ 83 } while (0) 84 #define LOG_WARN_VA(message, ...) \ 85 do \ 86 { \ 87 printf("[%s:%d] WARN: " message "\n", __FILE__, __LINE__, __VA_ARGS__); \ 88 fflush(stdout); \ 89 } while (0) 90 91 #else 92 93 #define LOG_WARN(message) 94 #define LOG_WARN_VA(message, ...) 95 96 #endif 97 98 #if LOG_LEVEL >= 1 99 100 #define LOG_ERROR(message) \ 101 do \ 102 { \ 103 printf("[%s:%d] ERROR: " message "\n", __FILE__, __LINE__); \ 104 fflush(stdout); \ 105 } while (0) 106 #define LOG_ERROR_VA(message, ...) \ 107 do \ 108 { \ 109 printf("[%s:%d] ERROR: " message "\n", __FILE__, __LINE__, __VA_ARGS__); \ 110 fflush(stdout); \ 111 } while (0) 112 113 #else 114 115 #define LOG_ERROR(message) 116 #define LOG_ERROR_VA(message, ...) 117 118 #endif 119 120 void log_debug_globals(); 121 void log_debug_event(xcb_generic_event_t *);