|
5 | 5 | import json |
6 | 6 | import logging |
7 | 7 | import mimetypes |
8 | | -import platform |
9 | 8 | import re |
10 | 9 | import uuid |
11 | 10 | from datetime import datetime, timezone |
|
34 | 33 | from .staged_insert import staged_insert1 as _staged_insert1 |
35 | 34 | from .storage import StorageBackend, build_object_path, verify_or_create_store_metadata |
36 | 35 | from .utils import get_master, is_camel_case, user_choice |
37 | | -from .version import __version__ as version |
38 | 36 |
|
39 | 37 | logger = logging.getLogger(__name__.split(".")[0]) |
40 | 38 |
|
@@ -73,7 +71,6 @@ class Table(QueryExpression): |
73 | 71 | """ |
74 | 72 |
|
75 | 73 | _table_name = None # must be defined in subclass |
76 | | - _log_ = None # placeholder for the Log table object |
77 | 74 |
|
78 | 75 | # These properties must be set by the schema decorator (schemas.py) at class level |
79 | 76 | # or by FreeTable at instance level |
@@ -118,7 +115,7 @@ def declare(self, context=None): |
118 | 115 | # skip if no create privilege |
119 | 116 | pass |
120 | 117 | else: |
121 | | - self._log("Declared " + self.full_table_name) |
| 118 | + logger.info("Declared %s", self.full_table_name) |
122 | 119 | # Populate lineage entries for semantic matching |
123 | 120 | self._populate_lineage() |
124 | 121 |
|
@@ -153,7 +150,7 @@ def alter(self, prompt=True, context=None): |
153 | 150 | self.__class__._heading = Heading(table_info=self.heading.table_info) |
154 | 151 | if prompt: |
155 | 152 | logger.info("Table altered") |
156 | | - self._log("Altered " + self.full_table_name) |
| 153 | + logger.info("Altered %s", self.full_table_name) |
157 | 154 |
|
158 | 155 | def _populate_lineage(self): |
159 | 156 | """ |
@@ -293,16 +290,6 @@ def full_table_name(self): |
293 | 290 | """ |
294 | 291 | return r"`{0:s}`.`{1:s}`".format(self.database, self.table_name) |
295 | 292 |
|
296 | | - @property |
297 | | - def _log(self): |
298 | | - if self._log_ is None: |
299 | | - self._log_ = Log( |
300 | | - self.connection, |
301 | | - database=self.database, |
302 | | - skip_logging=self.table_name.startswith("~"), |
303 | | - ) |
304 | | - return self._log_ |
305 | | - |
306 | 293 | @property |
307 | 294 | def external(self): |
308 | 295 | return self.connection.schemas[self.database].external |
@@ -609,7 +596,7 @@ def delete_quick(self, get_count=False): |
609 | 596 | query = "DELETE FROM " + self.full_table_name + self.where_clause() |
610 | 597 | self.connection.query(query) |
611 | 598 | count = self.connection.query("SELECT ROW_COUNT()").fetchone()[0] if get_count else None |
612 | | - self._log(query[:255]) |
| 599 | + logger.debug("Deleted from %s", self.full_table_name) |
613 | 600 | return count |
614 | 601 |
|
615 | 602 | def delete( |
@@ -787,10 +774,9 @@ def drop_quick(self): |
787 | 774 | self.connection.query(query) |
788 | 775 | # Clean up lineage entries |
789 | 776 | delete_lineage_entries(self.connection, self.database, self.table_name) |
790 | | - logger.info("Dropped table %s" % self.full_table_name) |
791 | | - self._log(query[:255]) |
| 777 | + logger.info("Dropped table %s", self.full_table_name) |
792 | 778 | else: |
793 | | - logger.info("Nothing to drop: table %s is not declared" % self.full_table_name) |
| 779 | + logger.info("Nothing to drop: table %s is not declared", self.full_table_name) |
794 | 780 |
|
795 | 781 | def drop(self): |
796 | 782 | """ |
@@ -1097,76 +1083,3 @@ def __init__(self, conn, full_table_name): |
1097 | 1083 |
|
1098 | 1084 | def __repr__(self): |
1099 | 1085 | return "FreeTable(`%s`.`%s`)\n" % (self.database, self._table_name) + super().__repr__() |
1100 | | - |
1101 | | - |
1102 | | -class Log(Table): |
1103 | | - """ |
1104 | | - The log table for each schema. |
1105 | | - Instances are callable. Calls log the time and identifying information along with the event. |
1106 | | -
|
1107 | | - :param skip_logging: if True, then log entry is skipped by default. See __call__ |
1108 | | - """ |
1109 | | - |
1110 | | - _table_name = "~log" |
1111 | | - |
1112 | | - def __init__(self, conn, database, skip_logging=False): |
1113 | | - self.database = database |
1114 | | - self.skip_logging = skip_logging |
1115 | | - self._connection = conn |
1116 | | - self._heading = Heading(table_info=dict(conn=conn, database=database, table_name=self.table_name, context=None)) |
1117 | | - self._support = [self.full_table_name] |
1118 | | - |
1119 | | - self._definition = """ # event logging table for `{database}` |
1120 | | - id :int unsigned auto_increment # event order id |
1121 | | - --- |
1122 | | - timestamp = CURRENT_TIMESTAMP : timestamp # event timestamp |
1123 | | - version :varchar(12) # datajoint version |
1124 | | - user :varchar(255) # user@host |
1125 | | - host="" :varchar(255) # system hostname |
1126 | | - event="" :varchar(255) # event message |
1127 | | - """.format(database=database) |
1128 | | - |
1129 | | - super().__init__() |
1130 | | - |
1131 | | - if not self.is_declared: |
1132 | | - self.declare() |
1133 | | - self.connection.dependencies.clear() |
1134 | | - self._user = self.connection.get_user() |
1135 | | - |
1136 | | - @property |
1137 | | - def definition(self): |
1138 | | - return self._definition |
1139 | | - |
1140 | | - def __call__(self, event, skip_logging=None): |
1141 | | - """ |
1142 | | -
|
1143 | | - :param event: string to write into the log table |
1144 | | - :param skip_logging: If True then do not log. If None, then use self.skip_logging |
1145 | | - """ |
1146 | | - skip_logging = self.skip_logging if skip_logging is None else skip_logging |
1147 | | - if not skip_logging: |
1148 | | - try: |
1149 | | - self.insert1( |
1150 | | - dict( |
1151 | | - user=self._user, |
1152 | | - version=version + "py", |
1153 | | - host=platform.uname().node, |
1154 | | - event=event, |
1155 | | - ), |
1156 | | - skip_duplicates=True, |
1157 | | - ignore_extra_fields=True, |
1158 | | - ) |
1159 | | - except DataJointError: |
1160 | | - logger.info("could not log event in table ~log") |
1161 | | - |
1162 | | - def delete(self): |
1163 | | - """ |
1164 | | - bypass interactive prompts and cascading dependencies |
1165 | | -
|
1166 | | - :return: number of deleted items |
1167 | | - """ |
1168 | | - return self.delete_quick(get_count=True) |
1169 | | - |
1170 | | - def drop(self): |
1171 | | - """bypass interactive prompts and cascading dependencies""" |
1172 | | - self.drop_quick() |
0 commit comments