Skip to content

Commit fd2bf7f

Browse files
committed
Merged PR 6457: SYNC: GH to ADO Main
#### AI description (iteration 1) #### PR Classification This pull request is a code migration and cleanup effort that overhauls the logging framework across the repository. #### PR Summary The changes replace the legacy logging system (including the removed `logging_config.py`) with a new, unified logging module and logger bridge for both Python and C++ code, improving performance, consistency, and coverage reporting. - **`mssql_python/logging.py`**: Introduces a new logger module that defines logger APIs (debug/info/warning/error) and deprecates the old logging configuration. - **`mssql_python/pybind/logger_bridge.cpp` and `.hpp`**: Add a new logger bridge to efficiently propagate C++ log messages to the Python logging system. - **Core modules (e.g., connection, auth, pooling, cursor) and test files (e.g., tests for logging, performance, and integration)** have been updated to use the new logging API. - Several obsolete files, including `logging_config.py`, `.config/SDL_CONFIGURATION.md`, and `unix_buffers.h`, were removed to clean up the codebase. <!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot --> Related work items: #40479
1 parent 5499a65 commit fd2bf7f

38 files changed

+5080
-1583
lines changed

.config/SDL_CONFIGURATION.md

Lines changed: 0 additions & 210 deletions
This file was deleted.

.coveragerc

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,27 @@ omit =
66
tests/*
77

88
[report]
9-
# Add any report-specific settings here, if needed
9+
# Exclude lines that don't need coverage (logging, defensive code, etc.)
10+
exclude_lines =
11+
# Default pragmas
12+
pragma: no cover
13+
14+
# Don't complain about missing debug-only code
15+
def __repr__
16+
17+
# Don't complain if tests don't hit defensive assertion code
18+
raise AssertionError
19+
raise NotImplementedError
20+
21+
# Don't complain if non-runnable code isn't run
22+
if __name__ == .__main__.:
23+
24+
# Exclude all logging statements (zero overhead when disabled by design)
25+
logger\.debug
26+
logger\.info
27+
logger\.warning
28+
logger\.error
29+
LOG\(
30+
31+
# Don't complain about abstract methods
32+
@abstract

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,6 @@ build/
6060
# Virtual environments
6161
*venv*/
6262
**/*venv*/
63+
64+
# learning files
65+
learnings/

benchmarks/perf-benchmarking.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@
3535

3636
# Ensure pyodbc connection string has ODBC driver specified
3737
if CONN_STR and 'Driver=' not in CONN_STR:
38-
CONN_STR = f"Driver={{ODBC Driver 18 for SQL Server}};{CONN_STR}"
38+
CONN_STR_PYODBC = f"Driver={{ODBC Driver 18 for SQL Server}};{CONN_STR}"
39+
else:
40+
CONN_STR_PYODBC = CONN_STR
3941

40-
NUM_ITERATIONS = 5 # Number of times to run each test for averaging
42+
NUM_ITERATIONS = 10 # Number of times to run each test for averaging
4143

4244
# SQL Queries
4345
COMPLEX_JOIN_AGGREGATION = """
@@ -187,7 +189,7 @@ def run_benchmark_pyodbc(query: str, name: str, iterations: int) -> BenchmarkRes
187189
for i in range(iterations):
188190
try:
189191
start_time = time.time()
190-
conn = pyodbc.connect(CONN_STR)
192+
conn = pyodbc.connect(CONN_STR_PYODBC)
191193
cursor = conn.cursor()
192194
cursor.execute(query)
193195
rows = cursor.fetchall()

generate_codecov.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,17 @@ llvm-cov export "$PYBIND_SO" \
8181
--skip-functions \
8282
-format=lcov > cpp-coverage.info
8383

84+
# Note: LCOV exclusion markers (LCOV_EXCL_LINE) should be added to source code
85+
# to exclude LOG() statements from coverage. However, for automated exclusion
86+
# of all LOG lines without modifying source code, we can use geninfo's --omit-lines
87+
# feature during the merge step (see below).
88+
8489
echo "==================================="
8590
echo "[STEP 4] Merging Python + C++ coverage"
8691
echo "==================================="
8792

8893
# Merge LCOV reports (ignore inconsistencies in Python LCOV export)
94+
echo "[ACTION] Merging Python and C++ coverage"
8995
lcov -a python-coverage.info -a cpp-coverage.info -o total.info \
9096
--ignore-errors inconsistent,corrupt
9197

main.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
from mssql_python import connect
2-
from mssql_python import setup_logging
2+
from mssql_python.logging import setup_logging
33
import os
4-
import decimal
54

6-
setup_logging('stdout')
5+
# Clean one-liner: set level and output mode together
6+
setup_logging(output="both")
77

88
conn_str = os.getenv("DB_CONNECTION_STRING")
99
conn = connect(conn_str)
10-
11-
# conn.autocommit = True
12-
1310
cursor = conn.cursor()
1411
cursor.execute("SELECT database_id, name from sys.databases;")
1512
rows = cursor.fetchall()

mssql_python/__init__.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
# Cursor Objects
5555
from .cursor import Cursor
5656

57-
# Logging Configuration
58-
from .logging_config import setup_logging, get_logger
57+
# Logging Configuration (Simplified single-level DEBUG system)
58+
from .logging import logger, setup_logging, driver_logger
5959

6060
# Constants
6161
from .constants import ConstantsDDBC, GetInfoConstants
@@ -182,6 +182,19 @@ def pooling(max_size: int = 100, idle_timeout: int = 600, enabled: bool = True)
182182

183183
_original_module_setattr = sys.modules[__name__].__setattr__
184184

185+
def _custom_setattr(name, value):
186+
if name == 'lowercase':
187+
with _settings_lock:
188+
_settings.lowercase = bool(value)
189+
# Update the module's lowercase variable
190+
_original_module_setattr(name, _settings.lowercase)
191+
else:
192+
_original_module_setattr(name, value)
193+
194+
# Replace the module's __setattr__ with our custom version
195+
sys.modules[__name__].__setattr__ = _custom_setattr
196+
197+
185198
# Export SQL constants at module level
186199
SQL_VARCHAR: int = ConstantsDDBC.SQL_VARCHAR.value
187200
SQL_LONGVARCHAR: int = ConstantsDDBC.SQL_LONGVARCHAR.value

0 commit comments

Comments
 (0)