| 1 | #ifndef BABELTRACE_PLUGINS_COMP_LOGGING_H |
| 2 | #define BABELTRACE_PLUGINS_COMP_LOGGING_H |
| 3 | |
| 4 | /* |
| 5 | * Copyright 2019 Philippe Proulx <pproulx@efficios.com> |
| 6 | * |
| 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | * of this software and associated documentation files (the "Software"), to deal |
| 9 | * in the Software without restriction, including without limitation the rights |
| 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | * copies of the Software, and to permit persons to whom the Software is |
| 12 | * furnished to do so, subject to the following conditions: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice shall be included in |
| 15 | * all copies or substantial portions of the Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 23 | * SOFTWARE. |
| 24 | */ |
| 25 | |
| 26 | #ifndef BT_LOG_TAG |
| 27 | # error Please define a tag with BT_LOG_TAG before including this file. |
| 28 | #endif |
| 29 | |
| 30 | #ifndef BT_LOG_OUTPUT_LEVEL |
| 31 | # error Please define a log level expression with BT_LOG_OUTPUT_LEVEL before including this file. |
| 32 | #endif |
| 33 | |
| 34 | #ifndef BT_COMP_LOG_SELF_COMP |
| 35 | # error Please define a self component address expression with BT_COMP_LOG_SELF_COMP before including this file. |
| 36 | #endif |
| 37 | |
| 38 | #include <stdlib.h> |
| 39 | #include <babeltrace2/babeltrace.h> |
| 40 | #include "logging/log.h" |
| 41 | |
| 42 | #define _BT_COMP_LOG_COMP_PREFIX "[%s] " |
| 43 | #define _BT_COMP_LOG_COMP_NA_STR "N/A" |
| 44 | |
| 45 | /* Logs with level `_lvl` for self component `_self_comp` */ |
| 46 | #define BT_COMP_LOG(_lvl, _self_comp, _fmt, ...) \ |
| 47 | BT_LOG_WRITE((_lvl), BT_LOG_TAG, _BT_COMP_LOG_COMP_PREFIX _fmt, \ |
| 48 | (_self_comp) ? \ |
| 49 | bt_component_get_name( \ |
| 50 | bt_self_component_as_component(_self_comp)) : \ |
| 51 | _BT_COMP_LOG_COMP_NA_STR, \ |
| 52 | ##__VA_ARGS__) |
| 53 | |
| 54 | #define BT_COMP_LOG_CUR_LVL(_lvl, _cur_lvl, _self_comp, _fmt, ...) \ |
| 55 | BT_LOG_WRITE_CUR_LVL((_lvl), (_cur_lvl), BT_LOG_TAG, \ |
| 56 | _BT_COMP_LOG_COMP_PREFIX _fmt, \ |
| 57 | (_self_comp) ? \ |
| 58 | bt_component_get_name( \ |
| 59 | bt_self_component_as_component(_self_comp)) : \ |
| 60 | _BT_COMP_LOG_COMP_NA_STR, \ |
| 61 | ##__VA_ARGS__) |
| 62 | |
| 63 | #define BT_COMP_LOG_ERRNO(_lvl, _self_comp, _msg, _fmt, ...) \ |
| 64 | BT_LOG_WRITE_ERRNO((_lvl), BT_LOG_TAG, _msg, \ |
| 65 | _BT_COMP_LOG_COMP_PREFIX _fmt, \ |
| 66 | (_self_comp) ? \ |
| 67 | bt_component_get_name( \ |
| 68 | bt_self_component_as_component(_self_comp)) : \ |
| 69 | _BT_COMP_LOG_COMP_NA_STR, \ |
| 70 | ##__VA_ARGS__) |
| 71 | |
| 72 | #define BT_COMP_LOG_ERRNO_CUR_LVL(_lvl, _cur_lvl, _self_comp, _msg, _fmt, ...) \ |
| 73 | BT_LOG_WRITE_ERRNO_CUR_LVL((_lvl), (_cur_lvl), BT_LOG_TAG, _msg, \ |
| 74 | _BT_COMP_LOG_COMP_PREFIX _fmt, \ |
| 75 | (_self_comp) ? \ |
| 76 | bt_component_get_name( \ |
| 77 | bt_self_component_as_component(_self_comp)) : \ |
| 78 | _BT_COMP_LOG_COMP_NA_STR, \ |
| 79 | ##__VA_ARGS__) |
| 80 | |
| 81 | #define BT_COMP_LOG_MEM(_lvl, _self_comp, _data_ptr, _data_sz, _fmt, ...) \ |
| 82 | BT_LOG_WRITE_MEM((_lvl), BT_LOG_TAG, (_data_ptr), (_data_sz), \ |
| 83 | _BT_COMP_LOG_COMP_PREFIX _fmt, \ |
| 84 | (_self_comp) ? \ |
| 85 | bt_component_get_name( \ |
| 86 | bt_self_component_as_component(_self_comp)) : \ |
| 87 | _BT_COMP_LOG_COMP_NA_STR, \ |
| 88 | ##__VA_ARGS__) |
| 89 | |
| 90 | /* Specific per-level logging macros; they use `BT_COMP_LOG_SELF_COMP` */ |
| 91 | #define BT_COMP_LOGF(_fmt, ...) \ |
| 92 | BT_COMP_LOG(BT_LOG_FATAL, (BT_COMP_LOG_SELF_COMP), _fmt, ##__VA_ARGS__) |
| 93 | #define BT_COMP_LOGE(_fmt, ...) \ |
| 94 | BT_COMP_LOG(BT_LOG_ERROR, (BT_COMP_LOG_SELF_COMP), _fmt, ##__VA_ARGS__) |
| 95 | #define BT_COMP_LOGW(_fmt, ...) \ |
| 96 | BT_COMP_LOG(BT_LOG_WARNING, (BT_COMP_LOG_SELF_COMP), _fmt, ##__VA_ARGS__) |
| 97 | #define BT_COMP_LOGI(_fmt, ...) \ |
| 98 | BT_COMP_LOG(BT_LOG_INFO, (BT_COMP_LOG_SELF_COMP), _fmt, ##__VA_ARGS__) |
| 99 | #define BT_COMP_LOGD(_fmt, ...) \ |
| 100 | BT_COMP_LOG(BT_LOG_DEBUG, (BT_COMP_LOG_SELF_COMP), _fmt, ##__VA_ARGS__) |
| 101 | #define BT_COMP_LOGT(_fmt, ...) \ |
| 102 | BT_COMP_LOG(BT_LOG_TRACE, (BT_COMP_LOG_SELF_COMP), _fmt, ##__VA_ARGS__) |
| 103 | #define BT_COMP_LOGF_STR(_str) \ |
| 104 | BT_COMP_LOG(BT_LOG_FATAL, (BT_COMP_LOG_SELF_COMP), "%s", (_str)) |
| 105 | #define BT_COMP_LOGE_STR(_str) \ |
| 106 | BT_COMP_LOG(BT_LOG_ERROR, (BT_COMP_LOG_SELF_COMP), "%s", (_str)) |
| 107 | #define BT_COMP_LOGW_STR(_str) \ |
| 108 | BT_COMP_LOG(BT_LOG_WARNING, (BT_COMP_LOG_SELF_COMP), "%s", (_str)) |
| 109 | #define BT_COMP_LOGI_STR(_str) \ |
| 110 | BT_COMP_LOG(BT_LOG_INFO, (BT_COMP_LOG_SELF_COMP), "%s", (_str)) |
| 111 | #define BT_COMP_LOGD_STR(_str) \ |
| 112 | BT_COMP_LOG(BT_LOG_DEBUG, (BT_COMP_LOG_SELF_COMP), "%s", (_str)) |
| 113 | #define BT_COMP_LOGT_STR(_str) \ |
| 114 | BT_COMP_LOG(BT_LOG_TRACE, (BT_COMP_LOG_SELF_COMP), "%s", (_str)) |
| 115 | #define BT_COMP_LOGF_ERRNO(_msg, _fmt, ...) \ |
| 116 | BT_COMP_LOG_ERRNO(BT_LOG_FATAL, (BT_COMP_LOG_SELF_COMP), _msg, _fmt, ##__VA_ARGS__) |
| 117 | #define BT_COMP_LOGE_ERRNO(_msg, _fmt, ...) \ |
| 118 | BT_COMP_LOG_ERRNO(BT_LOG_ERROR, (BT_COMP_LOG_SELF_COMP), _msg, _fmt, ##__VA_ARGS__) |
| 119 | #define BT_COMP_LOGW_ERRNO(_msg, _fmt, ...) \ |
| 120 | BT_COMP_LOG_ERRNO(BT_LOG_WARNING, (BT_COMP_LOG_SELF_COMP), _msg, _fmt, ##__VA_ARGS__) |
| 121 | #define BT_COMP_LOGI_ERRNO(_msg, _fmt, ...) \ |
| 122 | BT_COMP_LOG_ERRNO(BT_LOG_INFO, (BT_COMP_LOG_SELF_COMP), _msg, _fmt, ##__VA_ARGS__) |
| 123 | #define BT_COMP_LOGD_ERRNO(_msg, _fmt, ...) \ |
| 124 | BT_COMP_LOG_ERRNO(BT_LOG_DEBUG, (BT_COMP_LOG_SELF_COMP), _msg, _fmt, ##__VA_ARGS__) |
| 125 | #define BT_COMP_LOGT_ERRNO(_msg, _fmt, ...) \ |
| 126 | BT_COMP_LOG_ERRNO(BT_LOG_TRACE, (BT_COMP_LOG_SELF_COMP), _msg, _fmt, ##__VA_ARGS__) |
| 127 | #define BT_COMP_LOGF_MEM(_data_ptr, _data_sz, _fmt, ...) \ |
| 128 | BT_COMP_LOG_MEM(BT_LOG_FATAL, (BT_COMP_LOG_SELF_COMP), (_data_ptr), (_data_sz), _fmt, ##__VA_ARGS__) |
| 129 | #define BT_COMP_LOGE_MEM(_data_ptr, _data_sz, _fmt, ...) \ |
| 130 | BT_COMP_LOG_MEM(BT_LOG_ERROR, (BT_COMP_LOG_SELF_COMP), (_data_ptr), (_data_sz), _fmt, ##__VA_ARGS__) |
| 131 | #define BT_COMP_LOGW_MEM(_data_ptr, _data_sz, _fmt, ...) \ |
| 132 | BT_COMP_LOG_MEM(BT_LOG_WARNING, (BT_COMP_LOG_SELF_COMP), (_data_ptr), (_data_sz), _fmt, ##__VA_ARGS__) |
| 133 | #define BT_COMP_LOGI_MEM(_data_ptr, _data_sz, _fmt, ...) \ |
| 134 | BT_COMP_LOG_MEM(BT_LOG_INFO, (BT_COMP_LOG_SELF_COMP), (_data_ptr), (_data_sz), _fmt, ##__VA_ARGS__) |
| 135 | #define BT_COMP_LOGD_MEM(_data_ptr, _data_sz, _fmt, ...) \ |
| 136 | BT_COMP_LOG_MEM(BT_LOG_DEBUG, (BT_COMP_LOG_SELF_COMP), (_data_ptr), (_data_sz), _fmt, ##__VA_ARGS__) |
| 137 | #define BT_COMP_LOGT_MEM(_data_ptr, _data_sz, _fmt, ...) \ |
| 138 | BT_COMP_LOG_MEM(BT_LOG_TRACE, (BT_COMP_LOG_SELF_COMP), (_data_ptr), (_data_sz), _fmt, ##__VA_ARGS__) |
| 139 | |
| 140 | #define BT_COMP_LOG_SUPPORTED |
| 141 | |
| 142 | #endif /* BABELTRACE_PLUGINS_COMP_LOGGING_H */ |