def _configure_default_logging(cli_ctx, resource_group_name, name, slot=None, app_instance=None, level=None, web_server_logging='filesystem', docker_container_logging='true'): from azure.mgmt.web.models import (FileSystemApplicationLogsConfig, ApplicationLogsConfig, SiteLogsConfig, HttpLogsConfig, FileSystemHttpLogsConfig) # logger.warning('Configuring default logging for the app, if not already enabled...') site = _get_webapp(cli_ctx, resource_group_name, name, slot=slot, app_instance=app_instance) location = site.location fs_log = FileSystemApplicationLogsConfig(level='Error') application_logs = ApplicationLogsConfig(file_system=fs_log) http_logs = None server_logging_option = web_server_logging or docker_container_logging if server_logging_option: # TODO: az blob storage log config currently not in use, will be impelemented later. # Tracked as Issue: #4764 on Github filesystem_log_config = None turned_on = server_logging_option != 'off' if server_logging_option in ['filesystem', 'off']: # 100 mb max log size, retention lasts 3 days. Yes we hard code it, portal does too filesystem_log_config = FileSystemHttpLogsConfig( retention_in_mb=100, retention_in_days=3, enabled=turned_on) http_logs = HttpLogsConfig(file_system=filesystem_log_config, azure_blob_storage=None) site_log_config = SiteLogsConfig(location=location, application_logs=application_logs, http_logs=http_logs, failed_requests_tracing=None, detailed_error_messages=None) from ._client_factory import web_client_factory web_client = web_client_factory(cli_ctx).web_apps return web_client.update_diagnostic_logs_config(resource_group_name, name, site_log_config)
def config_diagnostics(resource_group_name, name, level=None, application_logging=None, web_server_logging=None, detailed_error_messages=None, failed_request_tracing=None, slot=None): from azure.mgmt.web.models import (FileSystemApplicationLogsConfig, ApplicationLogsConfig, SiteLogsConfig, HttpLogsConfig, FileSystemHttpLogsConfig, EnabledConfig) client = web_client_factory() #TODO: ensure we call get_site only once site = client.web_apps.get(resource_group_name, name) location = site.location application_logs = None if application_logging is not None: if not application_logging: level = 'Off' elif level is None: level = 'Error' fs_log = FileSystemApplicationLogsConfig(level) application_logs = ApplicationLogsConfig(fs_log) http_logs = None if web_server_logging is not None: enabled = web_server_logging #100 mb max log size, retenting last 3 days. Yes we hard code it, portal does too fs_server_log = FileSystemHttpLogsConfig(100, 3, enabled) http_logs = HttpLogsConfig(fs_server_log) detailed_error_messages_logs = (None if detailed_error_messages is None else EnabledConfig(detailed_error_messages)) failed_request_tracing_logs = (None if failed_request_tracing is None else EnabledConfig(failed_request_tracing)) site_log_config = SiteLogsConfig( location, application_logs=application_logs, http_logs=http_logs, failed_requests_tracing=failed_request_tracing_logs, detailed_error_messages=detailed_error_messages_logs) return _generic_site_operation(resource_group_name, name, 'update_diagnostic_logs_config', slot, site_log_config)