Helper function to create a Syslog handler.

    See `ulogger.syslog.SyslogHandlerBuilder` for arguments and
    supported keyword arguments.

    Returns:
        (obj): Instance of `logging.SysLogHandler`
189100
def get_handler(progname, address=None, proto=None, facility=None,
                fmt=None, datefmt=None, **_):
    
    builder = SyslogHandlerBuilder(
        progname, address=address, proto=proto, facility=facility,
        fmt=fmt, datefmt=datefmt)
    return builder.get_handler()
1146909
def build_flask_like_logger(
    logger_name='logger',
    log_level=None,
    log_dir=None,
    console_enabled=True,
    max_log_size=5*1024*1024,
    max_backup_logs=5,
    host=None):
    '''
    
    '''
    old_logger_class = logging.getLoggerClass()
    logging.setLoggerClass(FlaskLikeLogger)
    logger = logging.getLogger(logger_name)
    logging.setLoggerClass(old_logger_class)

    if log_level:
        logger.setLevel(log_level)
    if host:
        logger.set_host(host)
    logger.apply_default_handlers(log_dir, console_enabled, max_log_size, max_backup_logs)
    return logger
720608
def get_logger(cls):
        
        if cls.logger is None:
            cls.logger = logging.getLogger("django_auth_ldap")
            cls.logger.addHandler(logging.NullHandler())

        return cls.logger
1051248
def get_formatter(self, handler):
        
        if isinstance(handler, logging.handlers.SysLogHandler):
            formatter = '[%(levelname)-9s]'
        else:
            formatter = '[%(asctime)s] [%(levelname)-9s]'

        for p in self.prefix:
            formatter += ' [%s]' % (p)
        formatter = formatter + ' %(message)s'
        return logging.Formatter(formatter)
122786
def configureLogger(self):
        
        baseLogLevel = logging.DEBUG if self.isDebugLogging() else logging.INFO
        # create recorder app root logger
        logger = logging.getLogger(self._name)
        logger.setLevel(baseLogLevel)
        # file handler
        fh = handlers.RotatingFileHandler(path.join(self._getConfigPath(), self._name + '.log'),
                                          maxBytes=10 * 1024 * 1024, backupCount=10)
        fh.setLevel(baseLogLevel)
        # create console handler with a higher log level
        ch = logging.StreamHandler()
        ch.setLevel(logging.WARN)
        # create formatter and add it to the handlers
        formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(funcName)s - %(message)s')
        fh.setFormatter(formatter)
        ch.setFormatter(formatter)
        # add the handlers to the logger
        logger.addHandler(fh)
        logger.addHandler(ch)
        return logger
788320
def main():
    

    env = os.environ

    try:
        host = env['SYSLOG_SERVER']
        port = int(env['SYSLOG_PORT'])
        socktype = socket.SOCK_DGRAM if env['SYSLOG_PROTO'] == 'udp' \
            else socket.SOCK_STREAM
    except KeyError:
        sys.exit("SYSLOG_SERVER, SYSLOG_PORT and SYSLOG_PROTO are required.")

    handler = SysLogHandler(
        address=(host, port),
        socktype=socktype,
    )
    handler.setFormatter(PalletFormatter())

    for event_headers, event_data in supervisor_events(sys.stdin, sys.stdout):
        event = logging.LogRecord(
            name=event_headers['processname'],
            level=logging.INFO,
            pathname=None,
            lineno=0,
            msg=event_data,
            args=(),
            exc_info=None,
        )
        event.process = int(event_headers['pid'])
        handler.handle(event)
381896
def tree_handler(*args, **kwargs):
    
    global _TREE_HANDLER

    if not _TREE_HANDLER:
        _TREE_HANDLER = TreeHandler(*args, **kwargs)

    return _TREE_HANDLER
1275006
def log_to_syslog():
    
    # Get root logger
    rl = logging.getLogger()
    rl.setLevel('INFO')

    # Stderr gets critical messages (mostly config/setup issues)
    #   only when not daemonized
    stderr = logging.StreamHandler(stream=sys.stderr)
    stderr.setLevel(logging.CRITICAL)
    stderr.setFormatter(logging.Formatter(
        '%(asctime)s %(name)s: %(levelname)s %(message)s'))
    rl.addHandler(stderr)

    # All interesting data goes to syslog, using root logger's loglevel
    syslog = SysLogHandler(address='/dev/log', facility=SysLogHandler.LOG_MAIL)
    syslog.setFormatter(logging.Formatter(
        '%(name)s[%(process)d]: %(levelname)s %(message)s'))
    rl.addHandler(syslog)
169988
def _create_logger_(name):
    """"""
    logger = logging.getLogger(name)
    handler = logging.StreamHandler()
    handler.setFormatter(logging.Formatter('%(levelname)s %(message)s'))
    logger.addHandler(handler)
    logger.setLevel(logging.INFO)
    return logger
1127123
def get_logger(cls):
        
        if cls.logger is None:
            class NullHandler(logging.Handler):
                def emit(self, record):
                    pass

            cls.logger = logging.getLogger('django_auth_ldap')
            cls.logger.addHandler(NullHandler())

        return cls.logger
859104
def get_logger(self):
        
        if Global.LOGGER:
            Global.LOGGER.debug('configuring a logger')
        if self._logger_instance is not None:
            return self._logger_instance

        self._logger_instance = logging.getLogger("flowsLogger")
        self._logger_instance.setLevel(logging.DEBUG)

        log_format = '%(asctime)s - [%(levelname)s]|%(thread)d\t%(message)s'
        log_date_format = '%Y-%m-%d %H:%M:%S'
        formatter = logging.Formatter(log_format, log_date_format)

        new_log_stream_handler = logging.StreamHandler()
        new_log_stream_handler.setFormatter(formatter)
        new_log_stream_handler.setLevel(logging.INFO)

        self._logger_instance.addHandler(new_log_stream_handler)

        return self._logger_instance
1218742
def funclog(logger):
    """"""

    # check if logger is from structlog
    use_structlog = False
    if STRUCTLOG:
        if isinstance(logger, structlog._config.BoundLoggerLazyProxy):
            real_logger = logger
            use_structlog = True
    # If a Logger object is passed in, use that.  Otherwise, get the default
    # Logger.
    if use_structlog:
        pass
    elif isinstance(logger, Logger):
        real_logger = logger
    else:
        real_logger = getLogger()

    # __qualname__ is prettier but it didn't get added until 3.5
    name_attr = '__name__' if sys.version_info < (3, 5) else '__qualname__'

    def get_arg_string(args, kwargs):
        """Convert args and kwargs to a pretty string."""
        return ', '.join(["'{}'".format(a) if type(a) == str else
                          '{}'.format(a) for a in args] +
                         ["{}='{}'".format(a, v) if type(v) == str else
                          '{}={}'.format(a, v) for a, v in sorted(kwargs.items())])

    def real_decorator(fn):
        @functools.wraps(fn)
        def wrapper(*args, **kwargs):
            frame_info = inspect.getframeinfo(inspect.stack()[1][0])
            filename = os.path.basename(frame_info.filename)
            lineno = frame_info.lineno
            func_name = getattr(fn, name_attr)
            arg_string = get_arg_string(args, kwargs)
            source_info = '{}:{}:{}({})'.format(filename, lineno, func_name,
                                                arg_string)
            if use_structlog:
                real_logger.debug(u'calling', source_info=source_info)
            else:
                real_logger.debug(u'calling %s', source_info)
            try:
                res = fn(*args, **kwargs)
            except Exception as e:
                if use_structlog:
                    real_logger.exception(
                        u'{} threw exception'.format(source_info), e=e)
                else:
                    real_logger.exception(
                        u'%s threw exception:\n%s', source_info, e)
                raise
            if use_structlog:
                real_logger.debug(u'{} returned'.format(source_info), res=res)
            else:
                real_logger.debug(u'%s returned: %s', source_info, res)
            return res
        return wrapper

    if type(logger) == type(real_decorator):
        return real_decorator(logger)

    return real_decorator
315157
def patch_python_logging_handlers():
    '''
    
    '''
    logging.StreamHandler = StreamHandler
    logging.FileHandler = FileHandler
    logging.handlers.SysLogHandler = SysLogHandler
    logging.handlers.WatchedFileHandler = WatchedFileHandler
    logging.handlers.RotatingFileHandler = RotatingFileHandler
    if sys.version_info >= (3, 2):
        logging.handlers.QueueHandler = QueueHandler
974334
def add_logging_handler(handler, format_='file'):
    
    global __UTOOL_ROOT_LOGGER__
    if __UTOOL_ROOT_LOGGER__ is None:
        builtins.print('[WARNING] logger not started, cannot add handler')
        return
    # create formatter and add it to the handlers
    #logformat = '%Y-%m-%d %H:%M:%S'
    #logformat = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
    timeformat = '%H:%M:%S'
    if format_ == 'file':
        logformat = '[%(asctime)s]%(message)s'
    elif format_ == 'stdout':
        logformat = '%(message)s'
    else:
        raise AssertionError('unknown logging format_: %r' % format_)
    # Create formatter for handlers
    formatter = logging.Formatter(logformat, timeformat)
    handler.setLevel(logging.DEBUG)
    handler.setFormatter(formatter)
    __UTOOL_ROOT_LOGGER__.addHandler(handler)
42190
def get_logger(name=None):
    
    logging.setLoggerClass(CustomLogger)

    logger = logging.getLogger(name)
    logger.setLevel(logging.DEBUG)

    logger.addHandler(_get_info_handler())
    logger.addHandler(_get_out_handler())
    logger.addHandler(_get_warn_handler())
    logger.addHandler(_get_error_handler())
    logger.addHandler(_get_critical_handler())
    logger.addHandler(_get_success_handler())
    logger.propagate = False

    return logger
663484
def setup_logger():  # type: () -> logging.Logger
    
    formatter = logging.Formatter(
        fmt='%(levelname)s - %(module)s - %(message)s')

    handler = logging.StreamHandler()
    handler.setFormatter(formatter)

    logger = logging.getLogger()
    logger.setLevel(logging.DEBUG)
    logger.addHandler(handler)
    return logger
394349
def get_default_logger():
        
        handler = logging.StreamHandler()
        handler.setLevel(logging.DEBUG)
        handler.setFormatter(logging.Formatter(
            "[%(levelname)1.1s %(asctime)s %(name)s] %(message)s",
            "%y%m%d %H:%M:%S"))

        logger_name = "pydbal"
        if Connection._instance_count > 1:
            logger_name += ":" + str(Connection._instance_count)
        logger = logging.getLogger(logger_name)
        logger.setLevel(logging.DEBUG)
        logger.addHandler(handler)
        return logger