VCOS_STATUS_T vcos_log_status_cmd( VCOS_CMD_PARAM_T *param ) { VCOS_LOG_CAT_T *cat; VCOS_STATUS_T status; vcos_mutex_lock(&lock); if ( param->argc == 1) { int nw; int nameWidth = 0; /* Print information about all of the categories. */ for ( cat = vcos_logging_categories; cat != NULL; cat = cat->next ) { nw = (int)strlen( cat->name ); if ( nw > nameWidth ) { nameWidth = nw; } } for ( cat = vcos_logging_categories; cat != NULL; cat = cat->next ) { vcos_cmd_printf( param, "%-*s - %s\n", nameWidth, cat->name, vcos_log_level_to_string( cat->level )); } } else { /* Print information about a particular category */ for ( cat = vcos_logging_categories; cat != NULL; cat = cat->next ) { if ( vcos_strcmp( cat->name, param->argv[1] ) == 0 ) { vcos_cmd_printf( param, "%s - %s\n", cat->name, vcos_log_level_to_string( cat->level )); break; } } if ( cat == NULL ) { vcos_cmd_printf( param, "Unrecognized logging category: '%s'\n", param->argv[1] ); status = VCOS_ENOENT; goto out; } } status = VCOS_SUCCESS; out: vcos_mutex_unlock(&lock); return status; }
void vcos_log_register(const char *name, VCOS_LOG_CAT_T *category) { const char *env; VCOS_LOG_CAT_T *i; category->name = name; if ( category->level == VCOS_LOG_UNINITIALIZED ) { category->level = VCOS_LOG_ERROR; } category->flags.want_prefix = (category != &dflt_log_category ); vcos_mutex_lock(&lock); /* is it already registered? */ for (i = vcos_logging_categories; i ; i = i->next ) { if (i == category) { i->refcount++; break; } } if (!i) { /* not yet registered */ category->next = vcos_logging_categories; vcos_logging_categories = category; category->refcount++; vcos_log_platform_register(category); } vcos_mutex_unlock(&lock); /* Check to see if this log level has been enabled. Look for * (<category:level>,)* * * VC_LOGLEVEL=ilcs:info,vchiq:warn */ env = _VCOS_LOG_LEVEL(); if (env) { do { char env_name[64]; VCOS_LOG_LEVEL_T level; if (read_tok(env_name, sizeof(env_name), &env, ':') && read_level(&level, &env, ',')) { if (strcmp(env_name, name) == 0) { category->level = level; break; } } else { if (!warned_loglevel) { vcos_log("VC_LOGLEVEL format invalid at %s\n", env); warned_loglevel = 1; } return; } } while (env[0] != '\0'); } vcos_log_info( "Registered log category '%s' with level %s", category->name, vcos_log_level_to_string( category->level )); }
static void logging_show_category( VCOS_CFG_BUF_T buf, void *data ) { VCOS_LOG_CAT_T *category = data; vcos_cfg_buf_printf( buf, "%s\n", vcos_log_level_to_string( category->level )); }