File tree Expand file tree Collapse file tree 4 files changed +25
-7
lines changed
Expand file tree Collapse file tree 4 files changed +25
-7
lines changed Original file line number Diff line number Diff line change 11from mssql_python import connect
2- from mssql_python import setup_logging
2+ from mssql_python import setup_logging , get_logger
33import os
44import decimal
55
66setup_logging ('stdout' )
77
8+ logger = get_logger ()
9+ if logger :
10+ logger .info ("This should print" )
11+ else :
12+ print ("Logger is None - logging not enabled!" )
13+
814conn_str = os .getenv ("DB_CONNECTION_STRING" )
915conn = connect (conn_str )
1016
Original file line number Diff line number Diff line change 1818from mssql_python .helpers import add_driver_to_connection_str , sanitize_connection_string
1919from mssql_python import ddbc_bindings
2020from mssql_python .pooling import PoolingManager
21- from mssql_python .exceptions import DatabaseError , InterfaceError
21+ from mssql_python .exceptions import InterfaceError
2222
2323logger = get_logger ()
2424
@@ -281,5 +281,7 @@ def __del__(self):
281281 try :
282282 self .close ()
283283 except Exception as e :
284- if logger :
285- logger .error (f"Error during connection cleanup in __del__: { e } " )
284+ raise InterfaceError (
285+ driver_error = str (e ),
286+ ddbc_error = "Error during python connection cleanup"
287+ )
Original file line number Diff line number Diff line change 1717from mssql_python .helpers import check_error
1818from mssql_python .logging_config import get_logger
1919from mssql_python import ddbc_bindings
20+ from mssql_python .exceptions import InterfaceError
2021from .row import Row
2122
2223logger = get_logger ()
@@ -739,5 +740,7 @@ def __del__(self):
739740 try :
740741 self .close ()
741742 except Exception as e :
742- if logger :
743- logger .error (f"Error closing cursor: { e } " )
743+ raise InterfaceError (
744+ driver_error = str (e ),
745+ ddbc_error = "Error during python connection cleanup"
746+ )
Original file line number Diff line number Diff line change @@ -132,6 +132,7 @@ def get_logger(self):
132132 logging.Logger: The logger instance, or None if logging is not enabled.
133133 """
134134 if not self .enabled :
135+ # If logging is not enabled, return None
135136 return None
136137 return self ._logger
137138
@@ -160,4 +161,10 @@ def get_logger():
160161 Returns:
161162 logging.Logger: The logger instance.
162163 """
163- return _manager .get_logger ()
164+ # Always return a logger instance, even if setup hasn't been called yet
165+ # This ensures modules can get a logger reference that will work once setup is called
166+ if _manager ._logger is None :
167+ # Return the logger that will be configured when setup() is called
168+ # This logger won't output anything until handlers are added in setup()
169+ return logging .getLogger ("mssql_python" )
170+ return _manager ._logger
You can’t perform that action at this time.
0 commit comments