当前位置: 首页>>代码示例>>Python>>正文


Python fancylogger.logToScreen函数代码示例

本文整理汇总了Python中vsc.utils.fancylogger.logToScreen函数的典型用法代码示例。如果您正苦于以下问题:Python logToScreen函数的具体用法?Python logToScreen怎么用?Python logToScreen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了logToScreen函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

    def run(self, args):
        """Run 'create' subcommand."""
        optparser = CreateOptions(go_args=args, envvar_prefix=self.envvar_prefix, usage=self.usage_txt)
        options = optparser.options
        if not validate_pbs_option(options):
            sys.stderr.write('Missing config options. Exiting.\n')
            return 1

        label = options.label

        if not hc.validate_label(label, hc.known_cluster_labels()):
            sys.exit(1)

        if not hc.validate_hodconf_or_dist(options.hodconf, options.dist):
            sys.exit(1)

        try:
            j = PbsHodJob(optparser)
            hc.report_cluster_submission(label)
            j.run()
            jobs = j.state()
            hc.post_job_submission(label, jobs, optparser.options.workdir)
            return 0
        except StandardError as e:
            fancylogger.setLogFormat(fancylogger.TEST_LOGGING_FORMAT)
            fancylogger.logToScreen(enable=True)
            _log.raiseException(e.message)
开发者ID:ehiggs,项目名称:hanythingondemand,代码行数:27,代码来源:create.py

示例2: test_normal_logging

    def test_normal_logging(self):
        """
        Test if just using import logging, logging.warning still works after importing fancylogger
        """

        stringfile = StringIO()
        sys.stderr = stringfile
        handler = fancylogger.logToScreen()
        import logging
        msg = 'this is my string'
        logging.warning(msg)
        self.assertTrue(msg in stringfile.getvalue(),
                        msg="'%s' in '%s'" % (msg, stringfile.getvalue()))

        msg = 'there are many like it'
        logging.getLogger().warning(msg)
        self.assertTrue(msg in stringfile.getvalue(),
                        msg="'%s' in '%s'" % (msg, stringfile.getvalue()))

        msg = 'but this one is mine'
        logging.getLogger('mine').warning(msg)
        self.assertTrue(msg in stringfile.getvalue(),
                        msg="'%s' in '%s'" % (msg, stringfile.getvalue()))


        # restore
        fancylogger.logToScreen(enable=False, handler=handler)
开发者ID:Iepoev,项目名称:vsc-base,代码行数:27,代码来源:fancylogger.py

示例3: parse_options

def parse_options(args=None):
    """wrapper function for option parsing"""
    if os.environ.get("DEBUG_EASYBUILD_OPTIONS", "0").lower() in ("1", "true", "yes", "y"):
        # very early debug, to debug the generaloption itself
        fancylogger.logToScreen(enable=True)
        fancylogger.setLogLevel("DEBUG")

    usage = "%prog [options] easyconfig [...]"
    description = (
        "Builds software based on easyconfig (or parse a directory).\n"
        "Provide one or more easyconfigs or directories, use -H or --help more information."
    )

    try:
        eb_go = EasyBuildOptions(
            usage=usage,
            description=description,
            prog="eb",
            envvar_prefix=CONFIG_ENV_VAR_PREFIX,
            go_args=args,
            error_env_options=True,
            error_env_option_method=raise_easybuilderror,
        )
    except Exception, err:
        raise EasyBuildError("Failed to parse configuration options: %s" % err)
开发者ID:gppezzi,项目名称:easybuild-framework,代码行数:25,代码来源:options.py

示例4: parseoptions

    def parseoptions(self, options_list=None):
        """
        Handle mpirun mode:
          - continue with reduced set of commandline options
          - These options are the keys of opts_to_remove.
          - The values of opts_to_remove are the number of arguments of these options, that also need to be removed.
        """

        if options_list is None:
            options_list = self.default_parseoptions()

        newopts = options_list[:]  # copy
        if self.mpirunmode:
            opts_to_remove = {
                '-np': 1,
                '-machinefile': 1
            }

            for opt in opts_to_remove.keys():
                try:
                    pos = newopts.index(opt)
                    # remove 1 + args
                    del newopts[pos:pos + 1 + opts_to_remove[opt]]
                except ValueError:
                    continue

        GeneralOption.parseoptions(self, newopts)

        # set error logging to file as soon as possible
        if self.options.logtofile:
            print("logtofile %s" % self.options.logtofile)
            if os.path.exists(self.options.logtofile):
                os.remove(self.options.logtofile)
            fancylogger.logToFile(self.options.logtofile)
            fancylogger.logToScreen(False)
开发者ID:hpcugent,项目名称:vsc-mympirun,代码行数:35,代码来源:option.py

示例5: test_fancylogger_as_rootlogger_logging

    def test_fancylogger_as_rootlogger_logging(self):
        """
        Test if just using import logging, logging with logging uses fancylogger
        after setting the root logger
        """

        # test logging.root is loggin root logger
        # this is an assumption made to make the fancyrootlogger code work
        orig_root = logging.getLogger()
        self.assertEqual(logging.root, orig_root,
                         msg='logging.root is the root logger')
        self.assertFalse(isinstance(logging.root, fancylogger.FancyLogger),
                         msg='logging.root is not a FancyLogger')


        stringfile = StringIO()
        sys.stderr = stringfile
        handler = fancylogger.logToScreen()
        fancylogger.setLogLevelDebug()
        logger = fancylogger.getLogger()

        self.assertEqual(logger.handlers, [self.handler, handler],
                         msg='active handler for root fancylogger')
        self.assertEqual(logger.level, fancylogger.getLevelInt('DEBUG'), msg='debug level set')

        msg = 'this is my string'
        logging.debug(msg)
        self.assertEqual(stringfile.getvalue(), '',
                         msg="logging.debug reports nothing when fancylogger loglevel is debug")

        fancylogger.setroot()
        self.assertTrue(isinstance(logging.root, fancylogger.FancyLogger),
                         msg='logging.root is a FancyLogger after setRootLogger')
        self.assertEqual(logging.root.level, fancylogger.getLevelInt('DEBUG'), msg='debug level set for root')
        self.assertEqual(logger.level, logging.NOTSET, msg='original root fancylogger level set to NOTSET')

        self.assertEqual(logging.root.handlers, [self.handler, handler],
                         msg='active handler for root logger from previous root fancylogger')
        self.assertEqual(logger.handlers, [], msg='no active handlers on previous root fancylogger')

        root_logger = logging.getLogger('')
        self.assertEqual(root_logger, logging.root,
                        msg='logging.getLogger() returns logging.root FancyLogger')

        frl = fancylogger.getLogger()
        self.assertEqual(frl, logging.root,
                        msg='fancylogger.getLogger() returns logging.root FancyLogger')

        logging.debug(msg)
        self.assertTrue(msg in stringfile.getvalue(),
                         msg="logging.debug reports when fancylogger loglevel is debug")

        fancylogger.resetroot()
        self.assertEqual(logging.root, orig_root,
                         msg='logging.root is the original root logger after resetroot')

        # restore
        fancylogger.logToScreen(enable=False, handler=handler)
开发者ID:hpcugent,项目名称:vsc-base,代码行数:58,代码来源:fancylogger.py

示例6: parse_options

def parse_options(args=None):
    """wrapper function for option parsing"""
    if os.environ.get('DEBUG_EASYBUILD_OPTIONS', '0').lower() in ('1', 'true', 'yes', 'y'):
        # very early debug, to debug the generaloption itself
        fancylogger.logToScreen(enable=True)
        fancylogger.setLogLevel('DEBUG')

    usage = "%prog [options] easyconfig [...]"
    description = ("Builds software based on easyconfig (or parse a directory).\n"
                   "Provide one or more easyconfigs or directories, use -H or --help more information.")

    eb_go = EasyBuildOptions(usage=usage, description=description, prog='eb', envvar_prefix='EASYBUILD', go_args=args)
    return eb_go
开发者ID:JackPerdue,项目名称:easybuild-framework,代码行数:13,代码来源:options.py

示例7: run

 def run(self, args):
     """Run 'clean' subcommand."""
     optparser = CleanOptions(go_args=args, envvar_prefix=self.envvar_prefix, usage=self.usage_txt)
     try:
         pbs = rm_pbs.Pbs(optparser)
         state = pbs.state()
         labels = hc.known_cluster_labels()
         rm_master = rm_pbs.master_hostname()
         info = hc.mk_cluster_info_dict(labels, state, master=rm_master)
         hc.clean_cluster_info(rm_master, info)
     except StandardError as err:
         fancylogger.setLogFormat(fancylogger.TEST_LOGGING_FORMAT)
         fancylogger.logToScreen(enable=True)
         _log.raiseException(err.message)
开发者ID:ehiggs,项目名称:hanythingondemand,代码行数:14,代码来源:clean.py

示例8: init_logging

def init_logging(logfile, logtostdout=False, testing=False):
    """Initialize logging."""
    if logtostdout:
        fancylogger.logToScreen(enable=True, stdout=True)
    else:
        if logfile is None:
            # mkstemp returns (fd,filename), fd is from os.open, not regular open!
            fd, logfile = tempfile.mkstemp(suffix='.log', prefix='easybuild-')
            os.close(fd)

        fancylogger.logToFile(logfile)
        print_msg('temporary log file in case of crash %s' % (logfile), log=None, silent=testing)

    log = fancylogger.getLogger(fname=False)

    return log, logfile
开发者ID:dnangellight,项目名称:easybuild-framework,代码行数:16,代码来源:build_log.py

示例9: __init__

 def __init__(self, hostname, port, log_dir, filename, pidfile):
     """Constructor"""
     stdin = '/dev/null'
     stdout = os.path.join(log_dir, 'logging_error.log')
     stderr = os.path.join(log_dir, 'logging_error.log')
     Daemon.__init__(self, pidfile, stdin, stdout, stderr)
     self.hostname = hostname
     self.port = port
     #Set up logging
     # get logger, we will log to file
     fancylogger.logToScreen(False)
     # we want to log absolutely everything that's comming at us
     fancylogger.setLogLevel(0)
     self.logfile = os.path.join(log_dir, filename)
     fancylogger.logToFile(self.logfile)
     self.logger = fancylogger.getLogger()
     self.socket_ = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
开发者ID:hpcugent,项目名称:vsc-base,代码行数:17,代码来源:logdaemon.py

示例10: run

    def run(self, args):
        """Run 'batch' subcommand."""
        optparser = BatchOptions(go_args=args, envvar_prefix=self.envvar_prefix, usage=self.usage_txt)
        options = optparser.options
        if not validate_pbs_option(options):
            sys.stderr.write('Missing config options. Exiting.\n')
            return 1

        if optparser.options.script is None:
            sys.stderr.write('Missing script. Exiting.\n')
            return 1

        # resolve script path to absolute path
        optparser.options.script = os.path.abspath(optparser.options.script)

        if not os.path.exists(optparser.options.script):
            sys.stderr.write("Specified script does not exist: %s. Exiting.\n" % optparser.options.script)
            return 1

        # make sure script is executable
        cur_perms = os.stat(optparser.options.script)[stat.ST_MODE]
        if not (cur_perms & stat.S_IXUSR):
            print "Specified script %s is not executable yet, fixing that..." % optparser.options.script
            os.chmod(optparser.options.script, cur_perms|stat.S_IXUSR)

        label = options.label

        if not hc.validate_label(label, hc.known_cluster_labels()):
            sys.exit(1)

        if not hc.validate_hodconf_or_dist(options.hodconf, options.dist):
            sys.exit(1)

        try:
            j = PbsHodJob(optparser)
            hc.report_cluster_submission(label)
            j.run()
            jobs = j.state()
            hc.post_job_submission(label, jobs, optparser.options.workdir)
            return 0
        except StandardError as e:
            fancylogger.setLogFormat(fancylogger.TEST_LOGGING_FORMAT)
            fancylogger.logToScreen(enable=True)
            _log.raiseException(e.message)
开发者ID:ehiggs,项目名称:hanythingondemand,代码行数:44,代码来源:batch.py

示例11: test_normal_logging

    def test_normal_logging(self):
        """
        Test if just using import logging, logging.warning still works after importing fancylogger
        """
        _stderr = sys.stderr
        stringfile = StringIO()
        sys.stderr = stringfile
        handler = fancylogger.logToScreen()
        import logging
        logging.warning('this is my string')
        self.assertTrue('this is my string' in stringfile.getvalue())

        logging.getLogger().warning('there are many like it')
        self.assertTrue('there are many like it' in stringfile.getvalue())

        logging.getLogger('mine').warning('but this one is mine')
        self.assertTrue('but this one is mine' in stringfile.getvalue())

        # restore
        fancylogger.logToScreen(enable=False, handler=handler)
        sys.stderr = _stderr
开发者ID:billy-mahimahi,项目名称:vsc-base,代码行数:21,代码来源:fancylogger.py

示例12: _stream_stdouterr

    def _stream_stdouterr(self, isstdout=True, expect_match=True):
        """Log to stdout or stderror, check stdout or stderror"""
        fd, logfn = tempfile.mkstemp()
        # fh will be checked
        fh = os.fdopen(fd, 'w')

        _stdout = sys.stdout
        _stderr = sys.stderr

        if isstdout == expect_match:
            sys.stdout = fh
            sys.stderr = open(os.devnull, 'w')
        else:
            sys.stdout = open(os.devnull, 'w')
            sys.stderr = fh

        fancylogger.setLogLevelInfo()
        name = 'test_stream_stdout'
        lh = fancylogger.logToScreen(stdout=isstdout)
        logger = fancylogger.getLogger(name, fname=True, clsname=False)
        # logfn makes it unique
        msg = 'TEST isstdout %s expect_match %s logfn %s' % (isstdout, expect_match, logfn)
        logger.info(msg)

        # restore
        fancylogger.logToScreen(enable=False, handler=lh)
        sys.stdout = _stdout
        sys.stderr = _stderr

        fh2 = open(logfn)
        txt = fh2.read().strip()
        fh2.close()
        reg_exp = re.compile(r"INFO\s+\S+.%s.%s\s+\S+\s+%s" % (name, '_stream_stdouterr', msg))
        match = reg_exp.search(txt) is not None
        self.assertEqual(match, expect_match)

        try:
            os.remove(logfn)
        except:
            pass
开发者ID:Iepoev,项目名称:vsc-base,代码行数:40,代码来源:fancylogger.py

示例13: test_zzz_logtostdout

    def test_zzz_logtostdout(self):
        """Testing redirecting log to stdout."""

        fd, dummylogfn = tempfile.mkstemp(prefix='easybuild-dummy', suffix='.log')
        os.close(fd)

        for stdout_arg in ['--logtostdout', '-l']:

            _stdout = sys.stdout

            fd, fn = tempfile.mkstemp()
            fh = os.fdopen(fd, 'w')
            sys.stdout = fh

            args = [
                    '--software-name=somethingrandom',
                    '--robot', '.',
                    '--debug',
                    stdout_arg,
                   ]
            self.eb_main(args, logfile=dummylogfn)

            # make sure we restore
            sys.stdout.flush()
            sys.stdout = _stdout
            fancylogger.logToScreen(enable=False, stdout=True)

            outtxt = read_file(fn)

            self.assertTrue(len(outtxt) > 100, "Log messages are printed to stdout when %s is used (outtxt: %s)" % (stdout_arg, outtxt))

            # cleanup
            os.remove(fn)
            modify_env(os.environ, self.orig_environ)
            tempfile.tempdir = None

        if os.path.exists(dummylogfn):
            os.remove(dummylogfn)
        fancylogger.logToFile(self.logfile)
开发者ID:JackPerdue,项目名称:easybuild-framework,代码行数:39,代码来源:options.py

示例14: test_classname_in_log

    def test_classname_in_log(self):
        """Do a log and check if the classname is correctly in it"""
        _stderr = sys.stderr

        class Foobar:
            def somefunction(self):
                logger = fancylogger.getLogger(fname=True, clsname=True)
                logger.warn('we are logging something here')

        stringfile = StringIO()
        sys.stderr = stringfile
        handler = fancylogger.logToScreen()

        Foobar().somefunction()
        self.assertTrue('Foobar.somefunction' in stringfile.getvalue())
        stringfile.close()

        # restore
        fancylogger.logToScreen(enable=False, handler=handler)
        # and again
        stringfile = StringIO()
        sys.stderr = stringfile
        handler = fancylogger.logToScreen()
        classless_function()
        self.assertTrue('?.classless_function' in stringfile.getvalue())

        # restore
        fancylogger.logToScreen(enable=False, handler=handler)
        stringfile = StringIO()
        sys.stderr = stringfile

        fancylogger.setLogFormat("%(className)s blabla")
        handler = fancylogger.logToScreen()
        logger = fancylogger.getLogger(fname=False, clsname=False)
        logger.warn("blabla")
        print stringfile.getvalue()
        # this will only hold in debug mode, so also disable the test
        if __debug__:
            self.assertTrue('FancyLoggerTest' in stringfile.getvalue())
        # restore
        fancylogger.logToScreen(enable=False, handler=handler)
        sys.stderr = _stderr
开发者ID:Iepoev,项目名称:vsc-base,代码行数:42,代码来源:fancylogger.py

示例15: checkjob_data_location

This mimics the result of Moab's checkjob command, but without the
risks of letting users see job information of jobs that are not theirs.
"""
import cPickle
import os
import pwd
import time

from vsc.utils import fancylogger
from vsc.utils.generaloption import simple_option

MAXIMAL_AGE = 60 * 30  # 30 minutes

logger = fancylogger.getLogger("myshowq")
fancylogger.logToScreen(True)
fancylogger.setLogLevelWarning()


def checkjob_data_location(user_name, location):
    """Retrieve the pickled data form the right file.

    @type user_name: string
    @type location: string

    @param user_name: VSC user name (vscxyzuv)
    @param location: string defining the location of the pickle file
        - home: user's home directory
        - scratch: user's personal fileset on muk

    @returns: absolute path to the pickle file
开发者ID:piojo,项目名称:vsc-jobs,代码行数:30,代码来源:mycheckjob.py


注:本文中的vsc.utils.fancylogger.logToScreen函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。