Skip to content

Commit 59d50cd

Browse files
author
Shiyue Cheng
committed
fix for logging
1 parent 184d6cf commit 59d50cd

2 files changed

Lines changed: 18 additions & 20 deletions

File tree

meraki/__init__.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,18 @@ def __init__(self, api_key=None, base_url=DEFAULT_BASE_URL, single_request_timeo
7575
fmt='%(asctime)s %(name)12s: %(levelname)8s > %(message)s',
7676
datefmt='%Y-%m-%d %H:%M:%S'
7777
)
78-
79-
if log_path and log_path[-1] != '/':
80-
log_path += '/'
81-
self._log_file = f'{log_path}{log_file_prefix}_log__{datetime.now():%Y-%m-%d_%H-%M-%S}.log'
82-
8378
handler_console = logging.StreamHandler()
84-
handler_log = logging.FileHandler(
85-
filename=self._log_file
86-
)
87-
8879
handler_console.setFormatter(formatter)
89-
handler_log.setFormatter(formatter)
9080

81+
if output_log:
82+
if log_path and log_path[-1] != '/':
83+
log_path += '/'
84+
self._log_file = f'{log_path}{log_file_prefix}_log__{datetime.now():%Y-%m-%d_%H-%M-%S}.log'
85+
handler_log = logging.FileHandler(
86+
filename=self._log_file
87+
)
88+
handler_log.setFormatter(formatter)
89+
9190
if output_log and not self._logger.hasHandlers():
9291
self._logger.addHandler(handler_log)
9392
if print_console:

meraki/aio/__init__.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,18 @@ def __init__(self, api_key=None, base_url=DEFAULT_BASE_URL, single_request_timeo
7575
fmt='%(asctime)s %(name)12s: %(levelname)8s > %(message)s',
7676
datefmt='%Y-%m-%d %H:%M:%S'
7777
)
78-
79-
if log_path and log_path[-1] != '/':
80-
log_path += '/'
81-
self._log_file = f'{log_path}{log_file_prefix}_log__{datetime.now():%Y-%m-%d_%H-%M-%S}.log'
82-
8378
handler_console = logging.StreamHandler()
84-
handler_log = logging.FileHandler(
85-
filename=self._log_file
86-
)
87-
8879
handler_console.setFormatter(formatter)
89-
handler_log.setFormatter(formatter)
9080

81+
if output_log:
82+
if log_path and log_path[-1] != '/':
83+
log_path += '/'
84+
self._log_file = f'{log_path}{log_file_prefix}_log__{datetime.now():%Y-%m-%d_%H-%M-%S}.log'
85+
handler_log = logging.FileHandler(
86+
filename=self._log_file
87+
)
88+
handler_log.setFormatter(formatter)
89+
9190
if output_log and not self._logger.hasHandlers():
9291
self._logger.addHandler(handler_log)
9392
if print_console:

0 commit comments

Comments
 (0)