Skip to content

Commit

Permalink
revert
Browse files Browse the repository at this point in the history
  • Loading branch information
duyguHsnHsn committed Nov 24, 2023
1 parent b9de33e commit 0dedc3c
Showing 1 changed file with 58 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,51 +94,87 @@ def vdk_configure(self, config_builder: ConfigurationBuilder):
),
)

def configure_logger(self, context, additional_filters=[]):
@hookimpl
def vdk_initialize(self, context: CoreContext):
metadata_keys = context.configuration.get_value(STRUCTLOG_LOGGING_METADATA_KEY)
logging_formatter = context.configuration.get_value(STRUCTLOG_LOGGING_FORMAT_KEY)
custom_format_string = context.configuration.get_value(STRUCTLOG_CONSOLE_LOG_PATTERN)
logging_formatter = context.configuration.get_value(
STRUCTLOG_LOGGING_FORMAT_KEY
)
custom_format_string = context.configuration.get_value(
STRUCTLOG_CONSOLE_LOG_PATTERN
)

formatter, metadata_filter = create_formatter(
logging_formatter, metadata_keys, custom_format_string
)

root_logger = logging.getLogger()
if root_logger.handlers:
root_logger.removeHandler(root_logger.handlers[0])
root_logger.removeHandler(root_logger.handlers[0])

handler = logging.StreamHandler(sys.stderr)
handler.setFormatter(formatter)
handler.addFilter(metadata_filter)

for filter in additional_filters:
handler.addFilter(filter)
handler.setFormatter(formatter)

root_logger.addHandler(handler)

def remove_handler(self):
root_logger = logging.getLogger()
if root_logger.handlers:
root_logger.removeHandler(root_logger.handlers[-1])

@hookimpl
def vdk_initialize(self, context: CoreContext):
self.configure_logger(context)

@hookimpl(hookwrapper=True)
def initialize_job(self, context: JobContext) -> None:
metadata_keys = context.core_context.configuration.get_value(
STRUCTLOG_LOGGING_METADATA_KEY
)
logging_formatter = context.core_context.configuration.get_value(
STRUCTLOG_LOGGING_FORMAT_KEY
)
custom_format_string = context.core_context.configuration.get_value(
STRUCTLOG_CONSOLE_LOG_PATTERN
)

formatter, metadata_filter = create_formatter(
logging_formatter, metadata_keys, custom_format_string
)
job_name_adder = AttributeAdder("vdk_job_name", context.name)
self.configure_logger(context.core_context, [job_name_adder])

root_logger = logging.getLogger()
root_logger.removeHandler(root_logger.handlers[0])

handler = logging.StreamHandler(sys.stderr)
handler.setFormatter(formatter)
handler.addFilter(job_name_adder)
handler.addFilter(metadata_filter)

root_logger.addHandler(handler)

out: HookCallResult
out = yield

self.remove_handler()
root_logger.removeHandler(handler)

@hookimpl(hookwrapper=True)
def run_job(self, context: JobContext) -> Optional[ExecutionResult]:
metadata_keys = context.core_context.configuration.get_value(
STRUCTLOG_LOGGING_METADATA_KEY
)
logging_formatter = context.core_context.configuration.get_value(
STRUCTLOG_LOGGING_FORMAT_KEY
)
custom_format_string = context.core_context.configuration.get_value(
STRUCTLOG_CONSOLE_LOG_PATTERN
)

formatter, metadata_filter = create_formatter(
logging_formatter, metadata_keys, custom_format_string
)
job_name_adder = AttributeAdder("vdk_job_name", context.name)
self.configure_logger(context.core_context, [job_name_adder])

root_logger = logging.getLogger()
root_logger.removeHandler(root_logger.handlers[0])

handler = logging.StreamHandler(sys.stderr)
handler.setFormatter(formatter)
handler.addFilter(job_name_adder)
handler.addFilter(metadata_filter)

root_logger.addHandler(handler)

out: HookCallResult
out = yield
Expand All @@ -162,4 +198,4 @@ def run_step(self, context: JobContext, step: Step) -> Optional[StepResult]:

@hookimpl
def vdk_start(plugin_registry: IPluginRegistry, command_line_args: List):
plugin_registry.load_plugin_with_hooks_impl(StructlogPlugin(), "StructlogPlugin")
plugin_registry.load_plugin_with_hooks_impl(StructlogPlugin(), "StructlogPlugin")

0 comments on commit 0dedc3c

Please sign in to comment.