diff --git a/homeassistant/bootstrap.py b/homeassistant/bootstrap.py index daee13914fd..cbc8ec5a633 100644 --- a/homeassistant/bootstrap.py +++ b/homeassistant/bootstrap.py @@ -34,6 +34,7 @@ _LOGGER = logging.getLogger(__name__) ATTR_COMPONENT = 'component' PLATFORM_FORMAT = '{}.{}' +ERROR_LOG_FILENAME = 'home-assistant.log' 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") # 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) # Check if we can write to the error log if it exists or that diff --git a/homeassistant/components/api.py b/homeassistant/components/api.py index b11525170a4..405018938b5 100644 --- a/homeassistant/components/api.py +++ b/homeassistant/components/api.py @@ -14,13 +14,14 @@ import json import homeassistant.core as ha from homeassistant.helpers.state import TrackStates import homeassistant.remote as rem +from homeassistant.bootstrap import ERROR_LOG_FILENAME from homeassistant.const import ( 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_CONFIG, URL_API_BOOTSTRAP, + URL_API_CONFIG, URL_API_BOOTSTRAP, URL_API_ERROR_LOG, EVENT_TIME_CHANGED, EVENT_HOMEASSISTANT_STOP, MATCH_ALL, HTTP_OK, HTTP_CREATED, HTTP_BAD_REQUEST, HTTP_NOT_FOUND, - HTTP_UNPROCESSABLE_ENTITY) + HTTP_UNPROCESSABLE_ENTITY, CONTENT_TYPE_TEXT_PLAIN) DOMAIN = 'api' @@ -89,6 +90,9 @@ def setup(hass, config): hass.http.register_path( 'GET', URL_API_COMPONENTS, _handle_get_api_components) + hass.http.register_path('GET', URL_API_ERROR_LOG, + _handle_get_api_error_log) + return True @@ -341,6 +345,13 @@ def _handle_get_api_components(handler, path_match, data): 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): """ Generate services data to JSONify. """ return [{"domain": key, "services": value} diff --git a/homeassistant/const.py b/homeassistant/const.py index 7762f4acc6a..0ac36eb8459 100644 --- a/homeassistant/const.py +++ b/homeassistant/const.py @@ -151,6 +151,7 @@ URL_API_SERVICES_SERVICE = "/api/services/{}/{}" URL_API_EVENT_FORWARD = "/api/event_forwarding" URL_API_COMPONENTS = "/api/components" URL_API_BOOTSTRAP = "/api/bootstrap" +URL_API_ERROR_LOG = "/api/error_log" HTTP_OK = 200 HTTP_CREATED = 201 @@ -173,3 +174,4 @@ HTTP_HEADER_EXPIRES = "Expires" CONTENT_TYPE_JSON = "application/json" CONTENT_TYPE_MULTIPART = 'multipart/x-mixed-replace; boundary={}' +CONTENT_TYPE_TEXT_PLAIN = 'text/plain'