Python logging.CRITICAL() Examples

The following are code examples for showing how to use logging.CRITICAL(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the exmaples you don't like. You can also save this page to your account.

Example 1
Project: kinect-2-libras   Author: inessadl   File: handlers.py    (Apache License 2.0) View Source Project 6 votes vote down vote up
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 
Example 2
Project: openbare   Author: openbare   File: amazon_account_utils.py    (GNU General Public License v3.0) View Source Project 6 votes vote down vote up
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)) 
Example 3
Project: aio-service-client   Author: alfred82santa   File: tests_formatters.py    (GNU Lesser General Public License v3.0) View Source Project 6 votes vote down vote up
def test_on_parse_exception(self):

        log_entry = self.logger.makeRecord('test', logging.CRITICAL, 'test_request', 22, 'Test Message', tuple(), None,
                                           extra={'action': 'EXCEPTION',
                                                  'method': 'GET',
                                                  'url': 'http://example.com',
                                                  'headers': OrderedDict([('Test-Header-1', 'header value 1'),
                                                                          ('Test-Header-2', 'header value 2')]),
                                                  'body': 'foobar',
                                                  'status_code': 404,
                                                  'elapsed': timedelta(seconds=0.214),
                                                  'exception': AttributeError('test exception')})
        log_text = """EXCEPTION | GET http://example.com | 404 Not Found | 214 ms | AttributeError('test exception',)
Headers:
Test-Header-1: header value 1
Test-Header-2: header value 2
Body:
foobar"""

        self.assertEqual(self.formatter.formatMessage(log_entry), log_text) 
Example 4
Project: aio-service-client   Author: alfred82santa   File: tests_plugins.py    (GNU Lesser General Public License v3.0) View Source Project 6 votes vote down vote up
def test_on_parse_exception(self):
        ex = AttributeError('Testing Exception')
        resp = await self.session.request()
        await self.plugin.before_request(self.endpoint_desc, self.session, self.request_params)
        await self.plugin.on_parse_exception(self.endpoint_desc, self.session, self.request_params, resp, ex)

        self.assertEqual(self.logger.level, logging.CRITICAL)
        self.assertEqual(self.logger.message, "Testing Exception")
        self.assertEqual(self.logger.args, tuple())
        self.maxDiff = None
        self.assertEqual(self.logger.kwargs,
                         {"extra": {'action': 'EXCEPTION',
                                    'endpoint': 'test_endpoint',
                                    'path_param1': 'foo',
                                    'path_param2': 'bar',
                                    'service_name': 'test_service',
                                    'status_code': resp.status,
                                    'body': 'sss',
                                    'elapsed': resp.elapsed,
                                    'headers': resp.headers,
                                    'exception': ex}}) 
Example 5
Project: sharkfacts   Author: andrewthetechie   File: app.py    (MIT License) View Source Project 6 votes vote down vote up
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 
Example 6
Project: Projects   Author: SilverLuke   File: init.py    (license) View Source Project 6 votes vote down vote up
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 
Example 7
Project: geekcloud   Author: Mr-Linus   File: api.py    (GNU General Public License v2.0) View Source Project 6 votes vote down vote up
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 
Example 8
Project: aws-encryption-sdk-cli   Author: awslabs   File: logging_utils.py    (Apache License 2.0) View Source Project 6 votes vote down vote up
def _logging_levels(verbosity, quiet):
    # type: (int, bool) -> Sequence[int]
    """Determines the proper logging levels given required verbosity level and quiet.

    :param int verbosity: Requested level of verbosity
    :param bool quiet: Suppresses all logging when true
    :returns: local and root logging levels
    :rtype: list of int
    """
    if quiet:
        return logging.CRITICAL, logging.CRITICAL

    if verbosity is None or verbosity <= 0:
        return logging.WARNING, logging.CRITICAL

    normalized_local = min(verbosity, MAX_LOGGING_LEVEL)
    normalized_root = min(verbosity - normalized_local, MAX_LOGGING_LEVEL)
    return LOGGING_LEVELS[normalized_local], LOGGING_LEVELS[normalized_root] 
Example 9
Project: zabbix_manager   Author: BillWang139967   File: BLog.py    (Apache License 2.0) View Source Project 6 votes vote down vote up
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,
        } 
Example 10
Project: zabbix_manager   Author: BillWang139967   File: BLog.py    (Apache License 2.0) View Source Project 6 votes vote down vote up
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 
Example 11
Project: hostapd-mana   Author: adde88   File: handlers.py    (license) View Source Project 6 votes vote down vote up
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 
Example 12
Project: tumdlr   Author: FujiMakoto   File: main.py    (license) View Source Project 6 votes vote down vote up
def cli(ctx, config, quiet, debug):
    """
    Tumblr Downloader CLI utility
    """
    # Logging setup
    if debug:
        log_level = logging.DEBUG
    else:
        log_level = logging.CRITICAL if quiet else logging.WARN

    ctx.log = logging.getLogger('tumdlr')
    ctx.log.setLevel(log_level)

    ch = logging.StreamHandler()
    ch.setLevel(log_level)
    ch.setFormatter(logging.Formatter('[%(levelname)s] %(name)s: %(message)s'))
    ctx.log.addHandler(ch)

    # First run?
    if not ctx.config['Development'].getboolean('AgreedToTerms'):
        first_run(ctx) 
Example 13
Project: llk   Author: Tycx2ry   File: exif_log.py    (license) View Source Project 6 votes vote down vote up
def format(self, record):
        if self.debug and self.color:
            if record.levelno >= logging.CRITICAL:
                color = TEXT_RED
            elif record.levelno >= logging.ERROR:
                color = TEXT_RED
            elif record.levelno >= logging.WARNING:
                color = TEXT_YELLOW
            elif record.levelno >= logging.INFO:
                color = TEXT_GREEN
            elif record.levelno >= logging.DEBUG:
                color = TEXT_CYAN
            else:
                color = TEXT_NORMAL
            record.levelname = "\x1b[%sm%s\x1b[%sm" % (color, record.levelname, TEXT_NORMAL)
        return logging.Formatter.format(self, record) 
Example 14
Project: TFExperiments   Author: gnperdue   File: utils_mnist.py    (license) View Source Project 6 votes vote down vote up
def get_logging_level(log_level):
    logging_level = logging.INFO
    if log_level == 'DEBUG':
        logging_level = logging.DEBUG
    elif log_level == 'INFO':
        logging_level = logging.INFO
    elif log_level == 'WARNING':
        logging_level = logging.WARNING
    elif log_level == 'ERROR':
        logging_level = logging.ERROR
    elif log_level == 'CRITICAL':
        logging_level = logging.CRITICAL
    else:
        print('Unknown or unset logging level. Using INFO')

    return logging_level 
Example 15
Project: QXSConsolas   Author: qxsch   File: Cli.py    (license) View Source Project 6 votes vote down vote up
def run(self, argv = None, data = None, logger = None):
        """
        Runs the function
        """
        if not logger is None:
            assert isinstance(logger, logging.Logger), "logger is not a valid logging.Logger"
            self.logger = logger
        if not data is None:
            assert isinstance(data, Configuration), "data is not a valid QXSConsolas.Configuration.Configuration"
            self.data = data

        self.options, self.arguments = self._argparser.parseArguments(argv)
        if self._argparser.loglevel == 1:
            self._configureConsoleLoggers(logging.NOTSET, True)
        elif self._argparser.loglevel == -1:
            self._configureConsoleLoggers(logging.CRITICAL, False)
        try:
            self._argparser.validateRequiredArguments()
            return self._app(ApplicationData(self))
        except Exception as e:
            logger.exception(e)
            return 1 
Example 16
Project: QXSConsolas   Author: qxsch   File: Cli.py    (license) View Source Project 6 votes vote down vote up
def run(self, argv = None, data = None, logger = None):
        """
        Runs the function
        """
        if not logger is None:
            assert isinstance(logger, logging.Logger), "logger is not a valid logging.Logger"
            self.logger = logger
        if not data is None:
            assert isinstance(data, Configuration), "data is not a valid QXSConsolas.Configuration.Configuration"
            self.data = data

        self.options, self.arguments = self._argparser.parseArguments(argv)
        if self._argparser.loglevel == 1:
            self._configureConsoleLoggers(logging.NOTSET, True)
        elif self._argparser.loglevel == -1:
            self._configureConsoleLoggers(logging.CRITICAL, False)
        try:
            self._argparser.validateRequiredArguments()
            return self._app(ApplicationData(self))
        except Exception as e:
            logger.exception(e)
            return 1 
Example 17
Project: PGPool   Author: sLoPPydrive   File: console.py    (license) View Source Project 6 votes vote down vote up
def input_processor(state):
    mainlog = logging.getLogger()
    global default_log_level

    while True:
        # Wait for the user to press a key.
        command = raw_input()

        if command == '':
            # Toggle between scouts and log view
            state['display'] = 'stats' if state['display'] == 'logs' else 'logs'
            log.info("Showing {}".format(state['display']))

        # Disable logging if in fullscreen more
        if state['display'] == 'logs':
            mainlog.setLevel(default_log_level)
        else:
            mainlog.setLevel(logging.CRITICAL) 
Example 18
Project: Grating_Advanced_Simulation_Platform   Author: GratingLaboratories   File: init.py    (license) View Source Project 6 votes vote down vote up
def format(self, record):
        stdout_template = '{levelname}' + Fore.RESET + '] {threadName}: ' + '{message}'
        stdout_head = '[%s'

        allFormats = {
            logging.DEBUG: logging.StrFormatStyle(stdout_head % Fore.LIGHTBLUE_EX + stdout_template),
            logging.INFO: logging.StrFormatStyle(stdout_head % Fore.GREEN + stdout_template),
            logging.WARNING: logging.StrFormatStyle(stdout_head % Fore.LIGHTYELLOW_EX + stdout_template),
            logging.ERROR: logging.StrFormatStyle(stdout_head % Fore.LIGHTRED_EX + stdout_template),
            logging.CRITICAL: logging.StrFormatStyle(stdout_head % Fore.RED + stdout_template)
        }

        self._style = allFormats.get(record.levelno, logging.StrFormatStyle(logging._STYLES['{'][1]))
        self._fmt = self._style._fmt
        result = logging.Formatter.format(self, record)

        return result 
Example 19
Project: nojs   Author: chrisdickinson   File: logging_utils.py    (license) View Source Project 6 votes vote down vote up
def SuppressLogging(level=logging.ERROR):
  """Momentarilly suppress logging events from all loggers.

  TODO(jbudorick): This is not thread safe. Log events from other threads might
  also inadvertently disappear.

  Example:

    with logging_utils.SuppressLogging():
      # all but CRITICAL logging messages are suppressed
      logging.info('just doing some thing') # not shown
      logging.critical('something really bad happened') # still shown

  Args:
    level: logging events with this or lower levels are suppressed.
  """
  logging.disable(level)
  yield
  logging.disable(logging.NOTSET) 
Example 20
Project: spiderfoot   Author: wi-fi-analyzer   File: exif_log.py    (license) View Source Project 6 votes vote down vote up
def format(self, record):
        if self.debug and self.color:
            if record.levelno >= logging.CRITICAL:
                color = TEXT_RED
            elif record.levelno >= logging.ERROR:
                color = TEXT_RED
            elif record.levelno >= logging.WARNING:
                color = TEXT_YELLOW
            elif record.levelno >= logging.INFO:
                color = TEXT_GREEN
            elif record.levelno >= logging.DEBUG:
                color = TEXT_CYAN
            else:
                color = TEXT_NORMAL
            record.levelname = "\x1b[%sm%s\x1b[%sm" % (color, record.levelname, TEXT_NORMAL)
        return logging.Formatter.format(self, record) 
Example 21
Project: touch-pay-client   Author: HackPucBemobi   File: test_router.py    (license) View Source Project 6 votes vote down vote up
def test_router_syntax(self):
        """ Test router syntax error """
        level = logger.getEffectiveLevel()
        logger.setLevel(logging.CRITICAL)  # disable logging temporarily
        self.assertRaises(SyntaxError, load, data='x::y')
        self.assertRaises(
            SyntaxError, load, rdict=dict(BASE=dict(badkey="value")))
        self.assertRaises(SyntaxError, load, rdict=dict(
            BASE=dict(), app=dict(default_application="name")))

        self.myassertRaisesRegex(SyntaxError, "invalid syntax",
                                load, data='x::y')
        self.myassertRaisesRegex(SyntaxError, "unknown key",
                                load, rdict=dict(BASE=dict(badkey="value")))
        self.myassertRaisesRegex(SyntaxError, "BASE-only key",
                                load, rdict=dict(BASE=dict(), app=dict(default_application="name")))
        logger.setLevel(level) 
Example 22
Project: pipless   Author: d0c-s4vage   File: __init__.py    (license) View Source Project 6 votes vote down vote up
def _pip_main(self, *args):
        """Run pip.main with the specified ``args``
        """
        if self.quiet:
            import logging
            pip_log = logging.getLogger("pip")
            _level = pip_log.level
            pip_log.setLevel(logging.CRITICAL)
        elif self._should_color():
            self._sys.stdout.write("\x1b[36m")

        try:
            self._pip.main(list(args))
        finally:
            if self.quiet:
                pip_log.setLevel(_level)
            elif self._should_color():
                self._sys.stdout.write("\x1b[0m")
                self._sys.stdout.flush() 
Example 23
Project: core-python   Author: yidao620c   File: logmsg.py    (license) View Source Project 6 votes vote down vote up
def my_log():
    logging.basicConfig(level=logging.INFO,
                        format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
                        datefmt='%Y-%m-%d %H:%M:%S',
                        handlers=[logging.FileHandler('message.log', 'a', 'utf-8')])
    # ?????_?????__
    _log = logging.getLogger('app.' + __name__)
    host = '10.0.0.175'
    port = 8080
    # ??? 'xxxx' % (aa, bb)????????
    _log.error('error to connect to %s:%d', host, port)
    _log.addFilter(FilterFunc('foo'))  # ?????foo()???????
    lgg = logging.getLogger('app.network.client')
    lgg.propagate = False  # ??????
    lgg.error('do you see me?')  # ????????
    lgg.setLevel(logging.CRITICAL)
    lgg.error('now you see me?')
    logging.disable(logging.DEBUG)  # ????????
    # ??log??????main?????????
    config.fileConfig('applogcfg.ini') 
Example 24
Project: osc-lib   Author: openstack   File: test_logs.py    (license) View Source Project 6 votes vote down vote up
def test_log_level_from_config(self):
        cfg = {'verbose_level': 0}
        self.assertEqual(logging.ERROR, logs.log_level_from_config(cfg))
        cfg = {'verbose_level': 1}
        self.assertEqual(logging.WARNING, logs.log_level_from_config(cfg))
        cfg = {'verbose_level': 2}
        self.assertEqual(logging.INFO, logs.log_level_from_config(cfg))
        cfg = {'verbose_level': 3}
        self.assertEqual(logging.DEBUG, logs.log_level_from_config(cfg))
        cfg = {'verbose_level': 1, 'log_level': 'critical'}
        self.assertEqual(logging.CRITICAL, logs.log_level_from_config(cfg))
        cfg = {'verbose_level': 1, 'log_level': 'error'}
        self.assertEqual(logging.ERROR, logs.log_level_from_config(cfg))
        cfg = {'verbose_level': 1, 'log_level': 'warning'}
        self.assertEqual(logging.WARNING, logs.log_level_from_config(cfg))
        cfg = {'verbose_level': 1, 'log_level': 'info'}
        self.assertEqual(logging.INFO, logs.log_level_from_config(cfg))
        cfg = {'verbose_level': 1, 'log_level': 'debug'}
        self.assertEqual(logging.DEBUG, logs.log_level_from_config(cfg))
        cfg = {'verbose_level': 1, 'log_level': 'bogus'}
        self.assertEqual(logging.WARNING, logs.log_level_from_config(cfg))
        cfg = {'verbose_level': 1, 'log_level': 'info', 'debug': True}
        self.assertEqual(logging.DEBUG, logs.log_level_from_config(cfg)) 
Example 25
Project: flowsynth   Author: secureworks   File: flowsynth.py    (license) View Source Project 6 votes vote down vote up
def parse_cmd_line():
    """ use ArgumentParser to parse command line arguments """

    app_description = "FlowSynth v%s\nWill Urbanski <[email protected]>\n\na tool for rapidly modeling network traffic" % APP_VERSION_STRING

    parser = argparse.ArgumentParser(description=app_description, formatter_class = argparse.RawTextHelpFormatter)
    parser.add_argument('input', help='input files')
    parser.add_argument('-f', dest='output_format', action='store', default="hex",
        help='Output format. Valid output formats include: hex, pcap')
    parser.add_argument('-w', dest='output_file', action='store', default="", help='Output file.')
    parser.add_argument('-q', dest='quiet', action='store_true', default=False, help='Run silently')
    parser.add_argument('-d', dest='debug', action='store_true', default=False, help='Run in debug mode')
    parser.add_argument('--display', dest='display', action='store', default='text', choices=['text','json'], help='Display format')
    parser.add_argument('--no-filecontent', dest='no_filecontent', action='store_true', default=False, help='Disable support for the filecontent attribute')

    args = parser.parse_args()

    if (args.quiet == True):
        LOGGING_LEVEL = logging.CRITICAL
    if (args.debug == True):
        LOGGING_LEVEL = logging.DEBUG

    return args 
Example 26
Project: trappist1   Author: rodluger   File: data.py    (license) View Source Project 6 votes vote down vote up
def __init__(self, fitsfile, ID = 0, quiet = False, clobber = False, cadence = 'lc', **kwargs):
    '''
    
    '''
    
    # Read kwargs
    self.ID = ID
    self._season = 12
    self.mission = 'k2'
    self.clobber = clobber
    self.cadence = cadence
    
    # Initialize preliminary logging
    if not quiet:
      screen_level = logging.DEBUG
    else:
      screen_level = logging.CRITICAL
    everest.utils.InitLog(None, logging.DEBUG, screen_level, False)

    # Load
    self.fitsfile = fitsfile
    self.model_name = pyfits.getheader(self.fitsfile, 1)['MODEL']
    self._weights = None
    self.load_fits() 
Example 27
Project: zabbix_templates   Author: BillWang139967   File: mdb_sstat.py    (license) View Source Project 6 votes vote down vote up
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,
        } 
Example 28
Project: zabbix_templates   Author: BillWang139967   File: mdb_sstat.py    (license) View Source Project 6 votes vote down vote up
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 
Example 29
Project: zabbix_templates   Author: BillWang139967   File: QLog.py    (license) View Source Project 6 votes vote down vote up
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,
        } 
Example 30
Project: zabbix_templates   Author: BillWang139967   File: QLog.py    (license) View Source Project 6 votes vote down vote up
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 
Example 31
Project: zabbix_templates   Author: BillWang139967   File: redis.py    (license) View Source Project 6 votes vote down vote up
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,
        } 
Example 32
Project: zabbix_templates   Author: BillWang139967   File: redis.py    (license) View Source Project 6 votes vote down vote up
def get_map_level(self,level="debug"):
        level = str(level).lower()
        #print "get_map_level:",level
        if level == "debug":
            return logging.DEBUG
        if level == "info":
            return logging.INFO
        if level == "warn":
            return logging.WARN
        if level == "error":
            return logging.ERROR
        if level == "critical":
            return logging.CRITICAL
        
#}}}
#{{{Redis 
Example 33
Project: scriptworker   Author: mozilla-releng   File: verify.py    (license) View Source Project 6 votes vote down vote up
def raise_on_errors(errors, level=logging.CRITICAL):
    """Raise a CoTError if errors.

    Helper function because I had this code block everywhere.

    Args:
        errors (list): the error errors
        level (int, optional): the log level to use.  Defaults to logging.CRITICAL

    Raises:
        CoTError: if errors is non-empty

    """
    if errors:
        log.log(level, "\n".join(errors))
        raise CoTError("\n".join(errors))


# guess_worker_impl {{{1 
Example 34
Project: MyPythonLib   Author: BillWang139967   File: BLog.py    (license) View Source Project 6 votes vote down vote up
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,
        } 
Example 35
Project: MyPythonLib   Author: BillWang139967   File: BLog.py    (license) View Source Project 6 votes vote down vote up
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 
Example 36
Project: bjarkan   Author: GetWellNetwork   File: logger.py    (license) View Source Project 6 votes vote down vote up
def getLevel( self ):
        """
        A convenience wrapper around ``getEffectiveLevel()`` because the integer values for the
        various logging levels are clunky and probably don't mean anything to you.

        Returns:
            str: the name of the effective log level for this logging object, in lowercase
            (``"warning"``, ``"info"``, etc.)
        """
        level = self.getEffectiveLevel()
        if level == logging.CRITICAL:
            return 'critical'
        elif level == logging.ERROR:
            return 'error'
        elif level == logging.WARNING:
            return 'warning'
        elif level == logging.INFO:
            return 'info'
        elif level == logging.DEBUG:
            return 'debug'
        elif level == logging.NOTSET:
            return 'notset'
        else:
            return 'unknown ({})'.format( level ) 
Example 37
Project: jubakit   Author: jubatus   File: logger.py    (license) View Source Project 6 votes vote down vote up
def init(cls):
    cls.logger = logging.getLogger(_LOGGER_NAME)
    logger = cls.logger
    levelname = os.environ.get('JUBAKIT_LOG_LEVEL', None)
    if not levelname:
      # Surpress printing logs by default.
      logger.addHandler(cls._NullHandler())
      logger.setLevel(CRITICAL)
      return

    # Setup logger from environment variable.
    for lvl in (DEBUG, INFO, WARNING, ERROR, CRITICAL):
      if logging.getLevelName(lvl) == levelname:
        setup_logger(lvl)
        break
    else:
      setup_logger(INFO)
      logger.warning('invalid JUBAKIT_LOG_LEVEL (%s) specified; continue with INFO', levelname) 
Example 38
Project: pyglmnet   Author: glm-tools   File: utils.py    (license) View Source Project 6 votes vote down vote up
def set_log_level(verbose):
    """Convenience function for setting the log level.

    Parameters
    ----------
    verbose : bool, str, int, or None
        The verbosity of messages to print. If a str, it can be either DEBUG,
        INFO, WARNING, ERROR, or CRITICAL. Note that these are for
        convenience and are equivalent to passing in logging.DEBUG, etc.
        For bool, True is the same as 'INFO', False is the same as 'WARNING'.
    """
    if isinstance(verbose, bool):
        if verbose is True:
            verbose = 'INFO'
        else:
            verbose = 'WARNING'
    if isinstance(verbose, str):
        verbose = verbose.upper()
        logging_types = dict(DEBUG=logging.DEBUG, INFO=logging.INFO,
                             WARNING=logging.WARNING, ERROR=logging.ERROR,
                             CRITICAL=logging.CRITICAL)
        if verbose not in logging_types:
            raise ValueError('verbose must be of a valid type')
        verbose = logging_types[verbose]
    logger.setLevel(verbose) 
Example 39
Project: lava-hadoop-processing   Author: lavalamp-   File: cclogging.py    (license) View Source Project 6 votes vote down vote up
def format(self, record):
        """
        Format the contents of the given record to log.
        :param record: The record to log.
        :return: Results of calling super.format.
        """
        if record.levelno == logging.CRITICAL:
            self._fmt = LavaLogFormatter.CRITICAL
        elif record.levelno == logging.ERROR:
            self._fmt = LavaLogFormatter.ERROR
        elif record.levelno == logging.WARNING:
            self._fmt = LavaLogFormatter.WARNING
        elif record.levelno == logging.INFO:
            self._fmt = LavaLogFormatter.INFO
        elif record.levelno == logging.DEBUG:
            self._fmt = LavaLogFormatter.DEBUG
        return super(LavaLogFormatter, self).format(record) 
Example 40
Project: lava-hadoop-processing   Author: lavalamp-   File: run.py    (license) View Source Project 6 votes vote down vote up
def configure_logging(log_level):
    """
    Configure logging.
    :param log_level: The level to configure logging at.
    :return: None
    """
    lvl = None
    if log_level.upper() == "INFO":
        lvl = logging.INFO
    elif log_level.upper() == "WARNING":
        lvl = logging.WARNING
    elif log_level.upper() == "ERROR":
        lvl = logging.ERROR
    elif log_level.upper() == "CRITICAL":
        lvl = logging.CRITICAL
    elif log_level.upper() == "DEBUG":
        lvl = logging.DEBUG
    if not lvl:
        raise ValueError("%s is not a valid log level." % log_level)
    logger.setLevel(lvl)
    formatter = LavaLogFormatter()
    stream_handler = logging.StreamHandler()
    stream_handler.setFormatter(formatter)
    logger.addHandler(stream_handler)
    ConfigManager.LOGGING_LEVEL = lvl 
Example 41
Project: vulssimulator_ds   Author: kn0630   File: core.py    (license) View Source Project 6 votes vote down vote up
def log_at_level(self, value):
        """
        Make sure logging is always set at a valid level
        """
        if value in [
            logging.CRITICAL,
            logging.DEBUG,
            logging.ERROR,
            logging.FATAL,
            logging.INFO,
            logging.WARNING,
        ]:
            self._log_at_level = value
            self._set_logging()
        else:
            if not self._log_at_level:
                self._log_at_level = logging.WARNING
                self._set_logging()

    # *******************************************************************
    # methods
    # ******************************************************************* 
Example 42
Project: true_review_web2py   Author: lucadealfaro   File: test_router.py    (license) View Source Project 6 votes vote down vote up
def test_router_syntax(self):
        """ Test router syntax error """
        level = logger.getEffectiveLevel()
        logger.setLevel(logging.CRITICAL)  # disable logging temporarily
        self.assertRaises(SyntaxError, load, data='x:y')
        self.assertRaises(
            SyntaxError, load, rdict=dict(BASE=dict(badkey="value")))
        self.assertRaises(SyntaxError, load, rdict=dict(
            BASE=dict(), app=dict(default_application="name")))
        try:
            # 2.7+ only
            self.assertRaisesRegexp(SyntaxError, "invalid syntax",
                                    load, data='x:y')
            self.assertRaisesRegexp(SyntaxError, "unknown key",
                                    load, rdict=dict(BASE=dict(badkey="value")))
            self.assertRaisesRegexp(SyntaxError, "BASE-only key",
                                    load, rdict=dict(BASE=dict(), app=dict(default_application="name")))
        except AttributeError:
            pass
        logger.setLevel(level) 
Example 43
Project: geekcloud   Author: GeekCloud-Team   File: api.py    (license) View Source Project 6 votes vote down vote up
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 
Example 44
Project: webdirfuzz   Author: Fenguopeng   File: log.py    (license) View Source Project 6 votes vote down vote up
def init_logger(name='webdirfuzz', log_file_path=None):
    """
    ???????
    """
    logger = logging.getLogger(name)
    log_handler = logging.FileHandler(log_file_path)

    formatter = logging.Formatter(
        '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    log_handler.setFormatter(formatter)
    ll = (logging.CRITICAL,
          logging.ERROR,
          logging.WARNING,
          logging.INFO,
          logging.DEBUG)
    logger.setLevel(ll[4])
    log_handler.setLevel(ll[4])
    logger.addHandler(log_handler)
    return logger 
Example 45
Project: chromium-build   Author: discordapp   File: logging_utils.py    (license) View Source Project 6 votes vote down vote up
def SuppressLogging(level=logging.ERROR):
  """Momentarilly suppress logging events from all loggers.

  TODO(jbudorick): This is not thread safe. Log events from other threads might
  also inadvertently dissapear.

  Example:

    with logging_utils.SuppressLogging():
      # all but CRITICAL logging messages are suppressed
      logging.info('just doing some thing') # not shown
      logging.critical('something really bad happened') # still shown

  Args:
    level: logging events with this or lower levels are suppressed.
  """
  logging.disable(level)
  yield
  logging.disable(logging.NOTSET) 
Example 46
Project: LoveIsInTheAir-Stats-Plotter   Author: sahilsareen   File: StatesTweetCount.py    (license) View Source Project 6 votes vote down vote up
def __init__(self, config_file=DEFAULT_CONFIG_FILE):
        self.config = ConfigReader(config_file)
        self.states = {}
        self.geo_locator = Nominatim()
        self.tweet_count = 0
        self.city_cache_appender = CacheAppender(self.config.cache_file_path)

        def get_level():
            return {
                'DEBUG': logging.DEBUG,
                'INFO': logging.INFO,
                'WARN': logging.WARNING,
                'ERROR': logging.ERROR,
                'FATAL': logging.FATAL,
                'CRITICAL': logging.CRITICAL
            }[self.config.logging_level]

        logging.basicConfig(format="[%(levelname)s] %(name)s: %(message)s", level=get_level())

        self.logger = logging.getLogger(self.__class__.__name__)
        self.logger.info("Analysing city names using config in %s" % config_file) 
Example 47
Project: CommunityCellularManager   Author: facebookincubator   File: __init__.py    (license) View Source Project 6 votes vote down vote up
def _get_logging_level(level):
        """ Map a syslog level to a logging level. The logging module
        levels start from 10 (DEBUG) and increase by 10 for every level of
        of severity (INFO, WARNING, ERROR, CRITICAL). syslog starts at 0
        for the most severe messages (EMERGENCY) and increases by 1 for
        each lower level of messages (ALERT, CRITICAL, etc.). Mapping is
        mostly straightforward. """
        assert level >= 0
        if level >= logging.DEBUG:
            # level is already a logging-compatible value
            return level
        if level > LOG_DEBUG:
            return logging.DEBUG
        return [
            logging.CRITICAL,  # syslog.LOG_EMERG
            logging.CRITICAL,  # syslog.LOG_ALERT,
            logging.CRITICAL,  # syslog.LOG_CRIT,
            logging.ERROR,     # syslog.LOG_ERR,
            logging.WARNING,   # syslog.LOG_WARNING,
            _NOTICE,           # syslog.LOG_NOTICE,
            logging.INFO,      # syslog.LOG_INFO,
            logging.DEBUG,     # syslog.LOG_DEBUG
        ][level] 
Example 48
Project: CommunityCellularManager   Author: facebookincubator   File: __init__.py    (license) View Source Project 6 votes vote down vote up
def _get_logging_level(level):
        """ Map a syslog level to a logging level. The logging module
        levels start from 10 (DEBUG) and increase by 10 for every level of
        of severity (INFO, WARNING, ERROR, CRITICAL). syslog starts at 0
        for the most severe messages (EMERGENCY) and increases by 1 for
        each lower level of messages (ALERT, CRITICAL, etc.). Mapping is
        mostly straightforward. """
        assert level >= 0
        if level >= logging.DEBUG:
            # level is already a logging-compatible value
            return level
        if level > LOG_DEBUG:
            return logging.DEBUG
        return [
            logging.CRITICAL,  # syslog.LOG_EMERG
            logging.CRITICAL,  # syslog.LOG_ALERT,
            logging.CRITICAL,  # syslog.LOG_CRIT,
            logging.ERROR,     # syslog.LOG_ERR,
            logging.WARNING,   # syslog.LOG_WARNING,
            _NOTICE,           # syslog.LOG_NOTICE,
            logging.INFO,      # syslog.LOG_INFO,
            logging.DEBUG,     # syslog.LOG_DEBUG
        ][level] 
Example 49
Project: CommunityCellularManager   Author: facebookincubator   File: __init__.py    (license) View Source Project 6 votes vote down vote up
def _get_logging_level(level):
        """ Map a syslog level to a logging level. The logging module
        levels start from 10 (DEBUG) and increase by 10 for every level of
        of severity (INFO, WARNING, ERROR, CRITICAL). syslog starts at 0
        for the most severe messages (EMERGENCY) and increases by 1 for
        each lower level of messages (ALERT, CRITICAL, etc.). Mapping is
        mostly straightforward. """
        assert level >= 0
        if level >= logging.DEBUG:
            # level is already a logging-compatible value
            return level
        if level > LOG_DEBUG:
            return logging.DEBUG
        return [
            logging.CRITICAL,  # syslog.LOG_EMERG
            logging.CRITICAL,  # syslog.LOG_ALERT,
            logging.CRITICAL,  # syslog.LOG_CRIT,
            logging.ERROR,     # syslog.LOG_ERR,
            logging.WARNING,   # syslog.LOG_WARNING,
            _NOTICE,           # syslog.LOG_NOTICE,
            logging.INFO,      # syslog.LOG_INFO,
            logging.DEBUG,     # syslog.LOG_DEBUG
        ][level] 
Example 50
Project: BlurDetection   Author: whdcumt   File: scripts.py    (license) View Source Project 6 votes vote down vote up
def get_logger(level=logging.INFO, quite=False, debug=False, to_file=''):
    """
    This function initialises a logger to stdout.
    :return: logger
    """
    assert level in [logging.DEBUG, logging.INFO, logging.WARNING, logging.CRITICAL]
    logger = logging.getLogger('main')
    formatter = logging.Formatter('%(asctime)s - %(funcName)s - %(levelname)s - %(message)s')
    if debug:
        level = logging.DEBUG
    logger.setLevel(level=level)
    if not quite:
        if to_file:
            fh = logging.FileHandler(to_file)
            fh.setLevel(level=level)
            fh.setFormatter(formatter)
            logger.addHandler(fh)
        else:
            ch = logging.StreamHandler()
            ch.setLevel(level=level)
            ch.setFormatter(formatter)
            logger.addHandler(ch)
    return logger