You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by hu...@apache.org on 2021/03/03 16:47:39 UTC

[superset] branch hugh/event-logger-refactor updated: leverage enter and exit magic functions for with statements

This is an automated email from the ASF dual-hosted git repository.

hugh pushed a commit to branch hugh/event-logger-refactor
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/hugh/event-logger-refactor by this push:
     new 9e2f527  leverage enter and exit magic functions for with statements
9e2f527 is described below

commit 9e2f5276ee8e895feeb984c73510fcd4595fdab7
Author: hughhhh <hu...@gmail.com>
AuthorDate: Wed Mar 3 11:46:55 2021 -0500

    leverage enter and exit magic functions for with statements
---
 superset/utils/log.py | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/superset/utils/log.py b/superset/utils/log.py
index 824487e..df1958e 100644
--- a/superset/utils/log.py
+++ b/superset/utils/log.py
@@ -233,6 +233,26 @@ def get_event_logger_from_cfg_value(cfg_value: Any) -> AbstractEventLogger:
 class DBEventLogger(AbstractEventLogger):
     """Event logger that commits logs to Superset DB"""
 
+    def __init__(self):
+        self._args = {
+            "user_id": None,
+            "dashboard_id": None,
+            "duration_ms": None,
+            "slice_id": None,
+            "referrer": None,
+        }
+
+    def __call__(self, **kwargs: Any):
+        self._args.update(kwargs)
+        return self
+
+    def __enter__(self, **kwargs: Any):
+        return None
+
+    def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any):
+        # Log data w/ arguments being passed in
+        self.log(**self._args)
+
     def log(  # pylint: disable=too-many-arguments,too-many-locals
         self,
         user_id: Optional[int],