python类ERROR的实例源码

setup_logging.py 文件源码 项目:sphinxcontrib-versioning 作者: Robpol86 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def format(self, record):
        """Apply little arrow and colors to the record.

        Arrow and colors are only applied to sphinxcontrib.versioning log statements.

        :param logging.LogRecord record: The log record object to log.
        """
        formatted = super(ColorFormatter, self).format(record)
        if self.verbose or not record.name.startswith(self.SPECIAL_SCOPE):
            return formatted

        # Arrow.
        formatted = '=> ' + formatted

        # Colors.
        if not self.colors:
            return formatted
        if record.levelno >= logging.ERROR:
            formatted = str(colorclass.Color.red(formatted))
        elif record.levelno >= logging.WARNING:
            formatted = str(colorclass.Color.yellow(formatted))
        else:
            formatted = str(colorclass.Color.cyan(formatted))
        return formatted
__init__.py 文件源码 项目:core-framework 作者: RedhawkSDR 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def ConvertLog4ToCFLevel( log4level ):
      if  log4level == logging.FATAL+1 :
          return CF.LogLevels.OFF
      if  log4level == logging.FATAL :
          return CF.LogLevels.FATAL
      if  log4level == logging.ERROR :
          return CF.LogLevels.ERROR
      if  log4level == logging.WARN :
          return CF.LogLevels.WARN
      if  log4level == logging.INFO :
          return CF.LogLevels.INFO
      if  log4level == logging.DEBUG :
          return CF.LogLevels.DEBUG
      if  log4level == logging.TRACE :
          return CF.LogLevels.TRACE
      if  log4level == logging.NOTSET:
          return CF.LogLevels.ALL
      return CF.LogLevels.INFO
__init__.py 文件源码 项目:core-framework 作者: RedhawkSDR 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def ConvertToLog4Level( newLevel ):
    level = logging.INFO
    if  newLevel == CF.LogLevels.OFF :
            level=logging.FATAL+1
    if  newLevel == CF.LogLevels.FATAL :
            level=logging.FATAL
    if  newLevel == CF.LogLevels.ERROR :
            level=logging.ERROR
    if  newLevel == CF.LogLevels.WARN :
            level=logging.WARN
    if  newLevel == CF.LogLevels.INFO:
            level=logging.INFO
    if  newLevel == CF.LogLevels.DEBUG:
            level=logging.DEBUG
    if  newLevel == CF.LogLevels.TRACE:
            level=logging.TRACE
    if  newLevel == CF.LogLevels.ALL:
            level=logging.TRACE
    return level
jobs.py 文件源码 项目:jobs 作者: josiahcarlson 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def maker(name):
        my_level = getattr(logging, name.upper()) if name != 'exception' else logging.ERROR
        altname = (name if name != 'exception' else 'error').upper()
        def _log(self, msg, *args, **kwargs):
            exc = kwargs.pop('exc_info', None) or name == 'exception'
            tb = ('\n' + traceback.format_exc().strip()) if exc else ''
            if args:
                try:
                    msg = msg % args
                except:
                    self.exception(
                        "Exception raised while formatting message:\n%s\n%r",
                        msg, args)
            msg += tb
            # todo: check level before printing
            if self.level <= my_level:
                print("%s %s %s"%(time.asctime(), altname, msg))
        _log.__name__ = name
        return _log
handlers.py 文件源码 项目:kinect-2-libras 作者: inessadl 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def __init__(self, appname, dllname=None, logtype="Application"):
        logging.Handler.__init__(self)
        try:
            import win32evtlogutil, win32evtlog
            self.appname = appname
            self._welu = win32evtlogutil
            if not dllname:
                dllname = os.path.split(self._welu.__file__)
                dllname = os.path.split(dllname[0])
                dllname = os.path.join(dllname[0], r'win32service.pyd')
            self.dllname = dllname
            self.logtype = logtype
            self._welu.AddSourceToRegistry(appname, dllname, logtype)
            self.deftype = win32evtlog.EVENTLOG_ERROR_TYPE
            self.typemap = {
                logging.DEBUG   : win32evtlog.EVENTLOG_INFORMATION_TYPE,
                logging.INFO    : win32evtlog.EVENTLOG_INFORMATION_TYPE,
                logging.WARNING : win32evtlog.EVENTLOG_WARNING_TYPE,
                logging.ERROR   : win32evtlog.EVENTLOG_ERROR_TYPE,
                logging.CRITICAL: win32evtlog.EVENTLOG_ERROR_TYPE,
         }
        except ImportError:
            print("The Python Win32 extensions for NT (service, event "\
                        "logging) appear not to be available.")
            self._welu = None
amazon_account_utils.py 文件源码 项目:openbare 作者: openbare 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def log(self, message, level=logging.DEBUG, depth=0):
        """Prepend string to log messages to denote class."""
        if depth <= 0:
            prefix = 'AmazonAccountUtils: '
        else:
            prefix = "\t" * depth

        if level == CRITICAL:
            self.logger.critical(prefix + str(message))
        elif level == ERROR:
            self.logger.error(prefix + str(message))
        elif level == WARNING:
            self.logger.warning(prefix + str(message))
        elif level == INFO:
            self.logger.info(prefix + str(message))
        else:
            self.logger.debug(prefix + str(message))
abe.py 文件源码 项目:abe-bootstrap 作者: TryCoin-Team 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def q_hashpubkey(abe, page, chain):
        """shows the 160-bit hash of the given public key."""
        pubkey = wsgiref.util.shift_path_info(page['env'])
        if pubkey is None:
            return \
                "Returns the 160-bit hash of PUBKEY.\n" \
                "For example, the Bitcoin genesis block's output public key," \
                " seen in its transaction output scriptPubKey, starts with\n" \
                "04678afdb0fe..., and its hash is" \
                " 62E907B15CBF27D5425399EBF6F0FB50EBB88F18, corresponding" \
                " to address 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa.\n" \
                "/q/hashpubkey/PUBKEY\n"
        try:
            pubkey = pubkey.decode('hex')
        except Exception:
            return 'ERROR: invalid hexadecimal byte string.'
        return util.pubkey_to_hash(pubkey).encode('hex').upper()
log.py 文件源码 项目:Flask_Blog 作者: sugarguo 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def deprecated(self, removal_version, msg, *args, **kwargs):
        """
        Logs deprecation message which is log level WARN if the
        ``removal_version`` is > 1 minor release away and log level ERROR
        otherwise.

        removal_version should be the version that the deprecated feature is
        expected to be removed in, so something that will not exist in
        version 1.7, but will in 1.6 would have a removal_version of 1.7.
        """
        from pip import __version__

        if should_warn(__version__, removal_version):
            self.warn(msg, *args, **kwargs)
        else:
            self.error(msg, *args, **kwargs)
visualize.py 文件源码 项目:mbin 作者: fanglab 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def __check_input( opts, args, parser ):
    """
    Make sure the input is in the form of either a cmp.h5 file of aligned reads
    or a FOFN of unaligned bas.h5 files. Also make sure that a reference fasta 
    file is specified if 
    """
    if len(args)!=2:
        print "ERROR -- expecting two arguments: \
                 (1) <SEQ>_methyl_features.txt output from methylprofiles containing methylation features for mapping \
                 (2) <SEQ>_other_features.txt output from methylprofiles containing alternative sequence features for mapping"

    mfeats_fn  = args[0]
    ofeats_fn  = args[1]
    feature_type = None

    if not os.path.exists(mfeats_fn):
        parser.error("Can't find file of sequence features (methylprofiles output) for mapping: %s" % mfeats_fn)

    if not os.path.exists(ofeats_fn):
        parser.error("Can't find file of sequence features (methylprofiles output) for mapping: %s" % ofeats_fn)

    return mfeats_fn, ofeats_fn
SaffronTree.py 文件源码 项目:saffrontree 作者: sanger-pathogens 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def __init__(self,options):
        self.start_time = int(time.time())
        self.logger = logging.getLogger(__name__)
        self.output_directory           = options.output_directory 
        self.verbose                    = options.verbose
        self.threads                    = options.threads
        self.kmer                       = options.kmer
        self.min_kmers_threshold        = options.min_kmers_threshold
        self.max_kmers_threshold        = options.max_kmers_threshold
        self.input_files                = options.input_files
        self.keep_files                 = options.keep_files
        self.object_to_be_cleaned       = []

        if self.verbose:
            self.logger.setLevel(logging.DEBUG)
        else:
            self.logger.setLevel(logging.ERROR)
        self.kmc_major_version = KmcVersionDetect(self.verbose).major_version()
KmcFastq.py 文件源码 项目:saffrontree 作者: sanger-pathogens 项目源码 文件源码 阅读 39 收藏 0 点赞 0 评论 0
def __init__(self,output_directory, input_filename, threads, kmer, min_kmers_threshold, max_kmers_threshold, verbose):
        self.logger = logging.getLogger(__name__)
        self.output_directory = output_directory
        self.input_filename = input_filename
        self.threads = threads
        self.kmer = kmer

        if self.file_type_option() == '-fm':
            # a FASTA file doesnt have a depth of coverage
            self.min_kmers_threshold = 1
        else:
            self.min_kmers_threshold = min_kmers_threshold

        self.max_kmers_threshold = max_kmers_threshold
        self.temp_working_dir = tempfile.mkdtemp(dir=os.path.abspath(output_directory),prefix='tmp_samplekmers_')
        self.verbose = verbose
        if self.verbose:
            self.logger.setLevel(logging.DEBUG)
        else:
            self.logger.setLevel(logging.ERROR)
spct_downloader.py 文件源码 项目:specton 作者: somesortoferror 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def getDLsize(self):
        debug_log("getDLsize called")
        it = QTreeWidgetItemIterator(self.tw)
        while it.value():
            item = it.value()
            url_test = item.data(0, dataURL)
            if url_test is not None:
                try:
                    r = requests.head(url_test)
                    r.raise_for_status()
                    try:
                        size = (int(r.headers['Content-Length']) / 1024) / 1024
                    except ValueError:
                        size = 0
                    if size > 0:
                        item.setText(2, "{} MiB".format(round(size, 2)))
                except requests.exceptions.HTTPError:
                    debug_log("Error {} getting DL size: {}".format(r.status_code, r.headers))
                    item.setText(2, r.status_code)
                except requests.exceptions.RequestException as e:
                    item.setText(2, self.tr("Error"))
                    debug_log(e, logging.ERROR)
            it += 1
log_test.py 文件源码 项目:noc-orchestrator 作者: DirceuSilvaLabs 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def setUp(self):
        self.formatter = LogFormatter(color=False)
        # Fake color support.  We can't guarantee anything about the $TERM
        # variable when the tests are run, so just patch in some values
        # for testing.  (testing with color off fails to expose some potential
        # encoding issues from the control characters)
        self.formatter._colors = {
            logging.ERROR: u("\u0001"),
        }
        self.formatter._normal = u("\u0002")
        # construct a Logger directly to bypass getLogger's caching
        self.logger = logging.Logger('LogFormatterTest')
        self.logger.propagate = False
        self.tempdir = tempfile.mkdtemp()
        self.filename = os.path.join(self.tempdir, 'log.out')
        self.handler = self.make_handler(self.filename)
        self.handler.setFormatter(self.formatter)
        self.logger.addHandler(self.handler)
app.py 文件源码 项目:sharkfacts 作者: andrewthetechie 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def _get_logging_level():
    """
    Converts our ENV variable HA_LOG_LEVEL to a logging level object
    :return: logging level object
    """
    _log_level = _get_config('LOG_LEVEL', 'info').lower()

    to_return = logging.INFO

    if _log_level == 'critical':
        to_return = logging.CRITICAL
    if _log_level == 'error':
        to_return = logging.ERROR
    if _log_level == 'warning':
        to_return = logging.WARNING
    if _log_level == 'debug':
        to_return = logging.DEBUG

    return to_return
registrar_client.py 文件源码 项目:python-keylime 作者: mit-ll 项目源码 文件源码 阅读 38 收藏 0 点赞 0 评论 0
def doActivateNode(registrar_ip,registrar_port,instance_id,key):
    data = {
    'auth_tag': crypto.do_hmac(base64.b64decode(key),instance_id),
    }

    v_json_message = json.dumps(data)

    response = tornado_requests.request("PUT",
                                        "http://%s:%s/v2/instances/%s/activate"%(registrar_ip,registrar_port,instance_id),
                                        data=v_json_message,
                                        context=None)

    if response.status_code == 200:
        logger.info("Registration activated for node %s."%instance_id)
    else:
        logger.error("Error: unexpected http response code from Registrar Server: " + str(response.status_code))
        common.log_http_response(logger,logging.ERROR,response.json())
registrar_client.py 文件源码 项目:python-keylime 作者: mit-ll 项目源码 文件源码 阅读 61 收藏 0 点赞 0 评论 0
def doActivateVirtualNode(registrar_ip,registrar_port,instance_id,deepquote):
    data = {
    'deepquote': deepquote,
    }

    v_json_message = json.dumps(data)

    response = tornado_requests.request("PUT",
                                        "http://%s:%s/v2/instances/%s/vactivate"%(registrar_ip,registrar_port,instance_id),
                                        data=v_json_message,
                                        context=None)

    if response.status_code == 200:
        logger.info("Registration activated for node %s."%instance_id)
    else:
        logger.error("Error: unexpected http response code from Registrar Server: " + str(response.status_code))
        common.log_http_response(logger,logging.ERROR,response.json())
init.py 文件源码 项目:Projects 作者: SilverLuke 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def add_coloring_to_emit_ansi(fn):
    RED_BOLD = '\x1b[31;1m'
    RED      = '\x1b[31m'
    GREEN    = '\x1b[32m'
    YELLOW   = '\x1b[33m'
    BLUE     = '\x1b[34m'
    PINK     = '\x1b[35m'
    CYAN     = '\x1b[36m'
    DEFAULT  = '\x1b[0m'
    def new(*args):
        levelno = args[1].levelno
        color = DEFAULT
        if levelno >= logging.CRITICAL:
            color = RED_BOLD
        elif levelno >= logging.ERROR:
            color = RED
        elif levelno >= logging.WARNING:
            color = YELLOW
        elif levelno >= logging.INFO:
            color = DEFAULT
        elif levelno >= logging.DEBUG:
            color = GREEN
        args[1].msg = color + str(args[1].msg) + DEFAULT
        return fn(*args)
    return new
api.py 文件源码 项目:geekcloud 作者: Mr-Linus 项目源码 文件源码 阅读 44 收藏 0 点赞 0 评论 0
def set_log(level, filename='jumpserver.log'):
    """
    return a log file object
    ??????log??
    """
    log_file = os.path.join(LOG_DIR, filename)
    if not os.path.isfile(log_file):
        os.mknod(log_file)
        os.chmod(log_file, 0777)
    log_level_total = {'debug': logging.DEBUG, 'info': logging.INFO, 'warning': logging.WARN, 'error': logging.ERROR,
                       'critical': logging.CRITICAL}
    logger_f = logging.getLogger('jumpserver')
    logger_f.setLevel(logging.DEBUG)
    fh = logging.FileHandler(log_file)
    fh.setLevel(log_level_total.get(level, logging.DEBUG))
    formatter = logging.Formatter('%(asctime)s - %(filename)s - %(levelname)s - %(message)s')
    fh.setFormatter(formatter)
    logger_f.addHandler(fh)
    return logger_f
twampy.py 文件源码 项目:twampy 作者: nokia 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def connectionSetup(self):
        log.info("CTRL.RX <<Server Greeting>>")
        data = self.receive()
        self.smode = struct.unpack('!I', data[12:16])[0]
        log.info("TWAMP modes supported: %d", self.smode)
        if self.smode & 1 == 0:
            log.critical('*** TWAMPY only supports unauthenticated mode(1)')

        log.info("CTRL.TX <<Setup Response>>")
        self.send(struct.pack('!I', 1) + zeros(160))

        log.info("CTRL.RX <<Server Start>>")
        data = self.receive()

        rval = ord(data[15])
        if rval != 0:
            # TWAMP setup request not accepted by server
            log.critical("*** ERROR CODE %d in <<Server Start>>", rval)

        self.nbrSessions = 0
conf_client.py 文件源码 项目:trellio 作者: artificilabs 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def get_smtp_logging_handler(self):
        if self.settings.get(self.smtp_key):
            keys = ["smtp_host", "smtp_port", "smtp_user", "smtp_password"]
            setting_keys = self.settings[self.smtp_key].keys()
            missing_keys = list(filter(lambda x: x not in setting_keys, keys))
            if not missing_keys:
                handler = BufferingSMTPHandler(mailhost=self.settings[self.smtp_key]['smtp_host'],
                                               mailport=self.settings[self.smtp_key]['smtp_port'],
                                               fromaddr=self.settings[self.smtp_key]['smtp_user'],
                                               toaddrs=self.settings[self.admin_emails],
                                               subject='Error {} {}:{}'.format(self.settings[self.host_name_key],
                                                                               self.settings[
                                                                                   self.service_name_key].upper(),
                                                                               self.settings[self.service_version_key]),
                                               capacity=1,
                                               password=self.settings[self.smtp_key]['smtp_password'])
                handler.setLevel(logging.ERROR)
                if not self.settings[self.ronin_key]:
                    return handler
calm.py 文件源码 项目:calm 作者: cygwin 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def process(args, state):
    # send one email per run to leads, if any errors occurred
    with mail_logs(args.email, toaddrs=args.email, subject='%s' % (state.subject), thresholdLevel=logging.ERROR) as leads_email:
        if args.dryrun:
            logging.warning("--dry-run is in effect, nothing will really be done")

        state.packages = process_relarea(args)
        if not state.packages:
            return None

        state.packages = process_uploads(args, state)

    return state.packages


#
# remove stale packages
#
BLog.py 文件源码 项目:zabbix_manager 作者: BillWang139967 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def __init__(self, fmt = None, datefmt = None):
        logging.Formatter.__init__(self, fmt, datefmt)
        # Color escape string
        COLOR_RED='\033[1;31m'
        COLOR_GREEN='\033[1;32m'
        COLOR_YELLOW='\033[1;33m'
        COLOR_BLUE='\033[1;34m'
        COLOR_PURPLE='\033[1;35m'
        COLOR_CYAN='\033[1;36m'
        COLOR_GRAY='\033[1;37m'
        COLOR_WHITE='\033[1;38m'
        COLOR_RESET='\033[1;0m'

        # Define log color
        self.LOG_COLORS = {
            'DEBUG': '%s',
            'INFO': COLOR_GREEN + '%s' + COLOR_RESET,
            'WARNING': COLOR_YELLOW + '%s' + COLOR_RESET,
            'ERROR': COLOR_RED + '%s' + COLOR_RESET,
            'CRITICAL': COLOR_RED + '%s' + COLOR_RESET,
            'EXCEPTION': COLOR_RED + '%s' + COLOR_RESET,
        }
BLog.py 文件源码 项目:zabbix_manager 作者: BillWang139967 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def tolog(self, msg, level=None):
        try:
            level = level if level else self._level
            level = str(level).lower()
            level = self.get_map_level(level)
            if level == logging.DEBUG:
                self._logger.debug(msg)
            if level == logging.INFO:
                self._logger.info(msg)
            if level == logging.WARN:
                self._logger.warn(msg)
            if level == logging.ERROR:
                self._logger.error(msg)
            if level == logging.CRITICAL:
                self._logger.critical(msg)
        except Exception as expt:
            print expt
config.py 文件源码 项目:user-sync.py 作者: adobe-apiplatform 项目源码 文件源码 阅读 39 收藏 0 点赞 0 评论 0
def report_unused_values(self, logger, optional_configs=None):
        optional_configs = [] if optional_configs is None else optional_configs
        has_error = False
        for config in self.iter_configs():
            messages = config.describe_unused_values()
            if len(messages) > 0:
                if config in optional_configs:
                    log_level = logging.WARNING
                else:
                    log_level = logging.ERROR
                    has_error = True
                for message in messages:
                    logger.log(log_level, message)

        if has_error:
            raise AssertionException('Detected unused keys that are not ignorable.')
sum_and_product.py 文件源码 项目:robograph 作者: csparpa 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def logged_sum_and_product(list_of_numbers):
    v = value.Value(value=list_of_numbers)
    s = apply.Apply(function=sum)
    m = apply.Apply(function=lambda c: reduce(lambda x, y: x * y, c))
    b = buffers.Buffer()

    logging.basicConfig(level=logging.ERROR)
    p = printer.LogPrinter(logger=logging.getLogger(__name__),
                           loglevel=logging.ERROR)

    g = graph.Graph('logged_sum_and_product', [v, s, m, b, p])

    g.connect(p, b, 'message')
    g.connect(b, s, 'sum value')
    g.connect(b, m, 'product value')
    g.connect(s, v, 'argument')
    g.connect(m, v, 'argument')

    return g
sum_and_product.py 文件源码 项目:robograph 作者: csparpa 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def logged_sum_and_product(list_of_numbers):
    v = value.Value(value=list_of_numbers)
    s = apply.Apply(function=sum)
    m = apply.Apply(function=lambda c: reduce(lambda x, y: x * y, c))
    b = buffers.Buffer()

    logging.basicConfig(level=logging.ERROR)
    p = printer.LogPrinter(logger=logging.getLogger(__name__),
                           loglevel=logging.ERROR)

    g = graph.Graph('logged_sum_and_product', [v, s, m, b, p])

    g.connect(p, b, 'message')
    g.connect(b, s, 'sum value')
    g.connect(b, m, 'product value')
    g.connect(s, v, 'argument')
    g.connect(m, v, 'argument')

    return g
iosxr_show_install_version.py 文件源码 项目:iosxr-ansible 作者: ios-xr 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def init_logging (logfile):
    # Initialize the logging infra and add a handler
    logger = logging.getLogger ("ydk") 
    logger.setLevel (logging.DEBUG)

    # create file handler             
    fh = logging.FileHandler (logfile)
    fh.setLevel (logging.DEBUG)

    # create a console logger too
    ch = logging.StreamHandler ()
    ch.setLevel (logging.ERROR)

    # add the handlers to the logger
    logger.addHandler (fh)
    logger.addHandler (ch)
log.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def deprecated(self, removal_version, msg, *args, **kwargs):
        """
        Logs deprecation message which is log level WARN if the
        ``removal_version`` is > 1 minor release away and log level ERROR
        otherwise.

        removal_version should be the version that the deprecated feature is
        expected to be removed in, so something that will not exist in
        version 1.7, but will in 1.6 would have a removal_version of 1.7.
        """
        from pip import __version__

        if should_warn(__version__, removal_version):
            self.warn(msg, *args, **kwargs)
        else:
            self.error(msg, *args, **kwargs)
handlers.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def __init__(self, appname, dllname=None, logtype="Application"):
        logging.Handler.__init__(self)
        try:
            import win32evtlogutil, win32evtlog
            self.appname = appname
            self._welu = win32evtlogutil
            if not dllname:
                dllname = os.path.split(self._welu.__file__)
                dllname = os.path.split(dllname[0])
                dllname = os.path.join(dllname[0], r'win32service.pyd')
            self.dllname = dllname
            self.logtype = logtype
            self._welu.AddSourceToRegistry(appname, dllname, logtype)
            self.deftype = win32evtlog.EVENTLOG_ERROR_TYPE
            self.typemap = {
                logging.DEBUG   : win32evtlog.EVENTLOG_INFORMATION_TYPE,
                logging.INFO    : win32evtlog.EVENTLOG_INFORMATION_TYPE,
                logging.WARNING : win32evtlog.EVENTLOG_WARNING_TYPE,
                logging.ERROR   : win32evtlog.EVENTLOG_ERROR_TYPE,
                logging.CRITICAL: win32evtlog.EVENTLOG_ERROR_TYPE,
         }
        except ImportError:
            print("The Python Win32 extensions for NT (service, event "\
                        "logging) appear not to be available.")
            self._welu = None
config.py 文件源码 项目:circleci-demo-python-flask 作者: CircleCI-Public 项目源码 文件源码 阅读 93 收藏 0 点赞 0 评论 0
def init_app(cls, app):
        Config.init_app(app)

        # email errors to the administrators
        import logging
        from logging.handlers import SMTPHandler
        credentials = None
        secure = None
        if getattr(cls, 'MAIL_USERNAME', None) is not None:
            credentials = (cls.MAIL_USERNAME, cls.MAIL_PASSWORD)
            if getattr(cls, 'MAIL_USE_TLS', None):
                secure = ()
        mail_handler = SMTPHandler(
            mailhost=(cls.MAIL_SERVER, cls.MAIL_PORT),
            fromaddr=cls.CIRCULATE_MAIL_SENDER,
            toaddrs=[cls.CIRCULATE_ADMIN],
            subject=cls.CIRCULATE_MAIL_SUBJECT_PREFIX + ' Application Error',
            credentials=credentials,
            secure=secure)
        mail_handler.setLevel(logging.ERROR)
        app.logger.addHandler(mail_handler)


问题


面经


文章

微信
公众号

扫码关注公众号