Skip to content

Commit da34c9d

Browse files
committed
Formalized logger for nx.py
1 parent 1fd25ab commit da34c9d

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/cisco_gnmi/nx.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
from six import string_types
3232
from .client import Client, proto, util
3333

34+
logger = logging.getLogger(__name__)
35+
3436

3537
class NXClient(Client):
3638
"""NX-OS-specific wrapper for gNMI functionality.
@@ -167,14 +169,14 @@ def delete_xpaths(self, xpaths, prefix=None):
167169

168170
def check_configs(self, configs):
169171
if isinstance(configs, string_types):
170-
logging.debug("Handling as JSON string.")
172+
logger.debug("Handling as JSON string.")
171173
try:
172174
configs = json.loads(configs)
173175
except:
174176
raise Exception("{0}\n is invalid JSON!".format(configs))
175177
configs = [configs]
176178
elif isinstance(configs, dict):
177-
logging.debug("Handling already serialized JSON object.")
179+
logger.debug("Handling already serialized JSON object.")
178180
configs = [configs]
179181
elif not isinstance(configs, (list, set)):
180182
raise Exception(
@@ -206,7 +208,6 @@ def create_updates(self, configs, origin):
206208
)
207209
update.val.json_val = payload
208210
updates.append(update)
209-
logging.info('GNMI set:\n\n{0}'.format(str(update)))
210211
return updates
211212
else:
212213
for config in configs:
@@ -245,6 +246,8 @@ def set_json(self, update_json_configs=None, replace_json_configs=None,
245246
raise Exception("Must supply at least one set of configurations to method!")
246247

247248
updates = self.create_updates(update_json_configs, origin=origin)
249+
for update in updates:
250+
logger.info('\nGNMI set:\n{0}\n{1}'.format(9 * '=', str(update)))
248251
replaces = self.create_updates(replace_json_configs, origin=origin)
249252
return self.set(updates=updates, replaces=replaces)
250253

@@ -287,6 +290,7 @@ def get_xpaths(self, xpaths, data_type="ALL",
287290
raise Exception(
288291
"xpaths must be a single xpath string or iterable of xpath strings!"
289292
)
293+
logger.info('GNMI get:\n{0}\n{1}'.format(9 * '=', str(gnmi_path)))
290294
return self.get(gnmi_path, data_type=data_type, encoding=encoding)
291295

292296
def subscribe_xpaths(
@@ -399,6 +403,9 @@ def subscribe_xpaths(
399403
raise Exception("xpath in list must be xpath or dict/Path!")
400404
subscriptions.append(subscription)
401405
subscription_list.subscription.extend(subscriptions)
406+
logger.info('GNMI subscribe:\n{0}\n{1}'.format(
407+
15 * '=', str(subscription_list))
408+
)
402409
return self.subscribe([subscription_list])
403410

404411
def parse_xpath_to_gnmi_path(self, xpath, origin):

0 commit comments

Comments
 (0)