Exemple #1
0
def setup_python_logging(logging_settings):
    level = logging_settings.get("level", default_level)

    log_level = getattr(python_logging, level.upper())

    if log_level is python_logging.DEBUG:
        HTTPConnection.debuglevel = 1

    python_logging.basicConfig()
    python_logging.getLogger().setLevel(log_level)
    python_logging.getLogger().addHandler(EliotHandler())

    requests_log = python_logging.getLogger("urllib3")
    requests_log.addHandler(EliotHandler())
    requests_log.setLevel(log_level)
    requests_log.propagate = False

    cometd_log = python_logging.getLogger("aiocometd")
    cometd_log.addHandler(EliotHandler())
    cometd_log.setLevel(log_level)
    cometd_log.propagate = False

    multiprocessing_log = multiprocessing.get_logger()
    multiprocessing_log.addHandler(EliotHandler())
    multiprocessing_log.setLevel(log_level)
    multiprocessing_log.propagate = False
def _configure_logging(dest: Path_T) -> None:
    root = logging.getLogger()  # ISSUE: ambient
    # Add Eliot Handler to root Logger.
    root.addHandler(EliotHandler())
    # and to luigi
    logging.getLogger('luigi').addHandler(EliotHandler())
    logging.getLogger('luigi-interface').addHandler(EliotHandler())
    el.to_file(dest.open(mode='ab'))
 def eliotify_root_logger(self, level):
     rootlogger = logging.getLogger()
     rootlogger.handlers = [EliotHandler()]
     loggers = []
     lrmld = logging.root.manager.loggerDict
     loggers = loggers + [logging.getLogger(name) for name in lrmld]
     rootlogger.debug("Removing all existing log handlers.")
     for lgr in loggers:
         rootlogger.debug("Removing log handlers for '{}'".format(lgr.name))
         lgr.handlers = []
     if self.debug:
         # Reset root logger
         if level > logging.DEBUG:
             rootlogger.warn("Setting root logging level to DEBUG.")
             rootlogger.setLevel(logging.DEBUG)
     rootlogger.debug("Setting default log level to '{}'".format(level))
     rootlogger.setLevel(level)
     # There are some things we just don't want to log at DEBUG
     chattycathies = {
         "kubernetes": logging.WARNING,
         "urllib3": logging.WARNING,
         "JupyterHub": logging.INFO,
     }
     for k in chattycathies:
         v = chattycathies[k]
         lgr = logging.getLogger(k)
         el = lgr.getEffectiveLevel()
         if el < v:
             rootlogger.debug("Logger {} @level {} -> {}.".format(k, el, v))
             lgr.setLevel(v)
Exemple #4
0
def init_logging():
    eliot.register_exception_extractor(Exception,
                                       _add_exception_data_and_traceback)

    root_logger = logging.getLogger()
    root_logger.addHandler(EliotHandler())
    root_logger.setLevel(logging.DEBUG)
    logging.getLogger("morepath.directive").setLevel(logging.INFO)
    logging.getLogger("passlib.registry").setLevel(logging.INFO)
    logging.getLogger("passlib.utils.compat").setLevel(logging.INFO)
    logging.getLogger("parso").setLevel(logging.WARN)

    eliot.to_file(sys.stderr, encoder=EkklesiaLogEncoder)

    logging.captureWarnings(True)
def make_logger(name=None, level=None):
    """Create a logger with LSST-appropriate characteristics."""
    if name is None:
        # Get name of caller's class.
        #  From https://stackoverflow.com/questions/17065086/
        frame = inspect.stack()[1][0]
        name = _get_classname_from_frame(frame)
    logger = logging.getLogger(name)
    if name is None:
        logger.info("jupyterhubutils make_logger() called for root logger.")
        logger.info("not eliotify-ing root logger.")
        return logger
    logger.propagate = False
    if level is None:
        level = logging.getLogger().getEffectiveLevel()
    logger.setLevel(level)
    logger.handlers = [EliotHandler()]
    logger.info("Created logger object for class '{}'.".format(name))
    return logger
Exemple #6
0
import eliot
import logging
import sys
from eliot.stdlib import EliotHandler

logging.getLogger().addHandler(EliotHandler())
logging.getLogger().setLevel(logging.DEBUG)
eliot.to_file(sys.stdout)
logging.captureWarnings(True)

logg = logging.getLogger(__name__)

logging.getLogger("parso").setLevel(logging.WARN)

logg.info("init")
Exemple #7
0
from eliot.stdlib import EliotHandler
from eliot import start_action, to_file

# A Logger left over from before switch to Eliot
LEGACY_LOGGER = logging.Logger("hello_eliot_package")


def do_a_thing(i):
    with start_action(action_type="hello_eliot_package:do_a_thing"):
        # run your business logic....
        if i == 3:
            LEGACY_LOGGER.error("The number 3 is a bad number, don't use it.")
            raise ValueError("I hate the number 3")


def main():
    with start_action(action_type="hello_eliot_package:main"):
        for i in [1, 3]:
            try:
                do_a_thing(i)
            except ValueError:
                LEGACY_LOGGER.info("Number {} was rejected.".format(i))


if __name__ == '__main__':
    # Hook up stdlib logging to Eliot:
    LEGACY_LOGGER.addHandler(EliotHandler())
    # Write Eliot logs to stdout:
    to_file(sys.stdout)
    # Run the code:
    main()
from datetime import datetime, timezone
from typing import List, Optional, Set
import keycloak

import typer
from eliot import start_action, start_task, to_file, register_exception_extractor, log_message
from eliot.stdlib import EliotHandler

import settings
from common import create_keycloak_admin_client

URL_ADMIN_USER_LOGOUT = "admin/realms/{realm-name}/users/{id}/logout"

root_logger = logging.getLogger()
root_logger.setLevel(logging.DEBUG)
root_logger.addHandler(EliotHandler())
to_file(sys.stdout)
logging.captureWarnings(True)


# XXX: use Pydantic for validation
@dataclass
class UserUpdate:
    email: str
    sync_id: str
    verified: Optional[bool] = None
    eligible: Optional[bool] = None
    department: Optional[str] = None


def prepare_user_updates(csv_filepath: str) -> List[UserUpdate]: