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

How to remove #pytsql_prints lines from logs #107

Open
jonashaag opened this issue Sep 19, 2023 · 2 comments
Open

How to remove #pytsql_prints lines from logs #107

jonashaag opened this issue Sep 19, 2023 · 2 comments

Comments

@jonashaag
Copy link
Contributor

I wonder if there is something that we can implement in pytsql to optionally disable printing of the #pytsql_prints related lines to the SQLAlchemy logger.

@jonashaag
Copy link
Contributor Author

My current solution

    def log_filter(record):
        msg = record.getMessage()
        return not msg.startswith(
            (
                "DELETE FROM #pytsql_prints",
                "SELECT * FROM #pytsql_prints",
                "CREATE TABLE #pytsql_prints",
                "DROP TABLE IF EXISTS #pytsql_prints",

                # non-pytsql noise
                "COMMIT using DBAPI",
                "[raw sql] ()",
                "SELECT CAST('test max support",
                "SELECT CAST(SERVERPROPERTY('ProductVersion')",
                "SELECT schema_name()",
                "SELECT [INFORMATION_SCHEMA].[TABLES].[TABLE_NAME]",
                "[generated in ",
                "[cached since",
            )
        )

    for handler in logging.getLogger().handlers:
        handler.addFilter(log_filter)

@ivergara
Copy link
Collaborator

This is the point of using a log filter. My only suggestion would be to split it in two one for pytsql and the other for the extra noise you want to filter out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants