-
Notifications
You must be signed in to change notification settings - Fork 3
add structlog to dspace refactor #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,14 @@ | ||
| import datetime | ||
| import logging | ||
| import time | ||
|
|
||
| import click | ||
| import structlog | ||
|
|
||
| from dsaps import models | ||
ehanson8 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| logger = structlog.get_logger() | ||
|
|
||
|
|
||
| @click.group() | ||
| @click.option('--url', envvar='DSPACE_URL') | ||
|
|
@@ -15,7 +20,22 @@ | |
| @click.pass_context | ||
| def main(ctx, url, email, password): | ||
| ctx.obj = {} | ||
| print('Application start') | ||
| dt = datetime.datetime.utcnow().isoformat(timespec='seconds') | ||
| log_suffix = f'{dt}.log' | ||
| structlog.configure(processors=[ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was able to remove this entire block and it logged fine?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you getting |
||
| structlog.stdlib.filter_by_level, | ||
| structlog.stdlib.add_log_level, | ||
| structlog.stdlib.PositionalArgumentsFormatter(), | ||
| structlog.processors.TimeStamper(fmt="iso"), | ||
| structlog.processors.JSONRenderer() | ||
| ], | ||
| context_class=dict, | ||
| logger_factory=structlog.stdlib.LoggerFactory()) | ||
| logging.basicConfig(format="%(message)s", | ||
| handlers=[logging.FileHandler(f'logs/log-{log_suffix}', | ||
| 'w')], | ||
| level=logging.INFO) | ||
| logger.info('Application start') | ||
| client = models.Client(url, email, password) | ||
| start_time = time.time() | ||
| ctx.obj['client'] = client | ||
|
|
@@ -38,7 +58,7 @@ def search(ctx, field, string, search_type): | |
| client = ctx.obj['client'] | ||
| start_time = ctx.obj['start_time'] | ||
| item_links = client.filtered_item_search(field, string, search_type) | ||
| print(item_links) | ||
| logger.info(item_links) | ||
| models.elapsed_time(start_time, 'Elapsed time') | ||
|
|
||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.