claudevdm commented on code in PR #36432: URL: https://github.com/apache/beam/pull/36432#discussion_r2422016170
########## sdks/python/apache_beam/utils/logger.py: ########## @@ -0,0 +1,137 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# + +"""Helper functions for easier logging. + +This module provides a few convenient logging methods, some of which +were adopted from +https://github.com/abseil/abseil-py/blob/master/absl/logging/__init__.py +in +https://github.com/facebookresearch/detectron2/blob/main/detectron2/utils/logger.py +""" +import logging +import os +import sys +import time +from collections import Counter +from types import FrameType +from typing import Optional +from typing import Union + + +def _find_caller() -> tuple[str, tuple]: + """ + Returns: + str: module name of the caller + tuple: a hashable key to be used to identify different callers + """ + frame: Optional[FrameType] = sys._getframe(2) + while frame: + code = frame.f_code + if os.path.join("utils", "logger.") not in code.co_filename: + mod_name = frame.f_globals["__name__"] + if mod_name == "__main__": + mod_name = "apache_beam" + return mod_name, (code.co_filename, frame.f_lineno, code.co_name) + frame = frame.f_back + + # To appease mypy. Code returns earlier in practice. + return "unknown", ("unknown", 0, "unknown") + + +_LOG_COUNTER = Counter() Review Comment: Same with access to _LOG_TIMER -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
