1 /* PipeWire 2 * 3 * Copyright © 2018 Wim Taymans 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice (including the next 13 * paragraph) shall be included in all copies or substantial portions of the 14 * Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 * DEALINGS IN THE SOFTWARE. 23 */ 24 25 #ifndef PIPEWIRE_LOG_H 26 #define PIPEWIRE_LOG_H 27 28 #include <spa/support/log.h> 29 30 #ifdef __cplusplus 31 extern "C" { 32 #endif 33 34 /** \class pw_log 35 * 36 * Logging functions of PipeWire 37 * 38 * Logging is performed to stdout and stderr. Trace logging is performed 39 * in a lockfree ringbuffer and written out from the main thread as to not 40 * block the realtime threads. 41 */ 42 43 /** The global log level */ 44 extern enum spa_log_level pw_log_level; 45 46 /** Configure a logging module. This is usually done automatically 47 * in pw_init() but you can install a custom logger before calling 48 * pw_init(). */ 49 void pw_log_set(struct spa_log *log); 50 51 /** Get the log interface */ 52 struct spa_log *pw_log_get(void); 53 54 /** Configure the logging level */ 55 void pw_log_set_level(enum spa_log_level level); 56 57 58 /** Log a message */ 59 void 60 pw_log_log(enum spa_log_level level, 61 const char *file, 62 int line, const char *func, 63 const char *fmt, ...) SPA_PRINTF_FUNC(5, 6); 64 65 /** Log a message */ 66 void 67 pw_log_logv(enum spa_log_level level, 68 const char *file, 69 int line, const char *func, 70 const char *fmt, va_list args) SPA_PRINTF_FUNC(5, 0); 71 72 73 /** Check if a loglevel is enabled \memberof pw_log */ 74 #define pw_log_level_enabled(lev) (pw_log_level >= (lev)) 75 76 #define pw_log(lev,...) \ 77 ({ \ 78 if (SPA_UNLIKELY(pw_log_level_enabled (lev))) \ 79 pw_log_log(lev,__FILE__,__LINE__,__func__,__VA_ARGS__); \ 80 }) 81 82 #define pw_log_error(...) pw_log(SPA_LOG_LEVEL_ERROR,__VA_ARGS__) 83 #define pw_log_warn(...) pw_log(SPA_LOG_LEVEL_WARN,__VA_ARGS__) 84 #define pw_log_info(...) pw_log(SPA_LOG_LEVEL_INFO,__VA_ARGS__) 85 #define pw_log_debug(...) pw_log(SPA_LOG_LEVEL_DEBUG,__VA_ARGS__) 86 #define pw_log_trace(...) pw_log(SPA_LOG_LEVEL_TRACE,__VA_ARGS__) 87 88 #ifndef FASTPATH 89 #define pw_log_trace_fp(...) pw_log(SPA_LOG_LEVEL_TRACE,__VA_ARGS__) 90 #else 91 #define pw_log_trace_fp(...) 92 #endif 93 94 #ifdef __cplusplus 95 } 96 #endif 97 #endif /* PIPEWIRE_LOG_H */ 98