diff options
author | Roman Vasilets <rvasilets@mirantis.com> | 2014-08-08 15:44:42 +0300 |
---|---|---|
committer | Roman Vasilets <rvasilets@mirantis.com> | 2014-08-26 13:32:17 +0300 |
commit | 41dada16cd1c289a3b99a0ca44e316295dc298b1 (patch) | |
tree | f9dda5b587f80677db535a318e59b53709d257a8 /oslo | |
parent | 76c0676687a7250be958c7e7769a43f135f9d4d0 (diff) | |
download | oslo-db-41dada16cd1c289a3b99a0ca44e316295dc298b1.tar.gz |
Extract logging setup into a separate function
Change-Id: I9f1761a5332ad3c4a8f0b76c6f46fc687fd61aa5
Diffstat (limited to 'oslo')
-rw-r--r-- | oslo/db/sqlalchemy/session.py | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/oslo/db/sqlalchemy/session.py b/oslo/db/sqlalchemy/session.py index ea381e5..5c8688c 100644 --- a/oslo/db/sqlalchemy/session.py +++ b/oslo/db/sqlalchemy/session.py @@ -331,6 +331,25 @@ def _begin_ping_listener(connection): connection.scalar(select([1])) +def _setup_logging(connection_debug=0): + """setup_logging function maps SQL debug level to Python log level. + + Connection_debug is a verbosity of SQL debugging information. + 0=None(default value), + 1=Processed only messages with WARNING level or higher + 50=Processed only messages with INFO level or higher + 100=Processed only messages with DEBUG level + """ + if connection_debug >= 0: + logger = logging.getLogger('sqlalchemy.engine') + if connection_debug >= 100: + logger.setLevel(logging.DEBUG) + elif connection_debug >= 50: + logger.setLevel(logging.INFO) + else: + logger.setLevel(logging.WARNING) + + def create_engine(sql_connection, sqlite_fk=False, mysql_sql_mode=None, idle_timeout=3600, connection_debug=0, max_pool_size=None, max_overflow=None, @@ -346,15 +365,7 @@ def create_engine(sql_connection, sqlite_fk=False, mysql_sql_mode=None, 'convert_unicode': True, } - if connection_debug >= 0: - # Map SQL debug level to Python log level - logger = logging.getLogger('sqlalchemy.engine') - if connection_debug >= 100: - logger.setLevel(logging.DEBUG) - elif connection_debug >= 50: - logger.setLevel(logging.INFO) - else: - logger.setLevel(logging.WARNING) + _setup_logging(connection_debug) _init_connection_args( url, engine_args, |