README updates
DBLogHandler updates Added harvest_log table migration for existing users Implemented database log scoping
This commit is contained in:
parent
cc86f4062a
commit
0be2c868cb
81
README.rst
81
README.rst
|
@ -58,7 +58,53 @@ running a version lower than 2.0.
|
||||||
|
|
||||||
ckan.harvest.mq.type = redis
|
ckan.harvest.mq.type = redis
|
||||||
|
|
||||||
7. Setup time frame(in days) for the clean-up mechanism with the following config parameter::
|
7. If you want your ckan harvest logs to be exposed to the ckan API you need to properly
|
||||||
|
configure the logger. The default configuration logs everything to the database with
|
||||||
|
log level ``DEBUG``. If you want to modify the database logger configure the following
|
||||||
|
parameter::
|
||||||
|
|
||||||
|
``ckan.harvest.log_scope = 0``
|
||||||
|
|
||||||
|
* Log scope settings:
|
||||||
|
|
||||||
|
- ``-1`` Do not log to the database
|
||||||
|
- ``0`` Log everything - Default
|
||||||
|
- ``1`` model, logic.action, logic.validators, harvesters
|
||||||
|
- ``2`` model, logic.action, logic.validators
|
||||||
|
- ``3`` model, logic.action
|
||||||
|
- ``4`` logic.action
|
||||||
|
- ``5`` model
|
||||||
|
- ``6`` plugin
|
||||||
|
- ``7`` harvesters
|
||||||
|
|
||||||
|
Additionally you can configure the logger in the following way::
|
||||||
|
|
||||||
|
[loggers]
|
||||||
|
keys = ckan_harvester
|
||||||
|
|
||||||
|
[handlers]
|
||||||
|
keys = dblog
|
||||||
|
|
||||||
|
[formatters]
|
||||||
|
keys = dblog
|
||||||
|
|
||||||
|
[logger_ckan_harvester]
|
||||||
|
qualname = ckanext.harvest
|
||||||
|
handlers = dblog
|
||||||
|
level = DEBUG
|
||||||
|
|
||||||
|
[handler_dblog]
|
||||||
|
class = ckanext.harvest.log.DBLogHandler
|
||||||
|
args = ()
|
||||||
|
level = DEBUG
|
||||||
|
formatter = dblog
|
||||||
|
|
||||||
|
[formatter_dblog]
|
||||||
|
format = %(message)s
|
||||||
|
|
||||||
|
If you are having troubles configuring ckan logger please refer to ``test-core.ini``
|
||||||
|
|
||||||
|
8. Setup time frame(in days) for the clean-up mechanism with the following config parameter::
|
||||||
|
|
||||||
ckan.harvest.log_timeframe = 10
|
ckan.harvest.log_timeframe = 10
|
||||||
|
|
||||||
|
@ -91,39 +137,6 @@ config option (or ``default``) will be used to namespace the relevant things:
|
||||||
* On Redis, it will namespace the keys used, so only the relevant instance gets them, eg
|
* On Redis, it will namespace the keys used, so only the relevant instance gets them, eg
|
||||||
``site1:harvest_job_id``, ``site1:harvest_object__id:804f114a-8f68-4e7c-b124-3eb00f66202f``
|
``site1:harvest_job_id``, ``site1:harvest_object__id:804f114a-8f68-4e7c-b124-3eb00f66202f``
|
||||||
|
|
||||||
7. If you want your ckan harvest logs to be exposed to the ckan API you need to add the
|
|
||||||
following configuration options in your ckan configuriation file::
|
|
||||||
|
|
||||||
[loggers]
|
|
||||||
|
|
||||||
keys = ckan_harvester
|
|
||||||
|
|
||||||
[handlers]
|
|
||||||
|
|
||||||
keys = dblog
|
|
||||||
|
|
||||||
[formatters]
|
|
||||||
|
|
||||||
keys = dblog
|
|
||||||
|
|
||||||
[logger_ckan_harvester]
|
|
||||||
|
|
||||||
qualname = ckanext.harvest
|
|
||||||
handlers = dblog
|
|
||||||
level = DEBUG
|
|
||||||
|
|
||||||
[handler_dblog]
|
|
||||||
|
|
||||||
class = ckanext.harvest.log.DBLogHandler
|
|
||||||
args = ()
|
|
||||||
level = DEBUG
|
|
||||||
formatter = dblog
|
|
||||||
|
|
||||||
[formatter_dblog]
|
|
||||||
|
|
||||||
format = %(message)s
|
|
||||||
|
|
||||||
If you are having troubles configuring ckan logger please refer to ``test-core.ini``
|
|
||||||
|
|
||||||
Configuration
|
Configuration
|
||||||
=============
|
=============
|
||||||
|
|
|
@ -93,7 +93,7 @@ class Harvester(CkanCommand):
|
||||||
|
|
||||||
harvester job-all
|
harvester job-all
|
||||||
- create new harvest jobs for all active sources.
|
- create new harvest jobs for all active sources.
|
||||||
https://www.facebook.com/
|
|
||||||
harvester reindex
|
harvester reindex
|
||||||
- reindexes the harvest source datasets
|
- reindexes the harvest source datasets
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
from logging import Handler
|
from logging import Handler, NOTSET
|
||||||
|
|
||||||
from ckanext.harvest.model import HarvestLog
|
from ckanext.harvest.model import HarvestLog
|
||||||
|
|
||||||
class DBLogHandler(Handler, object):
|
class DBLogHandler(Handler):
|
||||||
def __init__(self):
|
def __init__(self, level=NOTSET):
|
||||||
super(DBLogHandler,self).__init__()
|
super(DBLogHandler,self).__init__(level=level)
|
||||||
|
|
||||||
def emit(self, record):
|
def emit(self, record):
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -89,6 +89,10 @@ def setup():
|
||||||
sources_to_migrate = [s[0] for s in sources_to_migrate]
|
sources_to_migrate = [s[0] for s in sources_to_migrate]
|
||||||
migrate_v3_create_datasets(sources_to_migrate)
|
migrate_v3_create_datasets(sources_to_migrate)
|
||||||
|
|
||||||
|
# Check if harvest_log table exist - needed for existing users
|
||||||
|
if not 'harvest_log' in inspector.get_table_names():
|
||||||
|
harvest_log_table.create()
|
||||||
|
|
||||||
|
|
||||||
class HarvestError(Exception):
|
class HarvestError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -19,6 +19,7 @@ from ckanext.harvest import logic as harvest_logic
|
||||||
|
|
||||||
from ckanext.harvest.model import setup as model_setup
|
from ckanext.harvest.model import setup as model_setup
|
||||||
from ckanext.harvest.model import HarvestSource, HarvestJob, HarvestObject
|
from ckanext.harvest.model import HarvestSource, HarvestJob, HarvestObject
|
||||||
|
from ckanext.harvest.log import DBLogHandler
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -218,6 +219,9 @@ class Harvest(p.SingletonPlugin, DefaultDatasetForm, DefaultTranslation):
|
||||||
# Setup harvest model
|
# Setup harvest model
|
||||||
model_setup()
|
model_setup()
|
||||||
|
|
||||||
|
# Configure logger
|
||||||
|
_configure_logger(config)
|
||||||
|
|
||||||
self.startup = False
|
self.startup = False
|
||||||
|
|
||||||
def before_map(self, map):
|
def before_map(self, map):
|
||||||
|
@ -463,3 +467,57 @@ def _delete_harvest_source_object(context, data_dict):
|
||||||
log.debug('Harvest source %s deleted', source_id)
|
log.debug('Harvest source %s deleted', source_id)
|
||||||
|
|
||||||
return source
|
return source
|
||||||
|
|
||||||
|
def _configure_logger(config):
|
||||||
|
# Log scope
|
||||||
|
#
|
||||||
|
# -1 - do not log to the database
|
||||||
|
# 0 - log everything
|
||||||
|
# 1 - model, logic.action, logic.validators, harvesters
|
||||||
|
# 2 - model, logic.action, logic.validators
|
||||||
|
# 3 - model, logic.action
|
||||||
|
# 4 - logic.action
|
||||||
|
# 5 - model
|
||||||
|
# 6 - plugin
|
||||||
|
# 7 - harvesters
|
||||||
|
#
|
||||||
|
scope = p.toolkit.asint(config.get('ckan.harvest.log_scope', 0))
|
||||||
|
if scope == -1:
|
||||||
|
return
|
||||||
|
|
||||||
|
parent_logger = 'ckanext.harvest'
|
||||||
|
children = ['plugin', 'model', 'logic.action.create', 'logic.action.delete',
|
||||||
|
'logic.action.get', 'logic.action.patch', 'action.update',
|
||||||
|
'logic.validators', 'harvesters.base', 'harvesters.ckanharvester']
|
||||||
|
|
||||||
|
children_ = {0: children, 1: children[1:], 2: children[1:-2],
|
||||||
|
3: children[1:-3], 4: children[2:-3], 5: children[1:2],
|
||||||
|
6: children[:1], 7: children[-2:]}
|
||||||
|
|
||||||
|
# Get log level from config param - default: DEBUG
|
||||||
|
from logging import DEBUG, INFO, WARNING, ERROR, CRITICAL
|
||||||
|
level_ = config.get('ckan.harvest.log_level', 'debug').upper()
|
||||||
|
if level_ == 'DEBUG':
|
||||||
|
level_ = DEBUG
|
||||||
|
elif level_ == 'INFO':
|
||||||
|
level_ = INFO
|
||||||
|
elif level_ == 'WARNING':
|
||||||
|
level_ = WARNING
|
||||||
|
elif level_ == 'ERROR':
|
||||||
|
level_ = ERROR
|
||||||
|
elif level_ == 'CRITICAL':
|
||||||
|
level_ = CRITICAL
|
||||||
|
else:
|
||||||
|
level_ = DEBUG
|
||||||
|
|
||||||
|
loggers = children_.get(scope)
|
||||||
|
|
||||||
|
# Get root logger and set db handler
|
||||||
|
logger = getLogger(parent_logger)
|
||||||
|
if scope < 1:
|
||||||
|
logger.addHandler(DBLogHandler(level=level_))
|
||||||
|
|
||||||
|
# Set db handler to all child loggers
|
||||||
|
for _ in loggers:
|
||||||
|
child_logger = logger.getChild(_)
|
||||||
|
child_logger.addHandler(DBLogHandler(level=level_))
|
||||||
|
|
Loading…
Reference in New Issue