[Asterisk-code-review] Logging: Add debug logging categories (asterisk[master])

George Joseph asteriskteam at digium.com
Wed Sep 16 08:14:48 CDT 2020


George Joseph has posted comments on this change. ( https://gerrit.asterisk.org/c/asterisk/+/14887 )

Change subject: Logging: Add debug logging categories
......................................................................


Patch Set 6:

(1 comment)

https://gerrit.asterisk.org/c/asterisk/+/14887/5/main/logger_category.c 
File main/logger_category.c:

https://gerrit.asterisk.org/c/asterisk/+/14887/5/main/logger_category.c@42 
PS5, Line 42: static uintmax_t get_next_id(struct categories_level_t *level)
            : {
            : 	if (level->id_pool == 0) {
            : 		level->id_pool = 1;
            : 	} else if (level->id_pool >= (UINTMAX_MAX / 2)) {
            : 		/* No more ids left*/
            : 		return 0;
            : 	} else {
            : 		level->id_pool <<= 1;
            : 	}
            : 
            : 	return level->id_pool;
            : }
            : 
            : static int cmp_by_name(const struct category_t *category, const char *name)
            : {
            : 	return !strcmp(category->name, name);
            : }
            : 
            : static uintmax_t category_register(struct categories_level_t *level, const char *name)
            : {
            : 	int i;
            : 	struct category_t *category;
            : 
            : 	AST_VECTOR_RW_WRLOCK(&level->categories);
            : 
            : 	i = AST_VECTOR_GET_INDEX(&level->categories, name, cmp_by_name);
            : 	if (i >= 0) {
            : 		AST_VECTOR_RW_UNLOCK(&level->categories);
            : 		ast_log(LOG_ERROR, "Cannot register logger category '%s'. "
            : 				"Name already used for type.\n", name);
            : 		return 0;
            : 	}
            : 
            : 	category = ast_calloc(1, sizeof(*category) + strlen(name) + 1);
            : 	if (!category) {
            : 		AST_VECTOR_RW_UNLOCK(&level->categories);
            : 		return 0;
            : 	}
            : 
            : 	category->id = get_next_id(level);
            : 	category->sublevel = AST_LOG_CATEGORY_DISABLED;
            : 	strcpy(category->name, name); /* Safe */
            : 
            : 	if (AST_VECTOR_APPEND(&level->categories, category)) {
            : 		AST_VECTOR_RW_UNLOCK(&level->categories);
            : 		ast_log(LOG_ERROR, "Cannot register logger category '%s'. "
            : 				"Unable to append.\n", name);
            : 		return 0;
            : 	}
            : 
            : 	AST_VECTOR_RW_UNLOCK(&level->categories);
            : 	ast_log(LOG_VERBOSE, "##### %s - %ju\n", category->name, category->id);
            : 	return category->id;
            : }
            : 
> Ids must be a power of 2. This allows for fast lookup, and "or'ing" of ids in order to permit multiple categories in a log statement.
> 
> Using a vector would require a for loop on every category log statement called. It would also make specifying multiple categories for a given log statement a little awkward.
> 
> I'll add a comment in the code.

I must be missing something.  Why does using a vector require a loop if the id is an integer and you do a straight AST_VECTOR_GET using it?



-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/14887
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: I6e6cb247bb1f01dbf34750b2cd98e5b5b41a1849
Gerrit-Change-Number: 14887
Gerrit-PatchSet: 6
Gerrit-Owner: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Comment-Date: Wed, 16 Sep 2020 13:14:48 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: George Joseph <gjoseph at digium.com>
Comment-In-Reply-To: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: comment
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200916/e0428a5f/attachment-0001.html>


More information about the asterisk-code-review mailing list