Esempio n. 1
0
def log(logfile="", mode="w", top=10):
    """Enable logging to the given file.

If the file name is unspecified, a default name is built by appending
a 'log-psyco' extension to the main script name.

Mode is 'a' to append to a possibly existing file or 'w' to overwrite
an existing file. Note that the log file may grow quickly in 'a' mode."""
    import profiler, logger

    if not logfile:
        import os

        logfile, dummy = os.path.splitext(sys.argv[0])
        if os.path.basename(logfile):
            logfile += "."
        logfile += "log-psyco"
    if hasattr(_psyco, "VERBOSE_LEVEL"):
        print >>sys.stderr, "psyco: logging to", logfile
    # logger.current should be a real file object; subtle problems
    # will show up if its write() and flush() methods are written
    # in Python, as Psyco will invoke them while compiling.
    logger.current = open(logfile, mode)
    logger.print_charges = top
    profiler.logger = logger
    logger.writedate("Logging started")
    cannotcompile(logger.psycowrite)
    _psyco.statwrite(logger=logger.psycowrite)
Esempio n. 2
0
def log(logfile='', mode='w', top=10):
    """Enable logging to the given file.

If the file name is unspecified, a default name is built by appending
a 'log-psyco' extension to the main script name.

Mode is 'a' to append to a possibly existing file or 'w' to overwrite
an existing file. Note that the log file may grow quickly in 'a' mode."""
    import profiler, logger
    if not logfile:
        import os
        logfile, dummy = os.path.splitext(sys.argv[0])
        if os.path.basename(logfile):
            logfile += '.'
        logfile += 'log-psyco'
    if hasattr(_psyco, 'VERBOSE_LEVEL'):
        print >> sys.stderr, 'psyco: logging to', logfile
    # logger.current should be a real file object; subtle problems
    # will show up if its write() and flush() methods are written
    # in Python, as Psyco will invoke them while compiling.
    logger.current = open(logfile, mode)
    logger.print_charges = top
    profiler.logger = logger
    logger.writedate('Logging started')
    cannotcompile(logger.psycowrite)
    _psyco.statwrite(logger=logger.psycowrite)