rough-rose-81585
01/10/2022, 3:43 PM@tasks
?
I’m configuring the root logger, but it seems like that code is only running at registration time not execution time? See thread for examplerough-rose-81585
01/10/2022, 3:45 PMfrom msat.logging import configure_logger
logger = configure_logger()
@task
def my_task():
<http://logger.info|logger.info>("an info message")
configure_logger
seems to be called when I run pyflyte, but not when the @task
actually executes. This results in all default log settings like the log level = WARNthankful-minister-83577
thankful-minister-83577
thankful-minister-83577
rough-rose-81585
01/10/2022, 5:05 PMflytekit==0.30.0b2
and configure_logger is a custom function where I i configure the root logger to be a JSON logger using pythonjsonlogger
rough-rose-81585
01/10/2022, 5:06 PMthankful-minister-83577
thankful-minister-83577
thankful-minister-83577
thankful-minister-83577
thankful-minister-83577
rough-rose-81585
01/10/2022, 5:16 PMrough-rose-81585
01/10/2022, 5:35 PMlogger = logging.getLogger("flytekit")
Happened before my code so it configures a default root logger. I just needed to force my configure_logger function to overwrite the default root loggerrough-rose-81585
01/10/2022, 5:35 PMthankful-minister-83577
thankful-minister-83577
rough-rose-81585
01/11/2022, 2:44 PMlogging
package’s info() warning() , etc functions will add a basic root log handler if one doesn’t exist.
For example
import logging
<http://logging.info|logging.info>("hello")
calls
def info(msg, *args, **kwargs):
"""
Log a message with severity 'INFO' on the root logger. If the logger has
no handlers, call basicConfig() to add a console handler with a pre-defined
format.
"""
if len(root.handlers) == 0:
basicConfig()
<http://root.info|root.info>(msg, *args, **kwargs)
thankful-minister-83577
thankful-minister-83577
rich-garden-69988
02/11/2022, 11:51 PMFLYTE_SDK_LOGGING_LEVEL_ROOT=20
would resolve, but still no user logs.
I think it may come down to the statement on this line - if acting on flytekit_root_env_var
should that line be using the root logger (e.g., use logger.root.setLevel
)?
If I set logging.root.setLevel(20)
at the top of my file, I can get logs to work. Without that, logging.root.level
is always set to 30thankful-minister-83577
FLYTE_SDK_LOGGING_LEVEL=20
and run
from flytekit import logger
<http://logger.info|logger.info>("This is info")
thankful-minister-83577
thankful-minister-83577
thankful-minister-83577
rich-garden-69988
02/13/2022, 1:54 AMFLYTE_SDK_LOGGING_LEVEL=20
and importing the logger from flytekit works - is that the recommended way for users to log? I would expect that it would be possible to set up my own logger like so, but this does not work currently:
import logging
from flytekit import task, workflow
logging.basicConfig(
level=<http://logging.INFO|logging.INFO>,
format="%(asctime)s [%(levelname)s] %(message)s",
)
@task
def test_task(value: int) -> int:
<http://logging.info|logging.info>("This is info")
return value
@workflow
def test_workflow(input_integer: int) -> int:
return test_task(value=input_integer)
After debugging, I found that inside the task, the root logger is still set to 30 (the default) - here is the output of logging.root.__dict__
when printed inside the task:
{'filters': [], 'name': 'root', 'level': 30, 'parent': None, 'propagate': True, 'handlers': [<StreamHandler <stderr> (NOTSET)>], 'disabled': False, '_cache': {10: False, 20: False}}
rich-garden-69988
02/13/2022, 2:13 AMthankful-minister-83577
thankful-minister-83577
thankful-minister-83577
In [1]: import logging
In [2]: logging.root.__dict__
Out[2]:
{'filters': [],
'name': 'root',
'level': 30,
'parent': None,
'propagate': True,
'handlers': [],
'disabled': False,
'_cache': {}}
In [3]: logging.basicConfig(level=<http://logging.INFO|logging.INFO>)
In [4]: logging.root.__dict__
Out[4]:
{'filters': [],
'name': 'root',
'level': 20,
'parent': None,
'propagate': True,
'handlers': [<StreamHandler <stderr> (NOTSET)>],
'disabled': False,
'_cache': {}}
In [5]: from flytekit import logger
In [6]: logging.root.__dict__
Out[6]:
{'filters': [],
'name': 'root',
'level': 20,
'parent': None,
'propagate': True,
'handlers': [<StreamHandler <stderr> (NOTSET)>],
'disabled': False,
'_cache': {}}
seems to work.thankful-minister-83577
thankful-minister-83577
rich-garden-69988
02/14/2022, 6:27 PMrich-garden-69988
02/14/2022, 6:32 PMthankful-minister-83577
thankful-minister-83577
thankful-minister-83577
thankful-minister-83577
thankful-minister-83577
In [1]: import logging
In [2]: <http://logging.info|logging.info>("fdjs")
In [3]: logging.basicConfig(level=<http://logging.INFO|logging.INFO>)
In [4]: logging.root.__dict__
Out[4]:
{'filters': [],
'name': 'root',
'level': 30,
'parent': None,
'propagate': True,
'handlers': [<StreamHandler <stderr> (NOTSET)>],
'disabled': False,
'_cache': {20: False}}
thankful-minister-83577
if len(root.handlers) == 0:
in itthankful-minister-83577
rich-garden-69988
02/14/2022, 7:29 PMthankful-minister-83577
thankful-minister-83577
force
option to your basicconfigthankful-minister-83577
thankful-minister-83577
thankful-minister-83577
rich-garden-69988
02/14/2022, 7:37 PMforce
is totally fine!