FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Merge pull request #12 from google/akefeli_logging · 7dracoder/python-spanner-orm@10fd35d · GitHub

Commit 10fd35d

Browse files
authored
Merge pull request google#12 from google/akefeli_logging
adding logging
2 parents b327f4d + 90361b4 commit 10fd35d

6 files changed

Lines changed: 26 additions & 1 deletion

File tree

‎spanner_orm/__init__.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,18 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
"""Sets up shorcuts for imports from the library."""
16+
import logging
1617

1718
from spanner_orm import api
1819
from spanner_orm import condition
1920
from spanner_orm import field
2021
from spanner_orm import model
2122
from spanner_orm import relationship
2223

24+
# add NullHandler to root-module logger so that individual modules
25+
# won't have to.
26+
logging.getLogger(__name__).addHandler(logging.NullHandler())
27+
2328
# pylint: disable=invalid-name
2429
SpannerApi = api.SpannerApi
2530

‎spanner_orm/api.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515
"""Class that handles API calls to Spanner."""
1616

1717
import abc
18+
import logging
1819

1920
from spanner_orm import error
2021

2122
from google.cloud import spanner
2223

24+
_logger = logging.getLogger(__name__)
25+
2326

2427
class SpannerReadApi(abc.ABC):
2528
"""Handles sending read requests to Spanner"""
@@ -39,13 +42,17 @@ def run_read_only(cls, method, *args, **kwargs):
3942
@staticmethod
4043
def find(transaction, table_name, columns, keyset):
4144
"""Obtains rows with primary_keys from the given table."""
45+
_logger.debug('Find table=%s columns=%s keys=%s',
46+
table_name, columns, keyset.keys)
4247
stream_results = transaction.read(
4348
table=table_name, columns=columns, keyset=keyset)
4449
return list(stream_results)
4550

4651
@staticmethod
4752
def sql_query(transaction, query, parameters, parameter_types):
4853
"""Runs a read only SQL query."""
54+
_logger.debug('Executing SQL:\n%s\n%s\n%s',
55+
query, parameters, parameter_types)
4956
stream_results = transaction.execute_sql(
5057
query, params=parameters, param_types=parameter_types)
5158
return list(stream_results)
@@ -68,16 +75,22 @@ def run_write(cls, *args, **kwargs):
6875
@staticmethod
6976
def insert(transaction, table_name, columns, values):
7077
"""Add rows to a table."""
78+
_logger.debug('Insert table=%s columns=%s values=%s',
79+
table_name, columns, values)
7180
transaction.insert(table=table_name, columns=columns, values=values)
7281

7382
@staticmethod
7483
def update(transaction, table_name, columns, values):
7584
"""Updates rows of a table."""
85+
_logger.debug('Update table=%s columns=%s values=%s',
86+
table_name, columns, values)
7687
transaction.update(table=table_name, columns=columns, values=values)
7788

7889
@staticmethod
7990
def upsert(transaction, table_name, columns, values):
8091
"""Updates existing rows of a table or adds rows if they don't exist."""
92+
_logger.debug('Upsert table=%s columns=%s values=%s',
93+
table_name, columns, values)
8194
transaction.insert_or_update(
8295
table=table_name, columns=columns, values=values)
8396

‎spanner_orm/tests/admin_test.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15-
15+
import logging
1616
import unittest
1717
from unittest import mock
1818

@@ -86,4 +86,5 @@ def test_metadata(self, columns, index_columns, indexes):
8686

8787

8888
if __name__ == '__main__':
89+
logging.basicConfig()
8990
unittest.main()

‎spanner_orm/tests/api_test.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16+
import logging
1617
import unittest
1718
from unittest import mock
1819

@@ -57,4 +58,5 @@ def mock_connection(self, client):
5758

5859

5960
if __name__ == '__main__':
61+
logging.basicConfig()
6062
unittest.main()

‎spanner_orm/tests/model_test.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# limitations under the License.
1515

1616
import datetime
17+
import logging
1718
import unittest
1819

1920
from spanner_orm import error
@@ -131,4 +132,5 @@ def test_error_on_unretrieved_relation_get(self):
131132

132133

133134
if __name__ == '__main__':
135+
logging.basicConfig()
134136
unittest.main()

‎spanner_orm/tests/query_test.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# limitations under the License.
1515

1616
import datetime
17+
import logging
1718
import unittest
1819
from unittest import mock
1920

@@ -255,4 +256,5 @@ def test_includes_error_on_invalid_subconditions(self):
255256

256257

257258
if __name__ == '__main__':
259+
logging.basicConfig()
258260
unittest.main()

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL