updated logging usage, to use the library directly and avoid imposing a core config by default, allowing users of the core library to configure logging as desired

This commit is contained in:
bharnden 2019-02-16 09:50:19 -08:00
parent 37f747c212
commit 7aee2b2ba7
44 changed files with 552 additions and 527 deletions

View file

@ -2,14 +2,13 @@
Helper objects for dealing with IPv4/v6 addresses.
"""
import logging
import random
import socket
import struct
from socket import AF_INET
from socket import AF_INET6
from core import logger
class MacAddress(object):
"""
@ -151,7 +150,7 @@ class IpAddress(object):
try:
carry = int(other)
except ValueError:
logger.exception("error during addition")
logging.exception("error during addition")
return NotImplemented
tmp = [ord(x) for x in self.addr]
@ -174,7 +173,7 @@ class IpAddress(object):
try:
tmp = -int(other)
except ValueError:
logger.exception("error during subtraction")
logging.exception("error during subtraction")
return NotImplemented
return self.__add__(tmp)
@ -276,7 +275,7 @@ class IpPrefix(object):
try:
tmp = int(other)
except ValueError:
logger.exception("error during addition")
logging.exception("error during addition")
return NotImplemented
a = IpAddress(self.af, self.prefix) + (tmp << (self.addrlen - self.prefixlen))
@ -297,7 +296,7 @@ class IpPrefix(object):
try:
tmp = -int(other)
except ValueError:
logger.exception("error during subtraction")
logging.exception("error during subtraction")
return NotImplemented
return self.__add__(tmp)

View file

@ -2,7 +2,7 @@
Serves as a global point for storing and retrieving node types needed during simulation.
"""
from core import logger
import logging
_NODE_MAP = None
@ -13,7 +13,7 @@ def _log_map():
name = None
if value:
name = value.__name__
logger.debug("node type (%s) - class (%s)", key.name, name)
logging.debug("node type (%s) - class (%s)", key.name, name)
def _convert_map(x, y):

View file

@ -2,7 +2,7 @@
Utilities for working with python struct data.
"""
from core import logger
import logging
def pack_values(clazz, packers):
@ -40,7 +40,7 @@ def pack_values(clazz, packers):
value = transformer(value)
# pack and add to existing data
logger.debug("packing: %s - %s", tlv_type, value)
logging.debug("packing: %s - %s", tlv_type, value)
data += clazz.pack(tlv_type.value, value)
return data

View file

@ -4,6 +4,7 @@ Miscellaneous utility functions, wrappers around some subprocess procedures.
import importlib
import inspect
import logging
import os
import shlex
import subprocess
@ -12,7 +13,6 @@ import sys
import fcntl
from core import CoreCommandError
from core import logger
DEVNULL = open(os.devnull, "wb")
@ -179,7 +179,7 @@ def cmd(args, wait=True):
:rtype: int
"""
args = split_args(args)
logger.debug("command: %s", args)
logging.debug("command: %s", args)
try:
p = subprocess.Popen(args)
if not wait:
@ -200,7 +200,7 @@ def cmd_output(args):
:raises CoreCommandError: when the file to execute is not found
"""
args = split_args(args)
logger.debug("command: %s", args)
logging.debug("command: %s", args)
try:
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
stdout, _ = p.communicate()
@ -224,7 +224,7 @@ def check_cmd(args, **kwargs):
kwargs["stdout"] = subprocess.PIPE
kwargs["stderr"] = subprocess.STDOUT
args = split_args(args)
logger.debug("command: %s", args)
logging.debug("command: %s", args)
try:
p = subprocess.Popen(args, **kwargs)
stdout, _ = p.communicate()
@ -362,7 +362,7 @@ def load_config(filename, d):
key, value = line.split("=", 1)
d[key] = value.strip()
except ValueError:
logger.exception("error reading file to dict: %s", filename)
logging.exception("error reading file to dict: %s", filename)
def load_classes(path, clazz):
@ -374,13 +374,13 @@ def load_classes(path, clazz):
:return: list of classes loaded
"""
# validate path exists
logger.debug("attempting to load modules from path: %s", path)
logging.debug("attempting to load modules from path: %s", path)
if not os.path.isdir(path):
logger.warn("invalid custom module directory specified" ": %s" % path)
logging.warn("invalid custom module directory specified" ": %s" % path)
# check if path is in sys.path
parent_path = os.path.dirname(path)
if parent_path not in sys.path:
logger.debug("adding parent path to allow imports: %s", parent_path)
logging.debug("adding parent path to allow imports: %s", parent_path)
sys.path.append(parent_path)
# retrieve potential service modules, and filter out invalid modules
@ -393,7 +393,7 @@ def load_classes(path, clazz):
classes = []
for module_name in module_names:
import_statement = "%s.%s" % (base_module, module_name)
logger.debug("importing custom module: %s", import_statement)
logging.debug("importing custom module: %s", import_statement)
try:
module = importlib.import_module(import_statement)
members = inspect.getmembers(module, lambda x: _is_class(module, x, clazz))
@ -401,6 +401,6 @@ def load_classes(path, clazz):
valid_class = member[1]
classes.append(valid_class)
except:
logger.exception("unexpected error during import, skipping: %s", import_statement)
logging.exception("unexpected error during import, skipping: %s", import_statement)
return classes