Example #1
0
def populate_default_mdc(request):
    """Populate default MDC fields given the request

    """
    if MDC.get("instanceUUID") is None:
        default_mdc()
        g.request_start = time.process_time()
        g.empty_value = "EMPTY"
        g.request_id = MDC.get("requestID")
    MDC.put('serviceName', request.path)
    MDC.put('IPAddress',
            request.headers.get('X-Forwarded-For', request.remote_addr))
Example #2
0
def mdc_from_json(request_json):
    """Populate MDC fields given a request in json format

    """
    if MDC.get("instanceUUID") is None:
        default_mdc()
    MDC.put('requestID', get_request_id(request_json))
    MDC.put('partnerName', get_partner_name(request_json))
Example #3
0
def default_server_info():
    """Populate server & server_ip_address MDC fields

    """
    # If not set or purposely set = None, then set default
    if MDC.get('server') is None:
        try:
            server = socket.getfqdn()
        except Exception:
            try:
                server = socket.gethostname()
            except Exception:
                server = ''
        MDC.put('server', server)
    if MDC.get('serverIPAddress') is None:
        try:
            server_ip_address = socket.gethostbyname(MDC.get('server'))
        except Exception:
            server_ip_address = ""
        MDC.put('serverIPAddress', server_ip_address)
Example #4
0
def error(self, msg, *args, **kwargs):
    """Wrapper method for log.error is called

    msg: log message
    args: logging args
    kwargs: all the optional args
    """
    if self.isEnabledFor(logging.ERROR):
        if not MDC.get('errorCode'):
            set_error_details(400, 'Internal Error')
        MDC.put('customField2', mdc_mapper())
        self._log(logging.ERROR, no_sep(msg), args, **kwargs)