Skip to content

Add simple debug logging to PythonUDF - #1119

Merged
Yicong-Huang merged 36 commits into
masterfrom
yicong-python-udf-simple-logging
May 13, 2021
Merged

Yicong-Huang merged 36 commits into
masterfrom
yicong-python-udf-simple-logging

Conversation

@Yicong-Huang

@Yicong-Huang Yicong-Huang commented May 11, 2021 •

Copy link
Copy Markdown
Contributor

This PR adds debug logging to PythonUDF. It is currently a simple implementation.

  • The root logger is configured to have a StreamHandler and a FileHandler. The StreamHandler outputs to stderr and inherited by Java process (worker). The FileHander outputs to a log file.
  • Python log configurations can be configured in conf/web.conf. By default,
    • fileHandler log to files in /tmp/ directory, and the log level is set to be INFO.
    • streamHandler log to stdout/stderr, and the log level is set to be ERROR.
  • A log file will be created for each Python process. When python is running in parallel mode, there will be multiple log files spawned. The file name is texera-python_udf-{time}-{pid}.log format.
  • Add log_exception decorator to log out all exceptions during defined PythonUDF operator APIs, such as open, accept, close, etc.
  • Logger will now output class name, method name, and line number.
  • Extracted operator base classes to make library dependency isolated.

Created from JetBrains using CodeStream

@Yicong-Huang Yicong-Huang self-assigned this May 11, 2021
@Yicong-Huang Yicong-Huang changed the title Add simple logging to PythonUDF Add simple debug logging to PythonUDF May 11, 2021
class DemoOperator(texera_udf_operator_base.TexeraUDFOperator):
logger = logging.getLogger("PythonUDF.DemoOperator")

def __init__(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why arent we putting the decorator on init?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added.

class SVMClassifier(texera_udf_operator_base.TexeraMapOperator):
logger = logging.getLogger("PythonUDF.SVMClassifier")

def __init__(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added.

# create a file handler

log_dir = args[0]
file_name = f"{datetime.utcnow().isoformat()}-{os.getpid()}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please change

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to texera-python_udf-{time}-{pid}.log

Comment thread core/conf/web.conf Outdated
# python3 log diretory
"dir": "/tmp/",
# python3 log level
"level": "ERROR"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets change this to INFO or whatever is the least. by default lets log everything

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed.

@avinash0161 avinash0161 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left some comments

@Yicong-Huang

Yicong-Huang commented May 11, 2021 •

Copy link
Copy Markdown
Contributor Author

@avinash0161 I added some more changes:

  1. logger will now output class name, method name, and line number.
  2. extracted operator base classes to make library dependency isolated.

Please give another round of review.

Also it is possible and doable to redirect python's print to log files: simply overwrites sys.stdout to logger.info. However I think this is pretty hacky way to do so. PyFlink recommended users to use log.info instead of print, so I suggest we keep it this way.

@Yicong-Huang
Yicong-Huang requested a review from avinash0161 May 11, 2021 09:21

@Xiao-zhen-Liu Xiao-zhen-Liu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine to me.

@Yicong-Huang
Yicong-Huang merged commit 1bd3360 into master May 13, 2021
@Yicong-Huang
Yicong-Huang deleted the yicong-python-udf-simple-logging branch May 13, 2021 17:46
yangzhang75 pushed a commit to yangzhang75/texera that referenced this pull request Jun 22, 2026
This PR adds debug logging to PythonUDF. It is currently a simple implementation.

- The root logger is configured to have a StreamHandler and a FileHandler. The StreamHandler outputs to stderr and inherited by Java process (worker). The FileHander outputs to a log file.
- Python log configurations can be configured in `conf/web.conf`. By default, 
    - fileHandler log to files in `/tmp/` directory, and the log level is set to be `INFO`.
    - streamHandler log to stdout/stderr, and the log level is set to be `ERROR`.
- A log file will be created for each Python process. When python is running in parallel mode, there will be multiple log files spawned. The file name is `texera-python_udf-{time}-{pid}.log` format.
- Add `log_exception` decorator to log out all exceptions during defined PythonUDF operator APIs, such as `open`, `accept`, `close`, etc.
- Logger will now output class name, method name, and line number.
- Extracted operator base classes to make library dependency isolated.

<sup> Created from JetBrains using [CodeStream](https://codestream.com/?utm_source=cs&utm_medium=pr&utm_campaign=github*com)</sup>
aglinxinyuan added a commit to aglinxinyuan/texera that referenced this pull request Oct 24, 2026
)

### What changes were proposed in this PR?

Removes the UDF Python log settings that nothing reads. **−30 lines.**
There is no behaviour change.

- `udf.conf`: the `python.log.fileHandler` section (`dir`, `level`,
`format` and their `UDF_PYTHON_LOG_FILEHANDLER_*` overrides) and
`python.log.streamHandler.format` (with
`UDF_PYTHON_LOG_STREAMHANDLER_FORMAT`).
- `UdfConfig`: `pythonLogStreamHandlerFormat`,
`pythonLogFileHandlerDir`, `pythonLogFileHandlerLevel`,
`pythonLogFileHandlerFormat`. The vals and the keys go together, because
the vals' eager `getString` would throw once a key is gone.
- `UdfConfigSpec`: the assertions for the removed settings.

`python.log.streamHandler.level` stays. `PythonWorkflowWorker` forwards
it as `loggerLevel`, and CI sets `UDF_PYTHON_LOG_STREAMHANDLER_LEVEL`.

### History

| | |
| --- | --- |
| **Introduced by** | apache#1119 (2021-05-13), "Add simple debug logging to
PythonUDF": the conf keys. apache#3466 (2025-06-12), "Move all conf files and
readers to `core/config`": the `UdfConfig` vals |
| **Usage removed by** | apache#1958 (2023-06-04), "Remove the deprecated
Python UDF V1". It deleted the Java launcher that read these keys and
attached the file handler. The `UdfConfig` vals were **never used** |

The keys have been dead for over three years. The worker installs one
stderr sink at the forwarded level and has never received a format or a
file-handler setting since apache#1958.

### Any related issues, documentation, discussions?

Closes apache#8741

### How was this PR tested?

No new tests. `UdfConfigSpec` keeps its cases for the surviving
settings.

Locally, from the repo root with Java 17:

- `sbt "Config/Test/compile" "WorkflowExecutionService/Test/compile"`:
success.
- `sbt "Config/testOnly *UdfConfigSpec *PythonUtilsSpec"`: 4 tests, all
pass.
- `sbt "Config/scalafmtCheckAll" "Config/scalafixAll --check"
"WorkflowExecutionService/scalafmtCheckAll"
"WorkflowExecutionService/scalafixAll --check"`: clean.

To re-check:

```
git grep -n -E "fileHandler|LOG_FILEHANDLER|STREAMHANDLER_FORMAT|pythonLogStreamHandlerFormat"   # no hits
```

### Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Claude Opus 5.5)

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants