Module: log_filter
Expand source code
# Copyright (C) 2023-present The Project Contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
class LogFilter(logging.Filter):
"""Logging filter adds custom fields to log messages."""
def filter(self, record):
record.custom_field = "custom_field_value"
return True
Classes
class LogFilter (name='')
-
Logging filter adds custom fields to log messages.
Initialize a filter.
Initialize with the name of the logger which, together with its children, will have its events allowed through the filter. If no name is specified, allow every event.
Expand source code
class LogFilter(logging.Filter): """Logging filter adds custom fields to log messages.""" def filter(self, record): record.custom_field = "custom_field_value" return True
Ancestors
- logging.Filter
Methods
def filter(self, record)
-
Determine if the specified record is to be logged.
Returns True if the record should be logged, or False otherwise. If deemed appropriate, the record may be modified in-place.