Repository: PrefectHQ/prefect

Issue:
Prefect logger doesn't use local Python logger timezone configuration
## Opened from the [Prefect Public Slack Community](https://join.slack.com/t/prefect-public/shared_invite/enQtNzE5OTU3OTQwNzc1LTQ5M2FkZmQzZjI0ODg1ZTBmOTc0ZjVjYWFjMWExZDAyYzBmYjVmMTE1NTQ1Y2IxZTllOTc4MmI3NzYxMDlhYWU)

**dcshah88**: Hello Everyone, 

Have started looking into prefect core library recently and exploring it to use for simple use cases.

One thing I am struggling with right now is to provide a different timezone to prefect instead of default UTC.

By default, prefect is generating UTC timestamps in logs but wanted to change it to my local timezone. 

Could you please help ?

**znicholasbrown**: Hi <@U01CWF05D6Y> - Prefect uses Python's built-in logging module; please look at the <https://docs.python.org/3/library/logging.html|Python logging documentation> for info on how to configure your local Python logger.

**dcshah88**: Thanks <@UN6FTLFAS> : what I am confused about is, if I use python logging without prefect, it prints logs using local timezone by default but when used with prefect it prints timestamps in UTC.

looks like prefect is overriding default python logging behavior.

So was wondering if prefect has any config option to provide which timezone to use while printing logs ?

**znicholasbrown**: Ah, that's a good flag - it looks like we're explicitly defaulting to UTC instead of local in the logger, which is probably unintentional. Let me see if there's a reason for that and if not we can PR it :slightly_smiling_face:

**znicholasbrown**: I think this is something we can open a ticket for <@U01CWF05D6Y> - <https://github.com/PrefectHQ/prefect/blob/master/src/prefect/utilities/logging.py#L220|this line> is where the timezone is set in the logger; I'll use <@ULVA73B9P> to open the ticket from this thread :slightly_smiling_face:

**znicholasbrown**: <@ULVA73B9P> open "Prefect logger doesn't use local Python logger timezone configuration"

Original thread can be found [here](https://prefect-community.slack.com/archives/CL09KU1K7/p1603234095357600?thread_ts=1603234095.357600&cid=CL09KU1K7).




Discussion:
@cicdw @joshmeek is there a reason we were doing this? Easy inspection of logs across distributed machines? Should we restore the default python behavior or allow timezone in the config?
Good question, looks like the line linked in the issue above was added 2 years ago and I don't see why it needs to be hardcoded. I vote we should default to the standard logging timezone and allow for overriding it with a config var
Hi there! I've been taking a look at this issue and the relevant code, and I'd like to pick it up as a first-time contributor.

My understanding of this feature request is that the user should be able to set their preferred logging timezone, but that UTC remains a sensible default over local time. Perhaps the difference is moot because most servers, especially in a cloud environment, will be set to UTC?

Whether UTC or local time is preferred for log formatting, I would propose adding a UTC offset to the default `datefmt` configuration value, for the sake of clarity. What do you think?
@speedyturkey Yeah go for it! That actually seems like a clean solution to me without the need for an extra variable 🙂 

Resolving patch:
diff --git a/src/prefect/utilities/logging.py b/src/prefect/utilities/logging.py
--- a/src/prefect/utilities/logging.py
+++ b/src/prefect/utilities/logging.py
@@ -217,7 +217,6 @@ def _create_logger(name: str) -> logging.Logger:
     formatter = logging.Formatter(
         context.config.logging.format, context.config.logging.datefmt
     )
-    formatter.converter = time.gmtime  # type: ignore
     handler.setFormatter(formatter)
     logger.addHandler(handler)
     logger.setLevel(context.config.logging.level)


Test patch: