On Fri, Jun 21, 2019 at 3:46 PM Tom Hromatka <tom.hroma...@oracle.com> wrote: > > This commit adds a Log() class for the functional test > suite. >
Could you please add a little more information in the commit log about Log, it's aim, goal and how it will be used in the future? > Signed-off-by: Tom Hromatka <tom.hroma...@oracle.com> Once the above is handled, Reviewed-by: Dhaval Giani <dhaval.gi...@oracle.com> > --- > tests/ftests/log.py | 66 > +++++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 66 insertions(+) > create mode 100644 tests/ftests/log.py > > diff --git a/tests/ftests/log.py b/tests/ftests/log.py > new file mode 100644 > index 0000000..d20f082 > --- /dev/null > +++ b/tests/ftests/log.py > @@ -0,0 +1,66 @@ > +#!/usr/bin/env python > +# > +# Log class for the libcgroup functional tests > +# > +# Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. > +# Author: Tom Hromatka <tom.hroma...@oracle.com> > +# > + > +# > +# This library is free software; you can redistribute it and/or modify it > +# under the terms of version 2.1 of the GNU Lesser General Public License as > +# published by the Free Software Foundation. > +# > +# This library is distributed in the hope that it will be useful, but WITHOUT > +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or > +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public > License > +# for more details. > +# > +# You should have received a copy of the GNU Lesser General Public License > +# along with this library; if not, see <http://www.gnu.org/licenses>. > +# > + > +import consts > +import datetime > +import log > + > +log_level = consts.DEFAULT_LOG_LEVEL > +log_file = consts.DEFAULT_LOG_FILE > +log_fd = None > + > + > +class Log(object): > + > + @staticmethod > + def log(msg, msg_level=consts.DEFAULT_LOG_LEVEL): > + if log_level >= msg_level: > + if log.log_fd is None: > + Log.open_logfd(log.log_file) > + > + timestamp = datetime.datetime.now().strftime('%b %d %H:%M:%S') > + log_fd.write("%s: %s\n" % (timestamp, msg)) > + > + @staticmethod > + def open_logfd(log_file): > + log.log_fd = open(log_file, "a") > + > + @staticmethod > + def log_critical(msg): > + Log.log("CRITICAL: %s" % msg, consts.LOG_CRITICAL) > + > + @staticmethod > + def log_warning(msg): > + Log.log("WARNING: %s" % msg, consts.LOG_WARNING) > + > + @staticmethod > + def log_debug(msg): > + Log.log("DEBUG: %s" % msg, consts.LOG_DEBUG) > + > + > +class LogError(Exception): > + def __init__(self, message): > + super(LogError, self).__init__(message) > + > + def __str__(self): > + out_str = "LogError:\n\tmessage = %s" % self.message > + return out_str > -- > 1.8.3.1 > > > > _______________________________________________ > Libcg-devel mailing list > Libcg-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/libcg-devel _______________________________________________ Libcg-devel mailing list Libcg-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libcg-devel