Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed root logger #871

Merged
merged 9 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions flytekit/bin/entrypoint.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import contextlib
import datetime as _datetime
import logging as python_logging
import os as _os
import pathlib
import traceback as _traceback
Expand Down Expand Up @@ -31,6 +30,7 @@
from flytekit.exceptions import scopes as _scoped_exceptions
from flytekit.exceptions import scopes as _scopes
from flytekit.interfaces.stats.taggable import get_stats as _get_stats
from flytekit.loggers import entrypoint_logger
from flytekit.loggers import entrypoint_logger as logger
from flytekit.models import dynamic_job as _dynamic_job
from flytekit.models import literals as _literal_models
Expand Down Expand Up @@ -209,7 +209,7 @@ def setup_execution(
"api_version": _api_version,
},
),
logging=python_logging,
logging=entrypoint_logger,
tmp_dir=user_workspace_dir,
raw_output_prefix=ctx.file_access._raw_output_prefix,
checkpoint=checkpointer,
Expand Down
3 changes: 1 addition & 2 deletions flytekit/clients/raw.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import base64 as _base64
import logging as _logging
import subprocess
import time
from typing import Optional
Expand Down Expand Up @@ -823,7 +822,7 @@ def get_token(token_endpoint, authorization_header, scope):
body["scope"] = scope
response = _requests.post(token_endpoint, data=body, headers=headers)
if response.status_code != 200:
_logging.error("Non-200 ({}) received from IDP: {}".format(response.status_code, response.text))
cli_logger.error("Non-200 ({}) received from IDP: {}".format(response.status_code, response.text))
raise FlyteAuthenticationException("Non-200 received from IDP")

response = response.json()
Expand Down
4 changes: 2 additions & 2 deletions flytekit/clis/sdk_in_container/pyflyte.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging as _logging
import os as _os
from pathlib import Path

Expand All @@ -16,6 +15,7 @@
from flytekit.configuration.internal import CONFIGURATION_PATH
from flytekit.configuration.platform import URL as _URL
from flytekit.configuration.sdk import WORKFLOW_PACKAGES as _WORKFLOW_PACKAGES
from flytekit.loggers import cli_logger


def validate_package(ctx, param, values):
Expand Down Expand Up @@ -61,7 +61,7 @@ def main(ctx, config=None, pkgs=None, insecure=None):
# Update the logger if it's set
log_level = _internal_config.LOGGING_LEVEL.get() or _sdk_config.LOGGING_LEVEL.get()
if log_level is not None:
_logging.getLogger().setLevel(log_level)
cli_logger.getLogger().setLevel(log_level)

ctx.obj = dict()

Expand Down
7 changes: 4 additions & 3 deletions flytekit/clis/sdk_in_container/serialize.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import logging as _logging
import logging
import math as _math
import os as _os
import sys
Expand All @@ -21,6 +21,7 @@
from flytekit.core.workflow import WorkflowBase
from flytekit.exceptions.scopes import system_entry_point
from flytekit.exceptions.user import FlyteValidationException
from flytekit.loggers import cli_logger
from flytekit.models import launch_plan as _launch_plan_models
from flytekit.models import task as task_models
from flytekit.models.admin import workflow as admin_workflow_models
Expand Down Expand Up @@ -294,7 +295,7 @@ def serialize(ctx, image, local_source_root, in_container_config_path, in_contai
@click.option("-f", "--folder", type=click.Path(exists=True))
@click.pass_context
def workflows(ctx, folder=None):
_logging.getLogger().setLevel(_logging.DEBUG)
cli_logger.getLogger().setLevel(logging.DEBUG)

if folder:
click.echo(f"Writing output to {folder}")
Expand Down Expand Up @@ -322,7 +323,7 @@ def fast(ctx):
@click.option("-f", "--folder", type=click.Path(exists=True))
@click.pass_context
def fast_workflows(ctx, folder=None):
_logging.getLogger().setLevel(_logging.DEBUG)
cli_logger.getLogger().setLevel(logging.DEBUG)

if folder:
click.echo(f"Writing output to {folder}")
Expand Down
7 changes: 4 additions & 3 deletions flytekit/configuration/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import logging as _logging
import os as _os
import pathlib as _pathlib

from flytekit.loggers import logger


def set_flyte_config_file(config_file_path):
"""
Expand All @@ -14,12 +15,12 @@ def set_flyte_config_file(config_file_path):
original_config_file_path = config_file_path
config_file_path = _os.path.abspath(config_file_path)
if not _pathlib.Path(config_file_path).is_file():
_logging.warning(
logger.warning(
f"No config file provided or invalid flyte config_file_path {original_config_file_path} specified."
)
_os.environ[_internal.CONFIGURATION_PATH.env_var] = config_file_path
elif _internal.CONFIGURATION_PATH.env_var in _os.environ:
_logging.debug("Deleting configuration path {} from env".format(_internal.CONFIGURATION_PATH.env_var))
logger.debug("Deleting configuration path {} from env".format(_internal.CONFIGURATION_PATH.env_var))
del _os.environ[_internal.CONFIGURATION_PATH.env_var]
_common.CONFIGURATION_SINGLETON.reset_config(config_file_path)

Expand Down
2 changes: 1 addition & 1 deletion flytekit/core/base_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ def dispatch_execute(
logger.exception(f"Exception when executing {e}")
raise e

logger.info(f"Task executed successfully in user level, outputs: {native_outputs}")
logger.debug("Task executed successfully in user level")
# Lets run the post_execute method. This may result in a IgnoreOutputs Exception, which is
# bubbled up to be handled at the callee layer.
native_outputs = self.post_execute(new_user_params, native_outputs)
Expand Down
12 changes: 6 additions & 6 deletions flytekit/core/context_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from __future__ import annotations

import datetime as _datetime
import logging
import logging as _logging
import os
import pathlib
Expand All @@ -40,6 +39,7 @@
from flytekit.core.node import Node
from flytekit.interfaces.cli_identifiers import WorkflowExecutionIdentifier
from flytekit.interfaces.stats import taggable
from flytekit.loggers import logger, user_space_logger
from flytekit.models.core import identifier as _identifier

# TODO: resolve circular import from flytekit.core.python_auto_container import TaskResolverMixin
Expand Down Expand Up @@ -157,7 +157,7 @@ class ExecutionParameters(object):
class Builder(object):
stats: taggable.TaggableStats
execution_date: datetime
logging: _logging
logging: _logging.Logger
execution_id: str
attrs: typing.Dict[str, typing.Any]
working_dir: typing.Union[os.PathLike, utils.AutoDeletingTempDir]
Expand Down Expand Up @@ -246,7 +246,7 @@ def stats(self) -> taggable.TaggableStats:
return self._stats

@property
def logging(self) -> _logging:
def logging(self) -> _logging.Logger:
"""
A handle to a useful logging object.
TODO: Usage examples
Expand Down Expand Up @@ -899,7 +899,7 @@ def push_context(ctx: FlyteContext, f: Optional[traceback.FrameSummary] = None)
ctx.set_stackframe(f)
FlyteContextManager._OBJS.append(ctx)
t = "\t"
logging.debug(
logger.debug(
f"{t * ctx.level}[{len(FlyteContextManager._OBJS)}] Pushing context - {'compile' if ctx.compilation_state else 'execute'}, branch[{ctx.in_a_condition}], {ctx.get_origin_stackframe_repr()}"
)
return ctx
Expand All @@ -908,7 +908,7 @@ def push_context(ctx: FlyteContext, f: Optional[traceback.FrameSummary] = None)
def pop_context() -> FlyteContext:
ctx = FlyteContextManager._OBJS.pop()
t = "\t"
logging.debug(
logger.debug(
f"{t * ctx.level}[{len(FlyteContextManager._OBJS) + 1}] Popping context - {'compile' if ctx.compilation_state else 'execute'}, branch[{ctx.in_a_condition}], {ctx.get_origin_stackframe_repr()}"
)
if len(FlyteContextManager._OBJS) == 0:
Expand Down Expand Up @@ -963,7 +963,7 @@ def initialize():
execution_id=str(WorkflowExecutionIdentifier.promote_from_model(default_execution_id)),
execution_date=_datetime.datetime.utcnow(),
stats=mock_stats.MockStats(),
logging=_logging,
logging=user_space_logger,
tmp_dir=user_space_path,
raw_output_prefix=default_context.file_access._raw_output_prefix,
)
Expand Down
5 changes: 2 additions & 3 deletions flytekit/core/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import collections
import copy
import inspect
import logging as _logging
import typing
from collections import OrderedDict
from typing import Any, Dict, Generator, List, Optional, Tuple, Type, TypeVar, Union
Expand Down Expand Up @@ -258,7 +257,7 @@ def _change_unrecognized_type_to_pickle(t: Type[T]) -> Type[T]:
else:
TypeEngine.get_transformer(t)
except ValueError:
_logging.warning(
logger.warning(
f"Unsupported Type {t} found, Flyte will default to use PickleFile as the transport. "
f"Pickle can only be used to send objects between the exact same version of Python, "
f"and we strongly recommend to use python type that flyte support."
Expand All @@ -267,7 +266,7 @@ def _change_unrecognized_type_to_pickle(t: Type[T]) -> Type[T]:
return t


def transform_function_to_interface(fn: Callable, docstring: Optional[Docstring] = None) -> Interface:
def transform_function_to_interface(fn: typing.Callable, docstring: Optional[Docstring] = None) -> Interface:
"""
From the annotations on a task function that the user should have provided, and the output names they want to use
for each output parameter, construct the TypedInterface object
Expand Down
5 changes: 3 additions & 2 deletions flytekit/core/mock_stats.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime as _datetime
import logging

from flytekit.loggers import logger


class MockStats(object):
Expand All @@ -25,7 +26,7 @@ def decr(self, metric, count=1, tags=None, **kwargs):
self._records_tags[full_name] = tags or {}

def timing(self, metric):
logging.warning("mock timing isn't implemented yet.")
logger.warning("mock timing isn't implemented yet.")

def timer(self, metric, tags=None, **kwargs):
return _Timer(self, metric, tags=tags or {})
Expand Down
2 changes: 1 addition & 1 deletion flytekit/core/reference_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def unwrap_literal_map_and_execute(
except Exception as e:
logger.exception(f"Exception when executing {e}")
raise e
logger.info(f"Task executed successfully in user level, outputs: {native_outputs}")
logger.debug("Task executed successfully in user level")

expected_output_names = list(self.python_interface.outputs.keys())
if len(expected_output_names) == 1:
Expand Down
2 changes: 1 addition & 1 deletion flytekit/core/shim_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def dispatch_execute(
logger.exception(f"Exception when executing {e}")
raise e

logger.info(f"Task executed successfully in user level, outputs: {native_outputs}")
logger.debug("Task executed successfully in user level")
# Lets run the post_execute method. This may result in a IgnoreOutputs Exception, which is
# bubbled up to be handled at the callee layer.
native_outputs = self.post_execute(new_user_params, native_outputs)
Expand Down
10 changes: 5 additions & 5 deletions flytekit/core/tracker.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import importlib as _importlib
import inspect
import inspect as _inspect
import logging as _logging
from typing import Callable

from flytekit.exceptions import system as _system_exceptions
from flytekit.loggers import logger


class InstanceTrackingMeta(type):
Expand Down Expand Up @@ -70,12 +70,12 @@ def find_lhs(self) -> str:
if self._instantiated_in is None or self._instantiated_in == "":
raise _system_exceptions.FlyteSystemException(f"Object {self} does not have an _instantiated in")

_logging.debug(f"Looking for LHS for {self} from {self._instantiated_in}")
logger.debug(f"Looking for LHS for {self} from {self._instantiated_in}")
m = _importlib.import_module(self._instantiated_in)
for k in dir(m):
try:
if getattr(m, k) is self:
_logging.debug(f"Found LHS for {self}, {k}")
logger.debug(f"Found LHS for {self}, {k}")
self._lhs = k
return k
except ValueError as err:
Expand All @@ -84,10 +84,10 @@ def find_lhs(self) -> str:
# a.any() or a.all()
# Since dataframes aren't registrable entities to begin with we swallow any errors they raise and
# continue looping through m.
_logging.warning("Caught ValueError {} while attempting to auto-assign name".format(err))
logger.warning("Caught ValueError {} while attempting to auto-assign name".format(err))
pass

_logging.error(f"Could not find LHS for {self} in {self._instantiated_in}")
logger.error(f"Could not find LHS for {self} in {self._instantiated_in}")
raise _system_exceptions.FlyteSystemException(f"Error looking for LHS in {self._instantiated_in}")


Expand Down
6 changes: 3 additions & 3 deletions flytekit/core/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging as _logging
import os as _os
import shutil as _shutil
import tempfile as _tempfile
Expand All @@ -8,6 +7,7 @@
from typing import Dict, List, Optional

from flytekit.configuration import resources as _resource_config
from flytekit.loggers import logger
from flytekit.models import task as _task_models


Expand Down Expand Up @@ -220,14 +220,14 @@ def __init__(self, context_statement):
self._start_process_time = None

def __enter__(self):
_logging.info("Entering timed context: {}".format(self._context_statement))
logger.info("Entering timed context: {}".format(self._context_statement))
self._start_wall_time = _time.perf_counter()
self._start_process_time = _time.process_time()

def __exit__(self, exc_type, exc_val, exc_tb):
end_wall_time = _time.perf_counter()
end_process_time = _time.process_time()
_logging.info(
logger.info(
"Exiting timed context: {} [Wall Time: {}s, Process Time: {}s]".format(
self._context_statement,
end_wall_time - self._start_wall_time,
Expand Down
6 changes: 3 additions & 3 deletions flytekit/extras/tasks/shell.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import datetime
import logging
import os
import string
import subprocess
Expand All @@ -11,6 +10,7 @@
from flytekit.core.interface import Interface
from flytekit.core.python_function_task import PythonInstanceTask
from flytekit.core.task import TaskPlugins
from flytekit.loggers import logger
from flytekit.types.directory import FlyteDirectory
from flytekit.types.file import FlyteFile

Expand Down Expand Up @@ -191,7 +191,7 @@ def execute(self, **kwargs) -> typing.Any:
"""
Executes the given script by substituting the inputs and outputs and extracts the outputs from the filesystem
"""
logging.info(f"Running shell script as type {self.task_type}")
logger.info(f"Running shell script as type {self.task_type}")
if self.script_file:
with open(self.script_file) as f:
self._script = f.read()
Expand All @@ -212,7 +212,7 @@ def execute(self, **kwargs) -> typing.Any:
except subprocess.CalledProcessError as e:
files = os.listdir("./")
fstr = "\n-".join(files)
logging.error(
logger.error(
f"Failed to Execute Script, return-code {e.returncode} \n"
f"StdErr: {e.stderr}\n"
f"StdOut: {e.stdout}\n"
Expand Down
2 changes: 2 additions & 0 deletions flytekit/loggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
"cli": logger.getChild("cli"),
"remote": logger.getChild("remote"),
"entrypoint": logger.getChild("entrypoint"),
"user_space": logger.getChild("user_space"),
}
auth_logger = child_loggers["auth"]
cli_logger = child_loggers["cli"]
remote_logger = child_loggers["remote"]
entrypoint_logger = child_loggers["entrypoint"]
user_space_logger = child_loggers["user_space"]

# create console handler
ch = logging.StreamHandler()
Expand Down
4 changes: 2 additions & 2 deletions flytekit/remote/component_nodes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging as _logging
from typing import Dict

from flytekit.exceptions import system as _system_exceptions
from flytekit.loggers import remote_logger
from flytekit.models import launch_plan as _launch_plan_model
from flytekit.models import task as _task_model
from flytekit.models.core import identifier as id_models
Expand Down Expand Up @@ -41,7 +41,7 @@ def promote_from_model(

if base_model.reference_id in tasks:
task = tasks[base_model.reference_id]
_logging.debug(f"Found existing task template for {task.id}, will not retrieve from Admin")
remote_logger.debug(f"Found existing task template for {task.id}, will not retrieve from Admin")
flyte_task = FlyteTask.promote_from_model(task)
return cls(flyte_task)

Expand Down
Loading