Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 1 | /* simple test for the debug interface */ |
| 2 | /* |
| 3 | * (C) 2008, 2009 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 4 | * (C) 2012-2013 by Katerina Barone-Adesi <kat.obsc@gmail.com> |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
Holger Hans Peter Freyther | 53aa0f5 | 2017-12-09 13:03:29 +0000 | [diff] [blame] | 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
Holger Hans Peter Freyther | 53aa0f5 | 2017-12-09 13:03:29 +0000 | [diff] [blame] | 17 | * You should have received a copy of the GNU General Public License along |
| 18 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 20 | * |
| 21 | */ |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 22 | |
| 23 | #include <osmocom/core/logging.h> |
| 24 | #include <osmocom/core/utils.h> |
Michael McTernan | 4e0543f | 2015-03-30 13:22:14 +0100 | [diff] [blame] | 25 | #include <osmocom/core/loggingrb.h> |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 26 | |
| 27 | enum { |
| 28 | DRLL, |
| 29 | DCC, |
| 30 | DMM, |
| 31 | }; |
| 32 | |
| 33 | static const struct log_info_cat default_categories[] = { |
| 34 | [DRLL] = { |
| 35 | .name = "DRLL", |
| 36 | .description = "A-bis Radio Link Layer (RLL)", |
Neels Hofmeyr | f2644ae | 2019-11-20 04:00:29 +0100 | [diff] [blame] | 37 | .color = OSMO_LOGCOLOR_RED, |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 38 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 39 | }, |
| 40 | [DCC] = { |
| 41 | .name = "DCC", |
| 42 | .description = "Layer3 Call Control (CC)", |
Neels Hofmeyr | f2644ae | 2019-11-20 04:00:29 +0100 | [diff] [blame] | 43 | .color = OSMO_LOGCOLOR_GREEN, |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 44 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 45 | }, |
| 46 | [DMM] = { |
| 47 | .name = NULL, |
| 48 | .description = "Layer3 Mobility Management (MM)", |
Neels Hofmeyr | f2644ae | 2019-11-20 04:00:29 +0100 | [diff] [blame] | 49 | .color = OSMO_LOGCOLOR_BLUE, |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 50 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 51 | }, |
| 52 | }; |
| 53 | |
| 54 | const struct log_info log_info = { |
| 55 | .cat = default_categories, |
| 56 | .num_cat = ARRAY_SIZE(default_categories), |
| 57 | }; |
| 58 | |
| 59 | int main(int argc, char **argv) |
| 60 | { |
| 61 | struct log_target *ringbuf_target; |
| 62 | |
| 63 | log_init(&log_info, NULL); |
Michael McTernan | 4e0543f | 2015-03-30 13:22:14 +0100 | [diff] [blame] | 64 | ringbuf_target = log_target_create_rb(0x1000); |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 65 | log_add_target(ringbuf_target); |
| 66 | log_set_all_filter(ringbuf_target, 1); |
| 67 | log_set_print_filename(ringbuf_target, 0); |
| 68 | |
| 69 | log_parse_category_mask(ringbuf_target, "DRLL:DCC"); |
| 70 | log_parse_category_mask(ringbuf_target, "DRLL"); |
| 71 | DEBUGP(DCC, "You should not see this\n"); |
| 72 | |
| 73 | log_parse_category_mask(ringbuf_target, "DRLL:DCC"); |
| 74 | DEBUGP(DRLL, "You should see this\n"); |
| 75 | DEBUGP(DCC, "You should see this\n"); |
| 76 | DEBUGP(DMM, "You should not see this\n"); |
Holger Hans Peter Freyther | 6b1faf7 | 2015-04-11 19:33:10 +0200 | [diff] [blame] | 77 | fprintf(stderr, "%s", log_target_rb_get(ringbuf_target, 0)); |
| 78 | fprintf(stderr, "%s", log_target_rb_get(ringbuf_target, 1)); |
Michael McTernan | 4e0543f | 2015-03-30 13:22:14 +0100 | [diff] [blame] | 79 | OSMO_ASSERT(!log_target_rb_get(ringbuf_target, 2)); |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 80 | |
| 81 | return 0; |
| 82 | } |