[log] New, make action log configurable and generic (#7705)

* [log] New, make action log configurable and generic

* [log] Fix, missing apache license

* [log] Fix, user_id is a required parameter on event logs

* [log] Fix, Rename Action to Event

* [log] Fix, flake8

* [logger] Change all log_this decorators to new abstract one

* [logger] [docs] Simple docs to show how to override the event log

* [style] Fix, single quote to double quote

* [style] Fix, single quote to double quote
This commit is contained in:
Daniel Vaz Gaspar
2019-07-08 17:38:12 +01:00
committed by Maxime Beauchemin
parent f5839c413e
commit 1ab04190cd
6 changed files with 186 additions and 98 deletions

View File

@@ -678,6 +678,40 @@ environment variable: ::
*Adapted from http://flask.pocoo.org/snippets/69/*
Event Logging
-------------
Superset by default logs special action event on it's database. These log can be accessed on the UI navigating to
"Security" -> "Action Log". You can freely customize these logs by implementing your own event log class.
Example of a simple JSON to Stdout class::
class JSONStdOutEventLogger(AbstractEventLogger):
def log(self, user_id, action, *args, **kwargs):
records = kwargs.get('records', list())
dashboard_id = kwargs.get('dashboard_id')
slice_id = kwargs.get('slice_id')
duration_ms = kwargs.get('duration_ms')
referrer = kwargs.get('referrer')
for record in records:
log = dict(
action=action,
json=record,
dashboard_id=dashboard_id,
slice_id=slice_id,
duration_ms=duration_ms,
referrer=referrer,
user_id=user_id
)
print(json.dumps(log))
Then on Superset's config reference the class you want to use::
EVENT_LOGGER = JSONStdOutEventLogger
Upgrading
---------