-
Notifications
You must be signed in to change notification settings - Fork 23
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
MNT: Create loggers.py and add Elasticsearch handler #49
Open
ke-zhang-rd
wants to merge
10
commits into
NSLS-II:master
Choose a base branch
from
ke-zhang-rd:logger
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e4b1494
MNT: Create loggers.py and add ElasticHandler
ke-zhang-rd a4ca284
MNT: Add .flake8
ke-zhang-rd b3dcf8c
STY: PEP8
ke-zhang-rd 4d27ea9
MNT: delete caproto related file
ke-zhang-rd a0169b9
MNT: Add requests
ke-zhang-rd 6bd6648
MNT: Update elastic index
ke-zhang-rd 5dbb1ff
MNT: Update .flaske8
ke-zhang-rd c99bc5d
MNT: typos
ke-zhang-rd 1c77494
MNT: Update dict for es
ke-zhang-rd 94b3de8
MNH: Assume record.address as a (host,port) tuple
ke-zhang-rd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
[flake8] | ||
exclude = .git,__pycache__,build,dist,versioneer.py,nslsii/_version.py,docs/source/conf.py | ||
ignore = E402,W504 | ||
exclude = .git,__pycache__,doc/source/conf.py,build,dist,versioneer.py | ||
max-line-length = 115 | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import logging | ||
import requests | ||
import json | ||
|
||
class ElasticHandler(logging.Handler): | ||
''' | ||
Logging handler that submits data to Elastic | ||
|
||
Parameters | ||
---------- | ||
url: string | ||
url to Elastic server | ||
|
||
level: Logging Levels, optional | ||
Handler logging level | ||
''' | ||
def __init__(self, url, level=logging.INFO): | ||
self.url = url | ||
self.level = level | ||
super().__init__(self.level) | ||
|
||
def emit(self, record): | ||
''' | ||
method is used to send the message to its destination and | ||
logging for debug | ||
''' | ||
# Extract useful info from the record and put them into a dict. | ||
try: | ||
record_dict = {'name': record.name, | ||
'levelname': record.levelname, | ||
'pathname': record.pathname, | ||
'lineno': record.lineno, | ||
'msg': self.format(record), | ||
'args': list(map(str, record.args)), | ||
'threadName': record.threadName} | ||
|
||
if hasattr(record, 'pv'): record_dict['pv'] = record.pv | ||
if hasattr(record, 'address'): record_dict['address'] = record.address[0]+':'+str(record.address[1]) | ||
if hasattr(record, 'role'): record_dict['role'] = record.role | ||
response = requests.post(self.url, json=record_dict) | ||
response.raise_for_status() | ||
except Exception: | ||
self.handleError(record) | ||
|
||
def configure_elastic(beamline): | ||
url = 'http://elasticsearch.cs.nsls2.local/' + beamline + '.blueksy' | ||
local_url = 'http://localhost:9200/test1/_doc' | ||
|
||
bluesky_logger = logging.getLogger('bluesky') | ||
bluesky_elastic_hdr = ElasticHandler(url, level = logging.DEBUG) | ||
bluesky_logger.addHandler(elastic_hdr) | ||
|
||
carproto_logger = logging.getLogger('carproto') | ||
carproto_elastic_hdr = ElasticHandler(local_url, level = logging.DEBUG) | ||
carproto_logger.addHandler(elastic_hdr) | ||
|
||
ophyd_logger = logging.getLogger('ophyd') | ||
ophyd_elastic_hdr = ElasticHandler(url, level = logging.INFO) | ||
ophyd_logger.addHandler(elastic_hdr) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ numpy | |
ophyd | ||
psutil | ||
pyolog | ||
requests |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My concern here is that the line length here is 115, but in .travis.yml it's set to 79 via command-line arg (which most likely has a priority). I think we should have a single source of truth here, so that only one configuration is controlling the settings in both development environments and in the CI systems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why it was set to
79
in.travis.yml
since that is the default anyway. @ke-zhang-rd, I think the right path here is to remove--max-line-length=79
from this line as part of this PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with the plan.