mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Merge pull request #591 from balloob/error-log
Expose API to view error log
This commit is contained in:
commit
6dfb8f5737
@ -34,6 +34,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
ATTR_COMPONENT = 'component'
|
ATTR_COMPONENT = 'component'
|
||||||
|
|
||||||
PLATFORM_FORMAT = '{}.{}'
|
PLATFORM_FORMAT = '{}.{}'
|
||||||
|
ERROR_LOG_FILENAME = 'home-assistant.log'
|
||||||
|
|
||||||
|
|
||||||
def setup_component(hass, domain, config=None):
|
def setup_component(hass, domain, config=None):
|
||||||
@ -252,7 +253,7 @@ def enable_logging(hass, verbose=False, daemon=False, log_rotate_days=None):
|
|||||||
"Colorlog package not found, console coloring disabled")
|
"Colorlog package not found, console coloring disabled")
|
||||||
|
|
||||||
# Log errors to a file if we have write access to file or config dir
|
# Log errors to a file if we have write access to file or config dir
|
||||||
err_log_path = hass.config.path('home-assistant.log')
|
err_log_path = hass.config.path(ERROR_LOG_FILENAME)
|
||||||
err_path_exists = os.path.isfile(err_log_path)
|
err_path_exists = os.path.isfile(err_log_path)
|
||||||
|
|
||||||
# Check if we can write to the error log if it exists or that
|
# Check if we can write to the error log if it exists or that
|
||||||
|
@ -14,13 +14,14 @@ import json
|
|||||||
import homeassistant.core as ha
|
import homeassistant.core as ha
|
||||||
from homeassistant.helpers.state import TrackStates
|
from homeassistant.helpers.state import TrackStates
|
||||||
import homeassistant.remote as rem
|
import homeassistant.remote as rem
|
||||||
|
from homeassistant.bootstrap import ERROR_LOG_FILENAME
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
URL_API, URL_API_STATES, URL_API_EVENTS, URL_API_SERVICES, URL_API_STREAM,
|
URL_API, URL_API_STATES, URL_API_EVENTS, URL_API_SERVICES, URL_API_STREAM,
|
||||||
URL_API_EVENT_FORWARD, URL_API_STATES_ENTITY, URL_API_COMPONENTS,
|
URL_API_EVENT_FORWARD, URL_API_STATES_ENTITY, URL_API_COMPONENTS,
|
||||||
URL_API_CONFIG, URL_API_BOOTSTRAP,
|
URL_API_CONFIG, URL_API_BOOTSTRAP, URL_API_ERROR_LOG,
|
||||||
EVENT_TIME_CHANGED, EVENT_HOMEASSISTANT_STOP, MATCH_ALL,
|
EVENT_TIME_CHANGED, EVENT_HOMEASSISTANT_STOP, MATCH_ALL,
|
||||||
HTTP_OK, HTTP_CREATED, HTTP_BAD_REQUEST, HTTP_NOT_FOUND,
|
HTTP_OK, HTTP_CREATED, HTTP_BAD_REQUEST, HTTP_NOT_FOUND,
|
||||||
HTTP_UNPROCESSABLE_ENTITY)
|
HTTP_UNPROCESSABLE_ENTITY, CONTENT_TYPE_TEXT_PLAIN)
|
||||||
|
|
||||||
|
|
||||||
DOMAIN = 'api'
|
DOMAIN = 'api'
|
||||||
@ -89,6 +90,9 @@ def setup(hass, config):
|
|||||||
hass.http.register_path(
|
hass.http.register_path(
|
||||||
'GET', URL_API_COMPONENTS, _handle_get_api_components)
|
'GET', URL_API_COMPONENTS, _handle_get_api_components)
|
||||||
|
|
||||||
|
hass.http.register_path('GET', URL_API_ERROR_LOG,
|
||||||
|
_handle_get_api_error_log)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@ -341,6 +345,13 @@ def _handle_get_api_components(handler, path_match, data):
|
|||||||
handler.write_json(handler.server.hass.config.components)
|
handler.write_json(handler.server.hass.config.components)
|
||||||
|
|
||||||
|
|
||||||
|
def _handle_get_api_error_log(handler, path_match, data):
|
||||||
|
""" Returns the logged errors for this session. """
|
||||||
|
error_path = handler.server.hass.config.path(ERROR_LOG_FILENAME)
|
||||||
|
with open(error_path, 'rb') as error_log:
|
||||||
|
handler.write_file_pointer(CONTENT_TYPE_TEXT_PLAIN, error_log)
|
||||||
|
|
||||||
|
|
||||||
def _services_json(hass):
|
def _services_json(hass):
|
||||||
""" Generate services data to JSONify. """
|
""" Generate services data to JSONify. """
|
||||||
return [{"domain": key, "services": value}
|
return [{"domain": key, "services": value}
|
||||||
|
@ -151,6 +151,7 @@ URL_API_SERVICES_SERVICE = "/api/services/{}/{}"
|
|||||||
URL_API_EVENT_FORWARD = "/api/event_forwarding"
|
URL_API_EVENT_FORWARD = "/api/event_forwarding"
|
||||||
URL_API_COMPONENTS = "/api/components"
|
URL_API_COMPONENTS = "/api/components"
|
||||||
URL_API_BOOTSTRAP = "/api/bootstrap"
|
URL_API_BOOTSTRAP = "/api/bootstrap"
|
||||||
|
URL_API_ERROR_LOG = "/api/error_log"
|
||||||
|
|
||||||
HTTP_OK = 200
|
HTTP_OK = 200
|
||||||
HTTP_CREATED = 201
|
HTTP_CREATED = 201
|
||||||
@ -173,3 +174,4 @@ HTTP_HEADER_EXPIRES = "Expires"
|
|||||||
|
|
||||||
CONTENT_TYPE_JSON = "application/json"
|
CONTENT_TYPE_JSON = "application/json"
|
||||||
CONTENT_TYPE_MULTIPART = 'multipart/x-mixed-replace; boundary={}'
|
CONTENT_TYPE_MULTIPART = 'multipart/x-mixed-replace; boundary={}'
|
||||||
|
CONTENT_TYPE_TEXT_PLAIN = 'text/plain'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user