2222 API_KEY_ENVIRONMENT_VARIABLE , DEFAULT_BASE_URL , SINGLE_REQUEST_TIMEOUT , CERTIFICATE_PATH , REQUESTS_PROXY ,
2323 WAIT_ON_RATE_LIMIT , NGINX_429_RETRY_WAIT_TIME , ACTION_BATCH_RETRY_WAIT_TIME , RETRY_4XX_ERROR ,
2424 RETRY_4XX_ERROR_WAIT_TIME , MAXIMUM_RETRIES , OUTPUT_LOG , LOG_PATH , LOG_FILE_PREFIX , PRINT_TO_CONSOLE ,
25- SUPPRESS_LOGGING , SIMULATE_API_CALLS , BE_GEO_ID , MERAKI_PYTHON_SDK_CALLER
25+ SUPPRESS_LOGGING , SIMULATE_API_CALLS , BE_GEO_ID , MERAKI_PYTHON_SDK_CALLER , INHERIT_LOGGING_CONFIG
2626)
2727
2828__version__ = '1.15.0'
@@ -48,20 +48,34 @@ class DashboardAPI(object):
4848 - log_file_prefix (string): log file name appended with date and timestamp
4949 - print_console (boolean): print logging output to console?
5050 - suppress_logging (boolean): disable all logging? you're on your own then!
51+ - inherit_logging_config (boolean): Inherits you're own logging scheme
5152 - simulate (boolean): simulate POST/PUT/DELETE calls to prevent changes?
5253 - be_geo_id (string): optional partner identifier for API usage tracking; can also be set as an environment variable BE_GEO_ID
5354 - caller (string): optional identifier for API usage tracking; can also be set as an environment variable MERAKI_PYTHON_SDK_CALLER
5455 - use_iterator_for_get_pages (boolean): list* methods will return an iterator with each object instead of a complete list with all items
5556 """
5657
57- def __init__ (self , api_key = None , base_url = DEFAULT_BASE_URL , single_request_timeout = SINGLE_REQUEST_TIMEOUT ,
58- certificate_path = CERTIFICATE_PATH , requests_proxy = REQUESTS_PROXY ,
59- wait_on_rate_limit = WAIT_ON_RATE_LIMIT , nginx_429_retry_wait_time = NGINX_429_RETRY_WAIT_TIME ,
60- action_batch_retry_wait_time = ACTION_BATCH_RETRY_WAIT_TIME , retry_4xx_error = RETRY_4XX_ERROR ,
61- retry_4xx_error_wait_time = RETRY_4XX_ERROR_WAIT_TIME , maximum_retries = MAXIMUM_RETRIES ,
62- output_log = OUTPUT_LOG , log_path = LOG_PATH , log_file_prefix = LOG_FILE_PREFIX ,
63- print_console = PRINT_TO_CONSOLE , suppress_logging = SUPPRESS_LOGGING , simulate = SIMULATE_API_CALLS ,
64- be_geo_id = BE_GEO_ID , caller = MERAKI_PYTHON_SDK_CALLER , use_iterator_for_get_pages = False ):
58+ def __init__ (self , api_key = None ,
59+ base_url = DEFAULT_BASE_URL ,
60+ single_request_timeout = SINGLE_REQUEST_TIMEOUT ,
61+ certificate_path = CERTIFICATE_PATH ,
62+ requests_proxy = REQUESTS_PROXY ,
63+ wait_on_rate_limit = WAIT_ON_RATE_LIMIT ,
64+ nginx_429_retry_wait_time = NGINX_429_RETRY_WAIT_TIME ,
65+ action_batch_retry_wait_time = ACTION_BATCH_RETRY_WAIT_TIME ,
66+ retry_4xx_error = RETRY_4XX_ERROR ,
67+ retry_4xx_error_wait_time = RETRY_4XX_ERROR_WAIT_TIME ,
68+ maximum_retries = MAXIMUM_RETRIES ,
69+ output_log = OUTPUT_LOG , log_path = LOG_PATH ,
70+ log_file_prefix = LOG_FILE_PREFIX ,
71+ print_console = PRINT_TO_CONSOLE ,
72+ suppress_logging = SUPPRESS_LOGGING ,
73+ simulate = SIMULATE_API_CALLS ,
74+ be_geo_id = BE_GEO_ID ,
75+ caller = MERAKI_PYTHON_SDK_CALLER ,
76+ inherit_logging_config = INHERIT_LOGGING_CONFIG ,
77+ use_iterator_for_get_pages = False ):
78+
6579 # Check API key
6680 api_key = api_key or os .environ .get (API_KEY_ENVIRONMENT_VARIABLE )
6781 if not api_key :
@@ -76,31 +90,33 @@ def __init__(self, api_key=None, base_url=DEFAULT_BASE_URL, single_request_timeo
7690 # Configure logging
7791 if not suppress_logging :
7892 self ._logger = logging .getLogger (__name__ )
79- self ._logger .setLevel (logging .DEBUG )
80-
81- formatter = logging .Formatter (
82- fmt = '%(asctime)s %(name)12s: %(levelname)8s > %(message)s' ,
83- datefmt = '%Y-%m-%d %H:%M:%S'
84- )
85- handler_console = logging .StreamHandler ()
86- handler_console .setFormatter (formatter )
87-
88- if output_log :
89- if log_path and log_path [- 1 ] != '/' :
90- log_path += '/'
91- self ._log_file = f'{ log_path } { log_file_prefix } _log__{ datetime .now ():%Y-%m-%d_%H-%M-%S} .log'
92- handler_log = logging .FileHandler (
93- filename = self ._log_file
94- )
95- handler_log .setFormatter (formatter )
93+
94+ if not inherit_logging_config :
95+ self ._logger .setLevel (logging .DEBUG )
9696
97- if output_log and not self ._logger .hasHandlers ():
98- self ._logger .addHandler (handler_log )
99- if print_console :
100- handler_console .setLevel (logging .INFO )
97+ formatter = logging .Formatter (
98+ fmt = '%(asctime)s %(name)12s: %(levelname)8s > %(message)s' ,
99+ datefmt = '%Y-%m-%d %H:%M:%S'
100+ )
101+ handler_console = logging .StreamHandler ()
102+ handler_console .setFormatter (formatter )
103+
104+ if output_log :
105+ if log_path and log_path [- 1 ] != '/' :
106+ log_path += '/'
107+ self ._log_file = f'{ log_path } { log_file_prefix } _log__{ datetime .now ():%Y-%m-%d_%H-%M-%S} .log'
108+ handler_log = logging .FileHandler (
109+ filename = self ._log_file
110+ )
111+ handler_log .setFormatter (formatter )
112+
113+ if output_log and not self ._logger .hasHandlers ():
114+ self ._logger .addHandler (handler_log )
115+ if print_console :
116+ handler_console .setLevel (logging .INFO )
117+ self ._logger .addHandler (handler_console )
118+ elif print_console and not self ._logger .hasHandlers ():
101119 self ._logger .addHandler (handler_console )
102- elif print_console and not self ._logger .hasHandlers ():
103- self ._logger .addHandler (handler_console )
104120 else :
105121 self ._logger = None
106122
0 commit comments