コード例 #1
0
def setup_logging(log_file):
    file_logging_stream = open(log_file, 'w')

    # We want to have all stdout and stderr messages in the logfile.
    # In the frozen version we cannot log to sys.stderr because it's
    # broken on windows. Stdout doesn't work either it seems.
    stderr_streams = [file_logging_stream]
    stdout_streams = [file_logging_stream]
    if not filesystem.main_is_frozen():
        stderr_streams.append(sys.__stderr__)
        stdout_streams.append(sys.__stdout__)
    sys.stderr = utils.StreamDuplicator(stderr_streams)
    sys.stdout = utils.StreamDuplicator(stdout_streams)

    root_logger = logging.getLogger('')
    root_logger.setLevel(logging.DEBUG)

    # Python adds a default handler if some log is generated before here
    # Remove all handlers that have been added automatically
    for handler in root_logger.handlers:
        root_logger.removeHandler(handler)

    # define a Handler which writes messages to sys.stdout
    console = logging.StreamHandler(sys.stdout)
    console.setLevel(logging.DEBUG)
    # set a format which is simpler for console use
    formatter = logging.Formatter('%(asctime)s %(levelname)-8s %(message)s')
    # tell the handler to use this format
    console.setFormatter(formatter)
    # add the handler to the root logger
    root_logger.addHandler(console)

    logging.info('Writing log to file "%s"' % log_file)
コード例 #2
0
ファイル: journal.py プロジェクト: rakotomandimby/rednotebook
def setup_logging(log_file):
    file_logging_stream = open(log_file, 'w')

    # We want to have all stdout and stderr messages in the logfile.
    # In the frozen version we cannot log to sys.stderr because it's
    # broken on windows. Stdout doesn't work either it seems.
    stderr_streams = [file_logging_stream]
    stdout_streams = [file_logging_stream]
    if not filesystem.main_is_frozen():
        stderr_streams.append(sys.__stderr__)
        stdout_streams.append(sys.__stdout__)
    sys.stderr = utils.StreamDuplicator(stderr_streams)
    sys.stdout = utils.StreamDuplicator(stdout_streams)

    root_logger = logging.getLogger('')
    root_logger.setLevel(logging.DEBUG)

    # Python adds a default handler if some log is generated before here
    # Remove all handlers that have been added automatically
    for handler in root_logger.handlers:
        root_logger.removeHandler(handler)

    # define a Handler which writes messages to sys.stdout
    console = logging.StreamHandler(sys.stdout)
    console.setLevel(logging.DEBUG)
    # set a format which is simpler for console use
    formatter = logging.Formatter('%(asctime)s %(levelname)-8s %(message)s')
    # tell the handler to use this format
    console.setFormatter(formatter)
    # add the handler to the root logger
    root_logger.addHandler(console)

    logging.info('Writing log to file "%s"' % log_file)
コード例 #3
0
ファイル: browser.py プロジェクト: tomka/rednotebook
def windows_webkit_import():
    global webkit
    
    cwd = os.getcwd()
    
    if filesystem.main_is_frozen():
        gtk_bin_dir = filesystem.app_dir
    else:
        gtk_bin_dir = r'C:\GTK'
        
    try:
        # It seems the dlls are only found if we are in the bin dir
        # during import
        os.chdir(gtk_bin_dir)
    except WindowsError:
        logging.error('Changing dir to "%s" failed' % gtk_bin_dir)
        return
    
    try:
        import webkit
    except ImportError:
        logging.info('webkit not found. For a nicer preview install python-webkit or pywebkitgtk')
    os.chdir(cwd)