Skip to content

Commit

Permalink
Merge branch 'master' into pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
postlund authored Mar 2, 2021
2 parents d60093c + 7464cb7 commit 9529a17
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 14 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/log.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install pygithub
- name: Install python packages
run: |
pip install pygithub
python setup.py develop
- uses: jannekem/run-python-script-action@v1
with:
fail-on-error: false
Expand Down Expand Up @@ -49,7 +50,7 @@ jobs:
fi
if [ -e "body" ]; then
python scripts/log2html.py --output ${base_name}.html --format markdown body
atvlog --output ${base_name}.html --format markdown body
fi
- name: Check if log exists
id: check_files
Expand Down
2 changes: 2 additions & 0 deletions docs/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ page_links:
title: atvproxy
- link: /documentation/atvscript/
title: atvscript
- link: /documentation/atvlog/
title: atvlog
development:
- link: /development/
title: Start
Expand Down
47 changes: 47 additions & 0 deletions docs/documentation/atvlog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
layout: template
title: atvlog
permalink: /documentation/atvlog/
link_group: documentation
---
# atvlog

The `atvlog` script simplifies log inspection by generating an HTML file with basic
live filtering capabilities.

*Note: This is an incubating script and may change behavior with short notice.*

## Features

Log output from the following tools are supported as input:

* atvremote and atvscript
* Home Assistant log

A special `markdown` mode is supported, which extracts a log from the following
format:

~~~
text here is ignored
```log
log data here
```
also ignored
~~~

Filtering can be performed on the following attributes:

* Include entries based on regexp
* Exclude entries based on regexp (performed prior to include regexp)
* Log levels
* Date can be stripped for more compact log

## Examples

```shell
$ atvlog pyatv.log # Print output to stdout
$ atvlog --output pyatv.html pyatv.log
$ cat pyatv.log | atvlog - # Read from stdin
$ cat markdown.log | atvlog --format=markdown -
```

40 changes: 29 additions & 11 deletions scripts/log2html.py → pyatv/scripts/atvlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import json
import logging
import argparse
from datetime import datetime

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -45,7 +46,6 @@
<script>
var content = {content};
var text_filter = null;
var level_checkboxes = [];
function createEntry(entry) {{
Expand Down Expand Up @@ -74,6 +74,9 @@
}}
function populate() {{
include_filter = document.getElementById("include_filter").value;
exclude_filter = document.getElementById("exclude_filter").value;
entries = document.getElementById("entries")
entries.innerHTML = "";
Expand All @@ -84,20 +87,20 @@
}}
}}
match_regexp = new RegExp(text_filter, "i");
include_regexp = new RegExp(include_filter, "i");
exclude_regexp = new RegExp(exclude_filter, "i");
for (const entry of content) {{
if ((text_filter == null || match_regexp.test(entry[3])) &&
if (exclude_filter && exclude_regexp.test(entry[3])) {{
continue;
}}
if ((include_filter == null || include_regexp.test(entry[3])) &&
active_levels.has(entry[1])) {{
entries.appendChild(createEntry(entry));
}}
}}
}}
function filterText() {{
text_filter = document.getElementById("filter").value;
populate();
}}
function loadData() {{
var log_levels = new Set();
Expand Down Expand Up @@ -144,9 +147,22 @@
</head>
<body>
<h1>pyatv log2html</h1>
<div>
Generated at {time}<br />
Command: {command}
</div>
<div id="filters" style="display: inline">
<input type="text" id="filter" onkeyup="filterText()"
placeholder="Filter regexp..." />
<div>
<label for="include_filter">Include</label>
<input type="text" id="include_filter" onkeyup="populate()"
placeholder="Include regexp..." />
</div>
<div>
<label for="exclude_filter">Exclude</label>
<input type="text" id="exclude_filter" onkeyup="populate()"
placeholder="Exclude regexp..." />
</div>
<div>
<input type="checkbox" id="show_date" onclick="populate()" checked />
<label for="show_date">Show date</label>
Expand Down Expand Up @@ -199,7 +215,9 @@ def generate_log_page(stream, output):
_LOGGER.warning("No log points found, not generating output")
return

page = HTML_TEMPLATE.format(content=json.dumps(logs))
page = HTML_TEMPLATE.format(
content=json.dumps(logs), time=datetime.now(), command=" ".join(sys.argv)
)
if not output:
print(page)
else:
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def get_requirements():
"console_scripts": [
"atvremote = pyatv.scripts.atvremote:main",
"atvproxy = pyatv.scripts.atvproxy:main",
"atvscript = pyatv.scripts.atvscript:main"
"atvscript = pyatv.scripts.atvscript:main",
"atvlog = pyatv.scripts.atvlog:main",
]
},
classifiers=[
Expand Down

0 comments on commit 9529a17

Please sign in to comment.