On 05/12/2011 08:58 AM, Jan Safranek wrote: > Allowed values are: > - DEBUG, INFO, WARNING, ERROR (case insensitive) > - integer numbers > > Signed-off-by: Jan Safranek<jsafr...@redhat.com> Acked-By: Ivana Hutarova Varekova <varek...@redhat.com>
> --- > > src/log.c | 30 +++++++++++++++++++++++++----- > 1 files changed, 25 insertions(+), 5 deletions(-) > > diff --git a/src/log.c b/src/log.c > index 8ca756c..1b02d45 100644 > --- a/src/log.c > +++ b/src/log.c > @@ -18,6 +18,7 @@ > #include<stdio.h> > #include<stdlib.h> > #include<errno.h> > +#include<strings.h> > > static cgroup_logger_callback cgroup_logger; > static void *cgroup_logger_userdata; > @@ -58,6 +59,29 @@ void cgroup_set_default_logger(int level) > cgroup_set_logger(cgroup_default_logger, level, NULL); > } > > +static int cgroup_parse_log_level_str(const char *levelstr) > +{ > + char *end; > + long level; > + errno = 0; > + > + /* try to parse integer first */ > + level = strtol(levelstr,&end, 10); > + if (end != levelstr&& *end == '\0') > + return level; > + > + if (strcasecmp(levelstr, "ERROR") == 0) > + return CGROUP_LOG_ERROR; > + if (strcasecmp(levelstr, "WARNING") == 0) > + return CGROUP_LOG_WARNING; > + if (strcasecmp(levelstr, "INFO") == 0) > + return CGROUP_LOG_INFO; > + if (strcasecmp(levelstr, "DEBUG") == 0) > + return CGROUP_LOG_DEBUG; > + > + return CGROUP_DEFAULT_LOGLEVEL; > +} > + > void cgroup_set_loglevel(int loglevel) > { > if (loglevel != -1) > @@ -65,11 +89,7 @@ void cgroup_set_loglevel(int loglevel) > else { > char *level_str = getenv("CGROUP_LOGLEVEL"); > if (level_str != NULL) > - /* > - * TODO: add better loglevel detection, e.g. strings > - * instead of plain numbers. > - */ > - cgroup_loglevel = atoi(level_str); > + cgroup_loglevel = cgroup_parse_log_level_str(level_str); > else > cgroup_loglevel = CGROUP_DEFAULT_LOGLEVEL; > } > > > ------------------------------------------------------------------------------ > Achieve unprecedented app performance and reliability > What every C/C++ and Fortran developer should know. > Learn how Intel has extended the reach of its next-generation tools > to help boost performance applications - inlcuding clusters. > http://p.sf.net/sfu/intel-dev2devmay > _______________________________________________ > Libcg-devel mailing list > Libcg-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/libcg-devel ------------------------------------------------------------------------------ Achieve unprecedented app performance and reliability What every C/C++ and Fortran developer should know. Learn how Intel has extended the reach of its next-generation tools to help boost performance applications - inlcuding clusters. http://p.sf.net/sfu/intel-dev2devmay _______________________________________________ Libcg-devel mailing list Libcg-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libcg-devel