Janet Carson
09/10/2024, 10:52 PM# started with : <https://raw.githubusercontent.com/PrefectHQ/prefect/main/src/prefect/logging/logging.yml>
# Prefect logging config file.
#
# Any item in this file can be overridden with an environment variable:
# `PREFECT_LOGGING_[PATH]_[TO]_[KEY]=VALUE`
#
# Templated values can be used to insert values from the Prefect settings at runtime.
version: 1
disable_existing_loggers: False
formatters:
simple:
format: "%(asctime)s.%(msecs)03d | %(message)s"
datefmt: "%H:%M:%S"
standard:
(): prefect.logging.formatters.PrefectFormatter
format: "%(asctime)s.%(msecs)03d | %(levelname)-7s | %(name)s - %(message)s"
flow_run_fmt: "%(asctime)s.%(msecs)03d | %(levelname)-7s | Flow run %(flow_run_name)r - %(message)s"
task_run_fmt: "%(asctime)s.%(msecs)03d | %(levelname)-7s | Task run %(task_run_name)r - %(message)s"
datefmt: "%H:%M:%S"
debug:
format: "%(asctime)s.%(msecs)03d | %(levelname)-7s | %(threadName)-12s | %(name)s - %(message)s"
datefmt: "%H:%M:%S"
json:
class: prefect.logging.formatters.JsonFormatter
format: "default"
# filters:
# Define any custom filters to drops records containing
# sensitive information
# my_filter:
# class: your_module.FilterClass
handlers:
# The handlers we define here will output all logs they receive by default
# but we include the `level` so it can be overridden by environment
console:
level: 0
class: prefect.logging.handlers.PrefectConsoleHandler
formatter: standard
styles:
log.web_url: bright_blue
log.local_url: bright_blue
log.info_level: cyan
log.warning_level: yellow3
log.error_level: red3
log.critical_level: bright_red
log.completed_state: green
log.cancelled_state: yellow3
log.failed_state: red3
log.crashed_state: bright_red
log.flow_run_name: magenta
log.flow_name: bold magenta
api:
level: INFO
class: prefect.logging.handlers.APILogHandler
debug:
level: 0
class: logging.StreamHandler
formatter: debug
logfile:
class: logging.FileHandler
filename: silly.log
mode: w
formatter: standard
loggers:
prefect:
level: "${PREFECT_LOGGING_LEVEL}"
prefect.extra:
level: "${PREFECT_LOGGING_LEVEL}"
handlers: [api]
prefect.flow_runs:
level: NOTSET
handlers: [api]
prefect.task_runs:
level: NOTSET
handlers: [api]
prefect.server:
level: "${PREFECT_LOGGING_SERVER_LEVEL}"
prefect.client:
level: "${PREFECT_LOGGING_LEVEL}"
prefect.infrastructure:
level: "${PREFECT_LOGGING_LEVEL}"
prefect._internal:
level: "${PREFECT_LOGGING_INTERNAL_LEVEL}"
propagate: false
handlers: [debug]
uvicorn:
level: "${PREFECT_LOGGING_SERVER_LEVEL}"
fastapi:
level: "${PREFECT_LOGGING_SERVER_LEVEL}"
silly:
level: DEBUG
handlers: [logfile]
# The root logger: any logger without propagation disabled sends to here as well
root:
# By default, we display warning level logs from any library in the console
# to match Python's default behavior while formatting logs nicely
level: WARNING
handlers: [console]
This is the flow that is trying to write to the log file:
@flow
def flow_main(arg1: str, arg2: str) -> None:
log = get_run_logger()
log.debug("run: This is debug")
<http://log.info|log.info>("run: This is info")
log.warning("run: This is warning")
log.error("run: This is error")
log = logging.getLogger("silly")
log.debug("silly: This is debug")
<http://log.info|log.info>("silly: This is info")
log.warning("silly: This is warning")
log.error("silly: This is error")
return
The log messages show up in the terminal where the deployment is running, but the log file is empty.Marvin
09/10/2024, 10:52 PMThere is a big in this config file - the "silly.log" file is created, but no log messages are written to it.```# started with : https://raw.githubusercontent.com/PrefectHQ/prefect/main/src/prefect/logging/logging.yml # Prefect logging config file. # # Any item in this file can be overridden with an environment variable: #
PREFECT_LOGGING_[PATH]_[TO]_[KEY]=VALUE
#
# Templated values can be used to insert values from the Prefect settings at runtime.
version: 1
disable_existing_loggers: False
formatters:
simple:
format: "%(asctime)s.%(msecs)03d | %(message)s"
datefmt: "%H:%M:%S"
standard:
(): prefect.logging.formatters.PrefectFormatter
format: "%(asctime)s.%(msecs)03d | %(levelname)-7s | %(name)s - %(message)s"
flow_run_fmt: "%(asctime)s.%(msecs)03d | %(levelname)-7s | Flow run %(flow_run_name)r - %(message)s"
task_run_fmt: "%(asctime)s.%(msecs)03d | %(levelname)-7s | Task run %(task_run_name)r - %(message)s"
datefmt: "%H:%M:%S"Janet Carson
09/10/2024, 11:09 PM*** 70,75 ****
--- 70,80 ----
class: logging.StreamHandler
formatter: debug
+ logfile:
+ class: logging.FileHandler
+ filename: silly.log
+ mode: w
+
loggers:
prefect:
level: "${PREFECT_LOGGING_LEVEL}"
***************
*** 106,114 ****
--- 111,125 ----
fastapi:
level: "${PREFECT_LOGGING_SERVER_LEVEL}"
+ silly:
+ level: DEBUG
+ handlers: [logfile]
+ propagate: false
+
# The root logger: any logger without propagation disabled sends to here as well
root:
# By default, we display warning level logs from any library in the console
# to match Python's default behavior while formatting logs nicely
level: WARNING
handlers: [console]
+
My log file is created, but no messages are logged to it. The flow that is trying to write to the log file is:
@flow
def flow_main(arg1: str, arg2: str) -> None:
log = get_run_logger()
log.debug("run: This is debug")
<http://log.info|log.info>("run: This is info")
log.warning("run: This is warning")
log.error("run: This is error")
log = logging.getLogger("silly")
log.debug("silly: This is debug")
<http://log.info|log.info>("silly: This is info")
log.warning("silly: This is warning")
log.error("silly: This is error")
return
Marvin
09/10/2024, 11:09 PMI am trying to add an error log file to my prefect flow. I started with the example at https://raw.githubusercontent.com/PrefectHQ/prefect/main/src/prefect/logging/logging.yml and made these diffs:
** 70,75 ***
--- 70,80 ----
class: logging.StreamHandler
formatter: debug
+ logfile:
+ class: logging.FileHandler
+ filename: silly.log
+ mode: w
+
loggers:
prefect:
level: "${PREFECT_LOGGING_LEVEL}"
*********
** 106,114 ***
--- 111,125 ----
fastapi:
level: "${PREFECT_LOGGING_SERVER_LEVEL}"
+ silly:
+ level: DEBUG
+ handlers: [logfile]
+ propagate: false
+
# The root logger: any logger without propagation disabled sends to here as well
root:
# By default, we display warning level logs from any library in the console
# to match Python's default behavior while formatting logs nicely
level: WARNING
handlers: [console]
+
My log file is created, but no messages are logged to it. The flow that is trying to write to the log file is:
```@flow
def flow_main(arg1: str, arg2: str) -> None:
log = get_run_loggerJanet Carson
09/10/2024, 11:11 PM** 70,75 ***
--- 70,80 ----
class: logging.StreamHandler
formatter: debug
+ logfile:
+ class: logging.FileHandler
+ filename: silly.log
+ mode: w
+
loggers:
prefect:
level: "${PREFECT_LOGGING_LEVEL}"
*********
** 106,114 ***
--- 111,125 ----
fastapi:
level: "${PREFECT_LOGGING_SERVER_LEVEL}"
+ silly:
+ level: DEBUG
+ handlers: [logfile]
+ propagate: false
+
# The root logger: any logger without propagation disabled sends to here as well
root:
# By default, we display warning level logs from any library in the console
# to match Python's default behavior while formatting logs nicely
level: WARNING
handlers: [console]
+
My log file is created, but no messages are logged to it. Why?Marvin
09/10/2024, 11:14 PMsilly
logger to your tasks:
python
logger = logging.getLogger("silly")
logger.debug("message")
Ask if use correct Prefect version, can be big difference.
Check this first, if still no work, tell Grug more details!
Source:
JSON Log Issue
Uvicorn Log IssueJanet Carson
09/10/2024, 11:17 PMMarvin
09/10/2024, 11:17 PMplaintext
PREFECT_LOGGING_EXTRA_LOGGERS=silly,another_logger
Need add silly logging directly in code:
python
import logging
logger = logging.getLogger("silly")
logger.setLevel(logging.DEBUG)
file_handler = logging.FileHandler("silly.log")
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)
logger.propagate = False
logger.debug("Debug message")
Check if your custom loggers output to the correct handler and not logged to UI.
You see docs for more detail:
- Logging Configuration
Good luck! If trouble still, tell Grug.Janet Carson
09/10/2024, 11:18 PMJanet Carson
09/10/2024, 11:18 PMMarvin
09/10/2024, 11:18 PMsilly
setup correct in loggers
and handlers
section.
2. Ensure the logger propagation set to false
.
Example YAML snippet look like:
yaml
version: 1
formatters:
debug:
format: "[%(asctime)s] %(levelname)s - %(name)s | %(message)s"
handlers:
console:
class: logging.StreamHandler
formatter: debug
logfile:
class: logging.FileHandler
filename: silly.log
mode: w
loggers:
silly:
level: DEBUG
handlers: [logfile]
propagate: false
root:
level: WARNING
handlers: [console]
Marvin summarize:
- Make sure logger propagate: false
.
- Configure handler logfile
correctly.
- Ensure no config conflict with PREFECT_LOGGING_EXTRA_LOGGERS
.
If still no work, check again config details or environment variable conflicts.
Reference:
Prefect Logging GuideJanet Carson
09/10/2024, 11:20 PMMarvin
09/10/2024, 11:20 PMyaml
version: 1
formatters:
debug:
format: "[%(asctime)s] %(levelname)s - %(name)s | %(message)s"
handlers:
console:
class: logging.StreamHandler
formatter: debug
logfile:
class: logging.FileHandler
filename: silly.log
mode: w
loggers:
prefect:
level: "${PREFECT_LOGGING_LEVEL}"
handlers: [console]
propagate: true
prefect_server:
level: "${PREFECT_LOGGING_SERVER_LEVEL}"
handlers: [console]
propagate: true
fastapi:
level: "${PREFECT_LOGGING_SERVER_LEVEL}"
handlers: [console]
propagate: true
silly:
level: DEBUG
handlers: [logfile]
propagate: false
root:
level: WARNING
handlers: [console]
Keep existing Prefect loggers, just add your custom one. This way, everything should continue to work, but also log to silly.log
.
Marvin say: careful, small steps better than break big thing.
Reference:
Prefect Logging Configuration Guide
Good luck! If still trouble, tell Marvin.Janet Carson
09/10/2024, 11:22 PMMarvin
09/10/2024, 11:22 PMsilly
log level set correctly to DEBUG
. Confirm if PREFECT_LOGGING_EXTRA_LOGGERS
environmental variable is affecting it.
2. Propagation: Double-check propagate
set to false
for silly
logger.
3. Conflict: Environmental variable or config overriding YAML settings.
Check these! Important pieces from Prefect 3 logging info:
1. Setting Log Level:
plain
export PREFECT_LOGGING_LOGGERS_SILLY_LEVEL="DEBUG"
2. Setting Custom YAML:
Prefect doc say to make custom logging.yml
file at PREFECT_HOME
usually ~/.prefect
. Confirm you use correct location.
3. Logging Docs Detail:
Prefect 3 Logging
Example YAML refreshed:
yaml
version: 1
formatters:
debug:
format: "[%(asctime)s] %(levelname)s - %(name)s | %(message)s"
handlers:
console:
class: logging.StreamHandler
formatter: debug
logfile:
class: logging.FileHandler
formatter: debug
filename: silly.log
mode: w
loggers:
silly:
level: DEBUG
handlers: [logfile]
propagate: false
root:
level: WARNING
handlers: [console]
Check log level consistency, propagation, and potential config/env conflicts.
Hope this help Marvin understand good doc. If trouble still persist, tell Marvin.